Closed ayrat555 closed 2 years ago
Thanks very much for the report. I have updated the documentation in commit 18b8c4.
The bigger issue is that it appears I have not actually implemented the code to call the callback. That not great, but I have a 19 hour plan flight coming up soon so I will get this fixed in the next 24 hours.
Custom currencies themselves are implemented, documented and tested. Just not the callback. The callback is there to provide a means of loading custom currencies at application startup time.
On reflection, adding a callback to the supervisor options is a poor design decisions. The callback is being invoked but, as you say, poorly documented.
I proposed undocumenting the callback and deprecating it. And then add a section to the documentation on how to hydrate the custom currencies. Which is most cases is nothing more than adding a call to the appropriate user function in the application start function.
Thoughts?
@kipcole9 sounds great
The idea of creating currencies outside of the supervision tree was very tempting. But it seemed not the way it has to be done according to docs.
btw I have another suggestion. do currencies have to be consistent with CLDR
? In the current implementation, BNB will have XBN
code, USDT - XUS
(there is already a different stable coin called XUSD - https://coinmarketcap.com/currencies/xusd-stable/)
Can this restriction be lifted so users can assign any code to the currency?
The supervision tree is there to hold the ets
table that holds the custom currency definitions.
As for the use of currency codes, ex_money
tries really hard to apply ISO4217 which is clear that non-standard currency codes need to start with an X
. I added that :alt_code
to the Cldr.Currency.t/0
struct to provide a way to store the commonly used code (like "BNB").
My plan (hope?) is that being ISO4217 compliant ensure there won't be a currency code clash, but still have a way to store a "preferred"/"alternate" currency code as well. At this time I don't think I have exposed an option to print/render a currency using its alternate code.
The other reason for keeping aligned with CLDR (and ISO4217) is that custom currencies don't have any translations whereas all known currencies do. Using only valid custom currencies (ie starting with "X") signals clearly that translations aren't available.
I'm more than happy to try to find a way for ex_money
to treat crypto currencies as first class citizens. I hope that can be done without going outside ISO4217.
For posterity, here are some examples of the challenges of using ISO4217 codes for crypto:
Crypto | Unofficial ISO Code | ISO Conflict |
---|---|---|
Bitcoin | XBT | Conflicts with ISO 4217 because BT stands for Bhutan. |
Ethereum | ETH | Conflicts with ISO 4217 because ET stands for Ethiopia. |
Bitcoin Cash | XBC | Is identical to the ISO 4217 code for the European Unit of Account 9. |
Solana | SOL | Is identical to the ISO 4217 code for the official currency of Peru. |
There is good news. There is now ISO 24165 for defining and registering Digital Tokens (a definition within which crypto currencies fit).
There is an official registry which means there is a path to a formal implementation in ex_money
.
Very glad you opened this issue - it made me update my research and discover a path forward. I'm going to close this issue but will open a new one related to implementing ISO 24165.
I have added a new repo, digital_token, to implement crypto currencies and other digital tokens. The project aims are documented at https://github.com/kipcole9/digital_token/issues/1
Also published ex_money 5.11.0 that supports ISO 24165 digital tokens. Also published ex_cldr_numbers version 2.27.0 which is required to support formatting of digital token-based money and numbers.
Lastly, also updated the README to remove references to the genserver callback option. Thanks for your patience and collaboration. Was a fun feature to add.
Hello!
Thank you for your hard work.
It seems docs related to custom currencies can be improved. It's not clear why MFA function accepts two arguments. Also, it's not clear what this callback should return