mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +02:00
Update hard-coded currency UI with currency specific params (#488)
* Update hard-coded currency UI with currency specific params * Rename extension methods to match currency option names; Move cents extension to numeric class extension * Use currency's precision to show the cents part in accounts show page --------- Co-authored-by: Sriram Krishnan <sriram@seafoodsouq.com>
This commit is contained in:
parent
1968fb0145
commit
7e883c4439
6 changed files with 78 additions and 5 deletions
|
@ -12,7 +12,7 @@ CURRENCY_OPTIONS = Hash.new { |hash, key| hash[key] = default_currency_options.d
|
|||
"NZD": { unit: "NZ$", precision: 2, delimiter: ",", separator: "." },
|
||||
"AUD": { unit: "A$", precision: 2, delimiter: ",", separator: "." },
|
||||
"KRW": { unit: "₩", precision: 0, delimiter: ",", separator: "." },
|
||||
"INR": { unit: "₹", precision: 0, delimiter: ",", separator: "." }
|
||||
"INR": { unit: "₹", precision: 2, delimiter: ",", separator: "." }
|
||||
)
|
||||
|
||||
EXCHANGE_RATE_ENABLED = ENV["OPEN_EXCHANGE_APP_ID"].present?
|
||||
|
|
11
config/initializers/numeric_extensions.rb
Normal file
11
config/initializers/numeric_extensions.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
class Numeric
|
||||
def cents(precision: 2)
|
||||
return "" unless precision.positive?
|
||||
|
||||
cents = self.to_s.split(".")[1]
|
||||
cents = "" unless cents.to_i.positive?
|
||||
|
||||
zero_padded_cents = cents.ljust(precision, "0")
|
||||
zero_padded_cents[0..precision - 1]
|
||||
end
|
||||
end
|
13
config/initializers/string_extensions.rb
Normal file
13
config/initializers/string_extensions.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
class String
|
||||
def unit
|
||||
CURRENCY_OPTIONS[self.to_sym][:unit]
|
||||
end
|
||||
|
||||
def separator
|
||||
CURRENCY_OPTIONS[self.to_sym][:separator]
|
||||
end
|
||||
|
||||
def precision
|
||||
CURRENCY_OPTIONS[self.to_sym][:precision]
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue