dev
dart 23 lines 726 Bytes
Raw
1 import "dart:convert";
2
3 import "package:cw_core/amount/money.dart";
4 import "package:cw_core/balance.dart";
5 import "package:cw_core/currency.dart";
6
7 class EVMChainERC20Balance extends Balance {
8 EVMChainERC20Balance(Money balance) : super(balance, Money.zero(balance.currency));
9
10 String toJSON() => json.encode({"balanceInWei": available.amount.toString()});
11
12 static EVMChainERC20Balance? fromJSON(String? jsonSource, Currency currency) {
13 if (jsonSource == null) return null;
14
15 final decoded = json.decode(jsonSource) as Map;
16
17 try {
18 return EVMChainERC20Balance(Money(BigInt.parse(decoded["balanceInWei"]), currency));
19 } catch (e) {
20 return EVMChainERC20Balance(Money.zero(currency));
21 }
22 }
23 }