From 8d646167004cc37994759b159e529ab3f9c0309f Mon Sep 17 00:00:00 2001 From: Douglas Franca Date: Mon, 15 Apr 2024 19:36:42 -0300 Subject: [PATCH] feature: Add support for ETH currency in Money library --- AUTHORS | 1 + config/currency_non_iso.json | 15 +++++++++++++++ spec/currency_spec.rb | 1 + spec/money/formatting_spec.rb | 6 ++++++ 4 files changed, 23 insertions(+) diff --git a/AUTHORS b/AUTHORS index e8b6a56cbc..3486118217 100644 --- a/AUTHORS +++ b/AUTHORS @@ -30,6 +30,7 @@ Dave Kroondyk Diego Aguir Selzlein Doug Droper Douglas Miller +Douglas Suptitz Franca Ed Saunders Edwin Vlieg Eloy diff --git a/config/currency_non_iso.json b/config/currency_non_iso.json index 3778e4ed44..96731b87e6 100644 --- a/config/currency_non_iso.json +++ b/config/currency_non_iso.json @@ -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": 1000000000000000000, + "symbol_first": true, + "html_entity": "Ξ", + "decimal_mark": ".", + "thousands_separator": ",", + "iso_numeric": "", + "smallest_denomination": 1 } } diff --git a/spec/currency_spec.rb b/spec/currency_spec.rb index 2e01018bbc..a9eacf8d18 100644 --- a/spec/currency_spec.rb +++ b/spec/currency_spec.rb @@ -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 diff --git a/spec/money/formatting_spec.rb b/spec/money/formatting_spec.rb index 45ce525997..464d2cfd10 100644 --- a/spec/money/formatting_spec.rb +++ b/spec/money/formatting_spec.rb @@ -917,20 +917,26 @@ 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(890000000000000000, "ETH").format(drop_trailing_zeros: true, symbol: false)).to eq "0.89" 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(1000890000000000000, "ETH").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" + expect(Money.new(1000000000000000000, "ETH").format(drop_trailing_zeros: true, symbol: false)).to eq "1" 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(890000000000000000, "ETH").format(drop_trailing_zeros: false, symbol: false)).to eq "0.890000000000000000" 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(1000890000000000000, "ETH").format(drop_trailing_zeros: false, symbol: false)).to eq "1.000890000000000000" 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" + expect(Money.new(1000000000000000000, "ETH").format(drop_trailing_zeros: false, symbol: false)).to eq "1.000000000000000000" expect(Money.new(110, "AUD").format(drop_trailing_zeros: false, symbol: false)).to eq "1.10" end end