Skip to content

Commit

Permalink
feature: Add support for ETH currency in Money library
Browse files Browse the repository at this point in the history
  • Loading branch information
douglas-franca committed Mar 18, 2024
1 parent 73b84b5 commit 6a63723
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Dave Kroondyk
Diego Aguir Selzlein
Doug Droper
Douglas Miller
Douglas Suptitz Franca
Ed Saunders
Edwin Vlieg
Eloy
Expand Down
15 changes: 15 additions & 0 deletions config/currency_non_iso.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,20 @@
"thousands_separator": ",",
"iso_numeric": "",
"smallest_denomination": 1
},
"eth": {
"priority": 100,
"iso_code": "ETH",
"name": "Ethereum",
"symbol": "Ξ",
"alternate_symbols": [],
"subunit": "Wei",
"subunit_to_unit": 100000000,
"symbol_first": true,
"html_entity": "Ξ",
"decimal_mark": ".",
"thousands_separator": ",",
"iso_numeric": "",
"smallest_denomination": 1
}
}
1 change: 1 addition & 0 deletions spec/currency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ def to_s

it "returns false if the currency is not iso" do
expect(described_class.new(:btc).iso?).to be false
expect(described_class.new(:eth).iso?).to be false
end
end

Expand Down
28 changes: 16 additions & 12 deletions spec/money/formatting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -914,23 +914,27 @@
end

describe ":drop_trailing_zeros option" do
currencies = ["BTC", "BCH", "ETH"]

specify "(drop_trailing_zeros: true) works as documented" do
expect(Money.new(89000, "BTC").format(drop_trailing_zeros: true, symbol: false)).to eq "0.00089"
expect(Money.new(89000, "BCH").format(drop_trailing_zeros: true, symbol: false)).to eq "0.00089"
expect(Money.new(100089000, "BTC").format(drop_trailing_zeros: true, symbol: false)).to eq "1.00089"
expect(Money.new(100089000, "BCH").format(drop_trailing_zeros: true, symbol: false)).to eq "1.00089"
expect(Money.new(100000000, "BTC").format(drop_trailing_zeros: true, symbol: false)).to eq "1"
expect(Money.new(100000000, "BCH").format(drop_trailing_zeros: true, symbol: false)).to eq "1"
amounts = { 89000 => "0.00089", 100089000 => "1.00089", 100000000 => "1" }

currencies.each do |currency|
amounts.each do |amount, expect|
expect(Money.new(amount, currency).format(drop_trailing_zeros: true, symbol: false)).to eq expect
end
end
expect(Money.new(110, "AUD").format(drop_trailing_zeros: true, symbol: false)).to eq "1.1"
end

specify "(drop_trailing_zeros: false) works as documented" do
expect(Money.new(89000, "BTC").format(drop_trailing_zeros: false, symbol: false)).to eq "0.00089000"
expect(Money.new(89000, "BCH").format(drop_trailing_zeros: false, symbol: false)).to eq "0.00089000"
expect(Money.new(100089000, "BTC").format(drop_trailing_zeros: false, symbol: false)).to eq "1.00089000"
expect(Money.new(100089000, "BCH").format(drop_trailing_zeros: false, symbol: false)).to eq "1.00089000"
expect(Money.new(100000000, "BTC").format(drop_trailing_zeros: false, symbol: false)).to eq "1.00000000"
expect(Money.new(100000000, "BCH").format(drop_trailing_zeros: false, symbol: false)).to eq "1.00000000"
amounts = { 89000 => "0.00089000", 100089000 => "1.00089000", 100000000 => "1.00000000"}

currencies.each do |currency|
amounts.each do |amount, expect|
expect(Money.new(amount, currency).format(drop_trailing_zeros: false, symbol: false)).to eq expect
end
end
expect(Money.new(110, "AUD").format(drop_trailing_zeros: false, symbol: false)).to eq "1.10"
end
end
Expand Down

0 comments on commit 6a63723

Please sign in to comment.