mirror of
https://github.com/we-promise/sure.git
synced 2026-04-10 07:44:48 +00:00
* [FEATURE] Add CoinStats exchange portfolios and normalize linked investment charts * [BUGFIX] Fix CoinStats PR regressions * [BUGFIX] Fix CoinStats PR review findings * [BUGFIX] Address follow-up CoinStats PR feedback * [REFACTO] Extract CoinStats exchange account helpers * [BUGFIX] Batch linked CoinStats chart normalization * [BUGFIX] Fix CoinStats processor lint --------- Signed-off-by: Juan José Mata <juanjo.mata@gmail.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
84 lines
1.7 KiB
Ruby
84 lines
1.7 KiB
Ruby
class UI::Account::Chart < ApplicationComponent
|
|
attr_reader :account
|
|
|
|
def initialize(account:, period: nil, view: nil)
|
|
@account = account
|
|
@period = period
|
|
@view = view
|
|
end
|
|
|
|
def period
|
|
@period ||= Period.last_30_days
|
|
end
|
|
|
|
def holdings_value_money
|
|
account.balance_money - account.cash_balance_money
|
|
end
|
|
|
|
def view_balance_money
|
|
case view
|
|
when "balance"
|
|
account.balance_money
|
|
when "holdings_balance"
|
|
holdings_value_money
|
|
when "cash_balance"
|
|
account.cash_balance_money
|
|
end
|
|
end
|
|
|
|
def title
|
|
case account.accountable_type
|
|
when "Investment", "Crypto"
|
|
case view
|
|
when "balance"
|
|
"Total account value"
|
|
when "holdings_balance"
|
|
"Holdings value"
|
|
when "cash_balance"
|
|
"Cash value"
|
|
end
|
|
when "Property", "Vehicle"
|
|
"Estimated #{account.accountable_type.humanize.downcase} value"
|
|
when "CreditCard", "OtherLiability"
|
|
"Debt balance"
|
|
when "Loan"
|
|
"Remaining principal balance"
|
|
else
|
|
"Balance"
|
|
end
|
|
end
|
|
|
|
def foreign_currency?
|
|
account.currency != account.family.currency
|
|
end
|
|
|
|
def converted_balance_money
|
|
return nil unless foreign_currency?
|
|
|
|
account.balance_money.exchange_to(account.family.currency, fallback_rate: 1)
|
|
end
|
|
|
|
def view
|
|
@view ||= "balance"
|
|
end
|
|
|
|
def series
|
|
account.balance_series(period: period, view: view)
|
|
end
|
|
|
|
def trend
|
|
series.trend
|
|
end
|
|
|
|
def comparison_label
|
|
start_date = series.start_date
|
|
return period.comparison_label if start_date.blank?
|
|
|
|
if start_date > period.start_date
|
|
"vs. available history"
|
|
else
|
|
period.comparison_label
|
|
end
|
|
end
|
|
end
|