vulpemventures / marina

Liquid Wallet browser extension
MIT License
36 stars 15 forks source link

Add Money domain for FIAT & Crypto amount management #19

Open tiero opened 3 years ago

Janaka-Steph commented 3 years ago

Create a DDD Money Value Object, which will validate that the amount is valid for the chosen currency (i.e no more than 21M bitcoins!), arithmetic methods with proper rounding, currency conversion. Money should extends the existing ValueObject abstract class.

Regarding formatting, we should avoid muddying up our domain model for this. So we will add a MoneyFormatter in the presentation layer, which takes a Money argument and returns a string, such as €5.00 or 5,00€ depending on local standards. We access user language/locale preferences using native i18n API. https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/i18n

tiero commented 3 years ago

I suggest also adding domain method like toFractional(satoshis, precision) and fromFractional(float, precision)

useful in the presentation layer when displaying asset amounts