| 1 | import 'package:cw_core/amount/money.dart'; |
| 2 | import 'package:cw_core/crypto_currency.dart'; |
| 3 | import 'package:cw_core/format_amount.dart'; |
| 4 | import 'package:cw_core/transaction_direction.dart'; |
| 5 | import 'package:cw_core/transaction_info.dart'; |
| 6 | |
| 7 | class NanoTransactionInfo extends TransactionInfo { |
| 8 | NanoTransactionInfo({ |
| 9 | required this.id, |
| 10 | required this.height, |
| 11 | required Money amountRaw, |
| 12 | this.tokenSymbol = "XNO", |
| 13 | required this.direction, |
| 14 | required this.confirmed, |
| 15 | required this.date, |
| 16 | required this.confirmations, |
| 17 | required this.to, |
| 18 | required this.from, |
| 19 | }) : this.amount = amountRaw; |
| 20 | |
| 21 | final String id; |
| 22 | final int height; |
| 23 | final Money amount; |
| 24 | final TransactionDirection direction; |
| 25 | final DateTime date; |
| 26 | final bool confirmed; |
| 27 | final int confirmations; |
| 28 | final String tokenSymbol; |
| 29 | final String? to; |
| 30 | final String? from; |
| 31 | String? _fiatAmount; |
| 32 | |
| 33 | bool get isPending => !this.confirmed; |
| 34 | |
| 35 | @override |
| 36 | String fiatAmount() => _fiatAmount ?? ''; |
| 37 | |
| 38 | @override |
| 39 | void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount); |
| 40 | |
| 41 | factory NanoTransactionInfo.fromJson(Map<String, dynamic> data) { |
| 42 | return NanoTransactionInfo( |
| 43 | id: data['id'] as String, |
| 44 | height: data['height'] as int, |
| 45 | amountRaw: Money(BigInt.parse(data['amountRaw'] as String), CryptoCurrency.nano), |
| 46 | direction: parseTransactionDirectionFromInt(data['direction'] as int), |
| 47 | date: DateTime.fromMillisecondsSinceEpoch(data['date'] as int), |
| 48 | confirmed: data['confirmed'] as bool, |
| 49 | confirmations: data['confirmations'] as int, |
| 50 | tokenSymbol: data['tokenSymbol'] as String, |
| 51 | to: data['to'] as String, |
| 52 | from: data['from'] as String, |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | Map<String, dynamic> toJson() => { |
| 57 | 'id': id, |
| 58 | 'height': height, |
| 59 | 'amountRaw': amount.amount.toString(), |
| 60 | 'direction': direction.index, |
| 61 | 'date': date.millisecondsSinceEpoch, |
| 62 | 'confirmed': confirmed, |
| 63 | 'confirmations': confirmations, |
| 64 | 'tokenSymbol': tokenSymbol, |
| 65 | 'to': to, |
| 66 | 'from': from, |
| 67 | }; |
| 68 | } |