1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00
Maybe/app/models/exchange_rate/provided.rb
Jakub Kottnauer 483d67846c
Fix foreign account sync crash (#794)
* Fix foreign account sync crash

* Refactor synth provider and show UI error if not configured

* Generate error message on missing exchange rates while converting balances

* Ignore sync messaged in i18n-tasks unused

* Generate missing exchange rate error during entry normalization

* Update alert classes
2024-05-27 12:10:28 -04:00

26 lines
678 B
Ruby

module ExchangeRate::Provided
extend ActiveSupport::Concern
include Providable
class_methods do
private
def fetch_rate_from_provider(from:, to:, date:)
return nil unless exchange_rates_provider.configured?
response = exchange_rates_provider.fetch_exchange_rate \
from: Money::Currency.new(from).iso_code,
to: Money::Currency.new(to).iso_code,
date: date
if response.success?
ExchangeRate.new \
base_currency: from,
converted_currency: to,
rate: response.rate,
date: date
else
raise response.error
end
end
end
end