refactoring mapFromInt static variable

Serhii committed Nov 21, 2022 at 21:09 UTC 196187255fcd731decee29ce1d34dd321250840e
1 file changed +7 -67
cw_core/lib/crypto_currency.dart
+7 -67
@@ -137,71 +137,11 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> {
137 static const uni = CryptoCurrency(title: 'UNI', iconPath: 'assets/images/uni_icon.png', tag: 'ETH', raw: 61);
138 static const stx = CryptoCurrency(title: 'STX', iconPath: 'assets/images/stx_icon.png', raw: 62);
139
140 - static const mapFromInt = {
141 - 0: CryptoCurrency.xmr,
142 - 1: CryptoCurrency.ada,
143 - 2: CryptoCurrency.bch,
144 - 3: CryptoCurrency.bnb,
145 - 4: CryptoCurrency.btc,
146 - 5: CryptoCurrency.dai,
147 - 6: CryptoCurrency.dash,
148 - 7: CryptoCurrency.eos,
149 - 8: CryptoCurrency.eth,
150 - 9: CryptoCurrency.ltc,
151 - 10: CryptoCurrency.nano,
152 - 11: CryptoCurrency.trx,
153 - 12: CryptoCurrency.usdt,
154 - 13: CryptoCurrency.usdterc20,
155 - 14: CryptoCurrency.xlm,
156 - 15: CryptoCurrency.xrp,
157 - 16: CryptoCurrency.xhv,
158 - 17: CryptoCurrency.xag,
159 - 18: CryptoCurrency.xau,
160 - 19: CryptoCurrency.xaud,
161 - 20: CryptoCurrency.xbtc,
162 - 21: CryptoCurrency.xcad,
163 - 22: CryptoCurrency.xchf,
164 - 23: CryptoCurrency.xcny,
165 - 24: CryptoCurrency.xeur,
166 - 25: CryptoCurrency.xgbp,
167 - 26: CryptoCurrency.xjpy,
168 - 27: CryptoCurrency.xnok,
169 - 28: CryptoCurrency.xnzd,
170 - 29: CryptoCurrency.xusd,
171 - 30: CryptoCurrency.ape,
172 - 31: CryptoCurrency.avaxc,
173 - 32: CryptoCurrency.btt,
174 - 33: CryptoCurrency.bttbsc,
175 - 34: CryptoCurrency.doge,
176 - 35: CryptoCurrency.firo,
177 - 36: CryptoCurrency.usdttrc20,
178 - 37: CryptoCurrency.hbar,
179 - 38: CryptoCurrency.sc,
180 - 39: CryptoCurrency.sol,
181 - 40: CryptoCurrency.usdc,
182 - 41: CryptoCurrency.usdcsol,
183 - 42: CryptoCurrency.zaddr,
184 - 43: CryptoCurrency.zec,
185 - 44: CryptoCurrency.zen,
186 - 45: CryptoCurrency.xvg,
187 - 46: CryptoCurrency.usdcpoly,
188 - 47: CryptoCurrency.dcr,
189 - 48: CryptoCurrency.husd,
190 - 49: CryptoCurrency.kmd,
191 - 50: CryptoCurrency.mana,
192 - 51: CryptoCurrency.maticpoly,
193 - 52: CryptoCurrency.matic,
194 - 53: CryptoCurrency.mkr,
195 - 54: CryptoCurrency.near,
196 - 55: CryptoCurrency.oxt,
197 - 56: CryptoCurrency.paxg,
198 - 57: CryptoCurrency.pivx,
199 - 58: CryptoCurrency.rune,
200 - 59: CryptoCurrency.rvn,
201 - 60: CryptoCurrency.scrt,
202 - 61: CryptoCurrency.uni,
203 - 62: CryptoCurrency.stx
204 - };
140 + static Map<int, CryptoCurrency> rawCurrencyMap =
141 + all.fold<Map<int, CryptoCurrency>>(<int, CryptoCurrency>{}, (acc, item) {
142 + acc.addAll({item.raw: item});
143 + return acc;
144 + });
145
146 static const mapFromString = {
147 'xmr': CryptoCurrency.xmr,
@@ -271,11 +211,11 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> {
211
212 static CryptoCurrency deserialize({required int raw}) {
213
274 - if (CryptoCurrency.mapFromInt[raw] == null) {
214 + if (CryptoCurrency.rawCurrencyMap[raw] == null) {
215 final s = 'Unexpected token: $raw for CryptoCurrency deserialize';
216 throw ArgumentError.value(raw, 'raw', s);
217 }
278 - return CryptoCurrency.mapFromInt[raw]!;
218 + return CryptoCurrency.rawCurrencyMap[raw]!;
219 }
220
221 static CryptoCurrency fromString(String raw) {