| 1 | import 'package:cw_core/amount/money.dart'; |
| 2 | import 'package:cw_core/currency.dart'; |
| 3 | import 'package:cw_core/enumerable_item.dart'; |
| 4 | |
| 5 | class FiatCurrency extends EnumerableItem<String> with Serializable<String> implements Currency { |
| 6 | const FiatCurrency({ |
| 7 | required this.symbol, |
| 8 | required this.countryCode, |
| 9 | required this.fullName, |
| 10 | this.decimals = 2, |
| 11 | }) : super(title: symbol, raw: symbol); |
| 12 | |
| 13 | final String countryCode; |
| 14 | |
| 15 | @override |
| 16 | final String fullName; |
| 17 | |
| 18 | @override |
| 19 | final int decimals; |
| 20 | |
| 21 | @override |
| 22 | final String symbol; |
| 23 | |
| 24 | static List<FiatCurrency> get all => _all.values.toList(); |
| 25 | |
| 26 | static List<FiatCurrency> get currenciesAvailableToBuyWith => [ |
| 27 | amd, |
| 28 | aud, |
| 29 | bgn, |
| 30 | brl, |
| 31 | cad, |
| 32 | chf, |
| 33 | clp, |
| 34 | cop, |
| 35 | czk, |
| 36 | dkk, |
| 37 | egp, |
| 38 | eur, |
| 39 | gbp, |
| 40 | gtq, |
| 41 | hkd, |
| 42 | hrk, |
| 43 | huf, |
| 44 | idr, |
| 45 | ils, |
| 46 | inr, |
| 47 | isk, |
| 48 | jpy, |
| 49 | krw, |
| 50 | mad, |
| 51 | mxn, |
| 52 | myr, |
| 53 | ngn, |
| 54 | nok, |
| 55 | nzd, |
| 56 | php, |
| 57 | pkr, |
| 58 | pln, |
| 59 | ron, |
| 60 | sek, |
| 61 | sgd, |
| 62 | thb, |
| 63 | twd, |
| 64 | usd, |
| 65 | vnd, |
| 66 | zar, |
| 67 | tur, |
| 68 | kes, |
| 69 | ]; |
| 70 | |
| 71 | static const amd = FiatCurrency(symbol: 'AMD', countryCode: "arm", fullName: "Armenian Dram"); |
| 72 | static const ars = FiatCurrency(symbol: 'ARS', countryCode: "arg", fullName: "Argentine Peso"); |
| 73 | static const aud = FiatCurrency(symbol: 'AUD', countryCode: "aus", fullName: "Australian Dollar"); |
| 74 | static const bdt = FiatCurrency(symbol: 'BDT', countryCode: "bgd", fullName: "Bangladeshi Taka"); |
| 75 | static const bgn = FiatCurrency(symbol: 'BGN', countryCode: "bgr", fullName: "Bulgarian Lev"); |
| 76 | static const brl = FiatCurrency(symbol: 'BRL', countryCode: "bra", fullName: "Brazilian Real"); |
| 77 | static const cad = FiatCurrency(symbol: 'CAD', countryCode: "cad", fullName: "Canadian Dollar"); |
| 78 | static const chf = FiatCurrency(symbol: 'CHF', countryCode: "che", fullName: "Swiss Franc"); |
| 79 | static const clp = FiatCurrency(symbol: 'CLP', countryCode: "chl", fullName: "Chilean Peso"); |
| 80 | static const cny = FiatCurrency(symbol: 'CNY', countryCode: "chn", fullName: "Chinese Yuan"); |
| 81 | static const cop = FiatCurrency(symbol: 'COP', countryCode: "col", fullName: "Colombian Peso"); |
| 82 | static const czk = FiatCurrency(symbol: 'CZK', countryCode: "czk", fullName: "Czech Koruna"); |
| 83 | static const dkk = FiatCurrency(symbol: 'DKK', countryCode: "dnk", fullName: "Danish Krone"); |
| 84 | static const egp = FiatCurrency(symbol: 'EGP', countryCode: "egy", fullName: "Egyptian Pound"); |
| 85 | static const eur = FiatCurrency(symbol: 'EUR', countryCode: "eur", fullName: "Euro"); |
| 86 | static const gbp = FiatCurrency(symbol: 'GBP', countryCode: "gbr", fullName: "Pound Sterling"); |
| 87 | static const ghs = FiatCurrency(symbol: 'GHS', countryCode: "gha", fullName: "Ghanaian Cedi"); |
| 88 | static const gtq = |
| 89 | FiatCurrency(symbol: 'GTQ', countryCode: "gtm", fullName: "Guatemalan Quetzal"); |
| 90 | static const hkd = FiatCurrency(symbol: 'HKD', countryCode: "hkg", fullName: "Hong Kong Dollar"); |
| 91 | static const hrk = FiatCurrency(symbol: 'HRK', countryCode: "hrv", fullName: "Croatian Kuna"); |
| 92 | static const huf = FiatCurrency(symbol: 'HUF', countryCode: "hun", fullName: "Hungarian Forint"); |
| 93 | static const idr = FiatCurrency(symbol: 'IDR', countryCode: "idn", fullName: "Indonesian Rupiah"); |
| 94 | static const ils = |
| 95 | FiatCurrency(symbol: 'ILS', countryCode: "isr", fullName: "Israeli New Shekel"); |
| 96 | static const inr = FiatCurrency(symbol: 'INR', countryCode: "ind", fullName: "Indian Rupee"); |
| 97 | static const irr = FiatCurrency(symbol: 'IRR', countryCode: "irn", fullName: "Iranian Rial"); |
| 98 | static const isk = |
| 99 | FiatCurrency(symbol: 'ISK', countryCode: "isl", fullName: "Icelandic Krona Króna"); |
| 100 | static const jpy = FiatCurrency(symbol: 'JPY', countryCode: "jpn", fullName: "Japanese Yen"); |
| 101 | static const krw = FiatCurrency(symbol: 'KRW', countryCode: "kor", fullName: "South Korean Won"); |
| 102 | static const mad = FiatCurrency(symbol: 'MAD', countryCode: "mar", fullName: "Moroccan Dirham"); |
| 103 | static const mxn = FiatCurrency(symbol: 'MXN', countryCode: "mex", fullName: "Mexican Peso"); |
| 104 | static const myr = FiatCurrency(symbol: 'MYR', countryCode: "mys", fullName: "Malaysian Ringgit"); |
| 105 | static const ngn = FiatCurrency(symbol: 'NGN', countryCode: "nga", fullName: "Nigerian Naira"); |
| 106 | static const nok = FiatCurrency(symbol: 'NOK', countryCode: "nor", fullName: "Norwegian Krone"); |
| 107 | static const nzd = |
| 108 | FiatCurrency(symbol: 'NZD', countryCode: "nzl", fullName: "New Zealand Dollar"); |
| 109 | static const php = FiatCurrency(symbol: 'PHP', countryCode: "phl", fullName: "Philippine Peso"); |
| 110 | static const pkr = FiatCurrency(symbol: 'PKR', countryCode: "pak", fullName: "Pakistani Rupee"); |
| 111 | static const pln = |
| 112 | FiatCurrency(symbol: 'PLN', countryCode: "pol", fullName: "Poland Zloty złoty"); |
| 113 | static const ron = FiatCurrency(symbol: 'RON', countryCode: "rou", fullName: "Romanian Leu"); |
| 114 | static const rub = FiatCurrency(symbol: 'RUB', countryCode: "rus", fullName: "Russian Ruble"); |
| 115 | static const sar = FiatCurrency(symbol: 'SAR', countryCode: "sau", fullName: "Saudi Riyal"); |
| 116 | static const sek = FiatCurrency(symbol: 'SEK', countryCode: "swe", fullName: "Swedish Krona"); |
| 117 | static const sgd = FiatCurrency(symbol: 'SGD', countryCode: "sgp", fullName: "Singapore Dollar"); |
| 118 | static const thb = |
| 119 | FiatCurrency(symbol: 'THB', countryCode: "tha", fullName: "New Thaiwan Dollar"); |
| 120 | static const twd = FiatCurrency(symbol: 'TWD', countryCode: "twn", fullName: "Thai Baht"); |
| 121 | static const uah = FiatCurrency(symbol: 'UAH', countryCode: "ukr", fullName: "Ukrainian Hryvnia"); |
| 122 | static const usd = |
| 123 | FiatCurrency(symbol: 'USD', countryCode: "usa", fullName: "United States Dollar"); |
| 124 | static const vef = |
| 125 | FiatCurrency(symbol: 'VEF', countryCode: "ven", fullName: "Venezuelan Bolivar Bolívar"); |
| 126 | static const vnd = |
| 127 | FiatCurrency(symbol: 'VND', countryCode: "vnm", fullName: "Vietnamese Dong đồng"); |
| 128 | static const zar = |
| 129 | FiatCurrency(symbol: 'ZAR', countryCode: "saf", fullName: "South African Rand"); |
| 130 | static const tur = FiatCurrency(symbol: 'TRY', countryCode: "tur", fullName: "Turkish Lira"); |
| 131 | static const kes = FiatCurrency(symbol: 'KES', countryCode: "ken", fullName: "Kenyan Shillings"); |
| 132 | |
| 133 | static final _all = { |
| 134 | FiatCurrency.amd.raw: FiatCurrency.amd, |
| 135 | FiatCurrency.ars.raw: FiatCurrency.ars, |
| 136 | FiatCurrency.aud.raw: FiatCurrency.aud, |
| 137 | FiatCurrency.bdt.raw: FiatCurrency.bdt, |
| 138 | FiatCurrency.bgn.raw: FiatCurrency.bgn, |
| 139 | FiatCurrency.brl.raw: FiatCurrency.brl, |
| 140 | FiatCurrency.cad.raw: FiatCurrency.cad, |
| 141 | FiatCurrency.chf.raw: FiatCurrency.chf, |
| 142 | FiatCurrency.clp.raw: FiatCurrency.clp, |
| 143 | FiatCurrency.cny.raw: FiatCurrency.cny, |
| 144 | FiatCurrency.cop.raw: FiatCurrency.cop, |
| 145 | FiatCurrency.czk.raw: FiatCurrency.czk, |
| 146 | FiatCurrency.dkk.raw: FiatCurrency.dkk, |
| 147 | FiatCurrency.egp.raw: FiatCurrency.egp, |
| 148 | FiatCurrency.eur.raw: FiatCurrency.eur, |
| 149 | FiatCurrency.gbp.raw: FiatCurrency.gbp, |
| 150 | FiatCurrency.ghs.raw: FiatCurrency.ghs, |
| 151 | FiatCurrency.gtq.raw: FiatCurrency.gtq, |
| 152 | FiatCurrency.hkd.raw: FiatCurrency.hkd, |
| 153 | FiatCurrency.hrk.raw: FiatCurrency.hrk, |
| 154 | FiatCurrency.huf.raw: FiatCurrency.huf, |
| 155 | FiatCurrency.idr.raw: FiatCurrency.idr, |
| 156 | FiatCurrency.ils.raw: FiatCurrency.ils, |
| 157 | FiatCurrency.inr.raw: FiatCurrency.inr, |
| 158 | FiatCurrency.irr.raw: FiatCurrency.irr, |
| 159 | FiatCurrency.isk.raw: FiatCurrency.isk, |
| 160 | FiatCurrency.jpy.raw: FiatCurrency.jpy, |
| 161 | FiatCurrency.krw.raw: FiatCurrency.krw, |
| 162 | FiatCurrency.mad.raw: FiatCurrency.mad, |
| 163 | FiatCurrency.mxn.raw: FiatCurrency.mxn, |
| 164 | FiatCurrency.myr.raw: FiatCurrency.myr, |
| 165 | FiatCurrency.ngn.raw: FiatCurrency.ngn, |
| 166 | FiatCurrency.nok.raw: FiatCurrency.nok, |
| 167 | FiatCurrency.nzd.raw: FiatCurrency.nzd, |
| 168 | FiatCurrency.php.raw: FiatCurrency.php, |
| 169 | FiatCurrency.pkr.raw: FiatCurrency.pkr, |
| 170 | FiatCurrency.pln.raw: FiatCurrency.pln, |
| 171 | FiatCurrency.ron.raw: FiatCurrency.ron, |
| 172 | FiatCurrency.rub.raw: FiatCurrency.rub, |
| 173 | FiatCurrency.sar.raw: FiatCurrency.sar, |
| 174 | FiatCurrency.sek.raw: FiatCurrency.sek, |
| 175 | FiatCurrency.sgd.raw: FiatCurrency.sgd, |
| 176 | FiatCurrency.thb.raw: FiatCurrency.thb, |
| 177 | FiatCurrency.twd.raw: FiatCurrency.twd, |
| 178 | FiatCurrency.uah.raw: FiatCurrency.uah, |
| 179 | FiatCurrency.usd.raw: FiatCurrency.usd, |
| 180 | FiatCurrency.vef.raw: FiatCurrency.vef, |
| 181 | FiatCurrency.vnd.raw: FiatCurrency.vnd, |
| 182 | FiatCurrency.zar.raw: FiatCurrency.zar, |
| 183 | FiatCurrency.tur.raw: FiatCurrency.tur, |
| 184 | FiatCurrency.kes.raw: FiatCurrency.kes, |
| 185 | }; |
| 186 | |
| 187 | static FiatCurrency deserialize({required String raw}) => _all[raw] ?? FiatCurrency.usd; |
| 188 | |
| 189 | @override |
| 190 | bool operator ==(Object other) => other is FiatCurrency && other.raw == raw; |
| 191 | |
| 192 | @override |
| 193 | int get hashCode => raw.hashCode ^ title.hashCode; |
| 194 | |
| 195 | @override |
| 196 | String get name => raw; |
| 197 | |
| 198 | @override |
| 199 | String? get tag => null; |
| 200 | |
| 201 | @override |
| 202 | String get iconPath => "assets/images/flags/$countryCode.png"; |
| 203 | |
| 204 | @override |
| 205 | Money parseAmount(String value) => Money.parse(value, this); |
| 206 | |
| 207 | @override |
| 208 | Money? tryParseAmount(String value) => Money.tryParse(value, this); |
| 209 | } |