mirror of
https://github.com/we-promise/sure.git
synced 2026-04-21 13:04:18 +00:00
Add SnapTrade brokerage integration with full trade history support (#737)
* Introduce SnapTrade integration with models, migrations, views, and activity processing logic. * Refactor SnapTrade activities processing: improve activity fetching flow, handle pending states, and update UI elements for enhanced user feedback. * Update Brakeman ignore file to include intentional redirect for SnapTrade OAuth portal. * Refactor SnapTrade models, views, and processing logic: add currency extraction helper, improve pending state handling, optimize migration checks, and enhance user feedback in UI. * Remove encryption for SnapTrade `snaptrade_user_id`, as it is an identifier, not a secret. * Introduce `SnaptradeConnectionCleanupJob` to asynchronously handle SnapTrade connection cleanup and improve i18n for SnapTrade item status messages. * Update SnapTrade encryption: make `snaptrade_user_secret` non-deterministic to enhance security. --------- Signed-off-by: Juan José Mata <juanjo.mata@gmail.com> Co-authored-by: luckyPipewrench <luckypipewrench@proton.me> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
@@ -122,6 +122,31 @@ module ApplicationHelper
|
||||
markdown.render(text).html_safe
|
||||
end
|
||||
|
||||
# Formats quantity with adaptive precision based on the value size.
|
||||
# Shows more decimal places for small quantities (common with crypto).
|
||||
#
|
||||
# @param qty [Numeric] The quantity to format
|
||||
# @param max_precision [Integer] Maximum precision for very small numbers
|
||||
# @return [String] Formatted quantity with appropriate precision
|
||||
def format_quantity(qty)
|
||||
return "0" if qty.nil? || qty.zero?
|
||||
|
||||
abs_qty = qty.abs
|
||||
|
||||
precision = if abs_qty >= 1
|
||||
1 # "10.5"
|
||||
elsif abs_qty >= 0.01
|
||||
2 # "0.52"
|
||||
elsif abs_qty >= 0.0001
|
||||
4 # "0.0005"
|
||||
else
|
||||
8 # "0.00000052"
|
||||
end
|
||||
|
||||
# Use strip_insignificant_zeros to avoid trailing zeros like "0.50000000"
|
||||
number_with_precision(qty, precision: precision, strip_insignificant_zeros: true)
|
||||
end
|
||||
|
||||
private
|
||||
def calculate_total(item, money_method, negate)
|
||||
# Filter out transfer-type transactions from entries
|
||||
|
||||
Reference in New Issue
Block a user