mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-22 06:39:39 +02:00
Format money for trade history in holdings drawer (#1961)
* Format money for trade history in holdings drawer * Fix broken tests * Lint fix
This commit is contained in:
parent
86bf47a32e
commit
a3cd5f4f1d
4 changed files with 14 additions and 7 deletions
|
@ -73,7 +73,7 @@
|
||||||
".trade_history_entry",
|
".trade_history_entry",
|
||||||
qty: trade_entry.account_trade.qty,
|
qty: trade_entry.account_trade.qty,
|
||||||
security: trade_entry.account_trade.security.ticker,
|
security: trade_entry.account_trade.security.ticker,
|
||||||
price: format_money(trade_entry.account_trade.price)
|
price: trade_entry.account_trade.price_money.format
|
||||||
) %></p>
|
) %></p>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -21,8 +21,7 @@
|
||||||
[["Total value", "balance"], ["Holdings", "holdings_balance"], ["Cash", "cash_balance"]],
|
[["Total value", "balance"], ["Holdings", "holdings_balance"], ["Cash", "cash_balance"]],
|
||||||
{ selected: chart_view },
|
{ selected: chart_view },
|
||||||
class: "border border-secondary rounded-lg text-sm pr-7 cursor-pointer text-primary focus:outline-hidden focus:ring-0",
|
class: "border border-secondary rounded-lg text-sm pr-7 cursor-pointer text-primary focus:outline-hidden focus:ring-0",
|
||||||
data: { "auto-submit-form-target": "auto" }
|
data: { "auto-submit-form-target": "auto" } %>
|
||||||
%>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= period_select form: form, selected: period %>
|
<%= period_select form: form, selected: period %>
|
||||||
|
|
|
@ -13,7 +13,7 @@ module Money::Formatting
|
||||||
local_option_overrides = locale_options(locale)
|
local_option_overrides = locale_options(locale)
|
||||||
|
|
||||||
{
|
{
|
||||||
unit: currency.symbol,
|
unit: get_symbol,
|
||||||
precision: currency.default_precision,
|
precision: currency.default_precision,
|
||||||
delimiter: currency.delimiter,
|
delimiter: currency.delimiter,
|
||||||
separator: currency.separator,
|
separator: currency.separator,
|
||||||
|
@ -22,6 +22,14 @@ module Money::Formatting
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def get_symbol
|
||||||
|
if currency.symbol == "$" && currency.iso_code != "USD"
|
||||||
|
[ currency.iso_code.first(2), currency.symbol ].join
|
||||||
|
else
|
||||||
|
currency.symbol
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def locale_options(locale)
|
def locale_options(locale)
|
||||||
case [ currency.iso_code, locale.to_sym ]
|
case [ currency.iso_code, locale.to_sym ]
|
||||||
when [ "EUR", :nl ], [ "EUR", :pt ]
|
when [ "EUR", :nl ], [ "EUR", :pt ]
|
||||||
|
|
|
@ -33,7 +33,7 @@ class Security::PriceTest < ActiveSupport::TestCase
|
||||||
tomorrow = Date.current + 1.day
|
tomorrow = Date.current + 1.day
|
||||||
|
|
||||||
@provider.expects(:fetch_security_prices)
|
@provider.expects(:fetch_security_prices)
|
||||||
.with(ticker: security.ticker, mic_code: security.exchange_mic, start_date: tomorrow, end_date: tomorrow)
|
.with(ticker: security.ticker, mic_code: security.exchange_operating_mic, start_date: tomorrow, end_date: tomorrow)
|
||||||
.once
|
.once
|
||||||
.returns(
|
.returns(
|
||||||
OpenStruct.new(
|
OpenStruct.new(
|
||||||
|
@ -54,7 +54,7 @@ class Security::PriceTest < ActiveSupport::TestCase
|
||||||
Security::Price.delete_all # Clear any existing prices
|
Security::Price.delete_all # Clear any existing prices
|
||||||
|
|
||||||
@provider.expects(:fetch_security_prices)
|
@provider.expects(:fetch_security_prices)
|
||||||
.with(ticker: security.ticker, mic_code: security.exchange_mic, start_date: Date.current, end_date: Date.current)
|
.with(ticker: security.ticker, mic_code: security.exchange_operating_mic, start_date: Date.current, end_date: Date.current)
|
||||||
.once
|
.once
|
||||||
.returns(OpenStruct.new(success?: false))
|
.returns(OpenStruct.new(success?: false))
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ class Security::PriceTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
@provider.expects(:fetch_security_prices)
|
@provider.expects(:fetch_security_prices)
|
||||||
.with(ticker: security.ticker,
|
.with(ticker: security.ticker,
|
||||||
mic_code: security.exchange_mic,
|
mic_code: security.exchange_operating_mic,
|
||||||
start_date: 2.days.ago.to_date,
|
start_date: 2.days.ago.to_date,
|
||||||
end_date: 2.days.ago.to_date)
|
end_date: 2.days.ago.to_date)
|
||||||
.returns(OpenStruct.new(success?: true, prices: [ { date: 2.days.ago.to_date, price: missing_price, currency: "USD" } ]))
|
.returns(OpenStruct.new(success?: true, prices: [ { date: 2.days.ago.to_date, price: missing_price, currency: "USD" } ]))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue