1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02:00
Maybe/app/models/exchange_rate.rb

17 lines
466 B
Ruby
Raw Normal View History

class ExchangeRate < ApplicationRecord
validates :base_currency, :converted_currency, presence: true
def self.convert(from, to, amount)
return amount unless EXCHANGE_RATE_ENABLED
rate = ExchangeRate.find_by(base_currency: from, converted_currency: to)
# TODO: Handle the case where the rate is not found
if rate.nil?
amount # Silently handle the error by returning the original amount
else
amount * rate.rate
end
end
end