-
Notifications
You must be signed in to change notification settings - Fork 43
feat: Add crypto currency support with global toggle #401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
193878d
to
1a371a5
Compare
9047b40
to
c64f55d
Compare
Add support for cryptocurrencies with USDC as the first implementation. This feature is opt-in and disabled by default. - Add crypto_currencies config option (default: false) - Add crypto.yml for cryptocurrency definitions - Implement crypto currency lookup in Currency class - Add load_crypto_currencies method to Currency::Loader - Add test - Update README with usage documentationt
c44bcb1
to
f86bbe0
Compare
disambiguate_symbol: USDC | ||
alternate_symbols: [] | ||
subunit: Cent | ||
subunit_to_unit: 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why two decimal places see; #398 (comment) for more context. In addition if there is a need to override we can do as mentioned on the same comment.
lib/money/currency/loader.rb
Outdated
@@ -5,14 +5,20 @@ | |||
class Money | |||
class Currency | |||
module Loader | |||
CURRENCY_DATA_PATH = File.expand_path("../../../../config", __FILE__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
CURRENCY_DATA_PATH = File.expand_path("../../../../config", __FILE__) | |
CURRENCY_DATA_PATH = File.expand_path("../../../config", __dir__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed 👍🏽
spec/currency_spec.rb
Outdated
expect(currency.iso_code).to eq('USDC') | ||
expect(currency.symbol).to eq('USDC') | ||
|
||
Money.config = old_config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Does this been to be in an ensure
block?
If the test fails I'm assuming the config won't be restored to the previous state and the custom config might affect other tests. I'm guessing we need something like:
old_config = Money.config
begin
# the test
ensure
Money.config = old_config
end
I wonder if it's worth adding a Edit: My suggestion isn't thread-safe, and refactoring with_config
method here?Money.config
to be thread-safe is likely not worthwhile. Maybe a test helper?
def with_config(config)
old_config = Money.config
Money.config = config
yield
ensure
Money.config = old_config
end
spec/spec_helper.rb
Outdated
old_config = Money.config | ||
Money.config = Money::Config.new.tap do |config| | ||
config.default_currency = default_currency if default_currency | ||
config.legacy_json_format! if legacy_json_format | ||
config.legacy_deprecations! if legacy_deprecations | ||
config.legacy_default_currency! if legacy_default_currency | ||
config.crypto_currencies = true if crypto_currencies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
config.crypto_currencies = true if crypto_currencies | |
config.crypto_currencies = crypto_currencies unless crypto_currencies.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a boolean and then just config.crypto_currencies = crypto_currencies
?
spec/spec_helper.rb
Outdated
old_config = Money.config | ||
Money.config = Money::Config.new.tap do |config| | ||
config.default_currency = default_currency if default_currency | ||
config.legacy_json_format! if legacy_json_format | ||
config.legacy_deprecations! if legacy_deprecations | ||
config.legacy_default_currency! if legacy_default_currency | ||
config.crypto_currencies = true if crypto_currencies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a boolean and then just config.crypto_currencies = crypto_currencies
?
e41a0a0
to
cdb107a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing all the comments. LGTM!
90c56f8
to
716b09d
Compare
Adds support for cryptocurrencies to the Money gem, starting with USDC stablecoin. It's implemented through a clean configuration system that makes crypto handling seamless while maintaining backward compatibility.
Changes
Breaking changes
None! The feature is opt-in and disabled by default, so existing code will continue to work without any changes.
Configuration System
Before
After
Example Usage