| 1 | import 'package:cw_core/amount/money.dart'; |
| 2 | import 'package:cw_core/crypto_currency.dart'; |
| 3 | import 'package:cw_core/transaction_direction.dart'; |
| 4 | import 'package:cw_core/transaction_info.dart'; |
| 5 | import 'package:cw_zano/api/model/transfer.dart'; |
| 6 | import 'package:cw_zano/zano_formatter.dart'; |
| 7 | |
| 8 | class ZanoTransactionInfo extends TransactionInfo { |
| 9 | ZanoTransactionInfo({ |
| 10 | required this.id, |
| 11 | required this.height, |
| 12 | required this.direction, |
| 13 | required this.date, |
| 14 | required this.isPending, |
| 15 | required this.amount, |
| 16 | required this.fee, |
| 17 | required this.confirmations, |
| 18 | required this.tokenSymbol, |
| 19 | required this.decimalPoint, |
| 20 | required String assetId, |
| 21 | }) { |
| 22 | additionalInfo['assetId'] = assetId; |
| 23 | } |
| 24 | |
| 25 | ZanoTransactionInfo.fromTransfer(Transfer transfer, |
| 26 | {required int confirmations, |
| 27 | required bool isIncome, |
| 28 | required String assetId, |
| 29 | required Money amount, |
| 30 | this.tokenSymbol = 'ZANO', |
| 31 | this.decimalPoint = ZanoFormatter.defaultDecimalPoint}) |
| 32 | : id = transfer.txHash, |
| 33 | height = transfer.height, |
| 34 | direction = isIncome ? TransactionDirection.incoming : TransactionDirection.outgoing, |
| 35 | date = DateTime.fromMillisecondsSinceEpoch(transfer.timestamp * 1000), |
| 36 | amount = amount, |
| 37 | fee = Money.fromInt(transfer.fee, CryptoCurrency.zano), |
| 38 | confirmations = confirmations, |
| 39 | isPending = confirmations < 10, |
| 40 | recipientAddress = |
| 41 | transfer.remoteAddresses.isNotEmpty ? transfer.remoteAddresses.first : '' { |
| 42 | additionalInfo = <String, dynamic>{ |
| 43 | 'comment': transfer.comment, |
| 44 | 'assetId': assetId, |
| 45 | }; |
| 46 | } |
| 47 | |
| 48 | String get assetId => additionalInfo["assetId"] as String; |
| 49 | |
| 50 | set assetId(String newId) => additionalInfo["assetId"] = newId; |
| 51 | final String id; |
| 52 | final int height; |
| 53 | final TransactionDirection direction; |
| 54 | final DateTime date; |
| 55 | final bool isPending; |
| 56 | final Money amount; |
| 57 | final Money fee; |
| 58 | final int confirmations; |
| 59 | final int decimalPoint; |
| 60 | late String recipientAddress; |
| 61 | final String tokenSymbol; |
| 62 | String? key; |
| 63 | } |