| 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 SolanaBalance extends Balance { |
| 8 | SolanaBalance(Money balance) : super(balance, balance.copyWith(amount: BigInt.zero)); |
| 9 | |
| 10 | factory SolanaBalance.zero(Currency currency) => SolanaBalance(Money.zero(currency)); |
| 11 | |
| 12 | static SolanaBalance? 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 SolanaBalance(currency.parseAmount(decoded["balance"])); |
| 19 | } catch (e) { |
| 20 | return SolanaBalance(Money.zero(currency)); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | String toJSON() => json.encode({"balance": available.toString()}); |
| 25 | } |