| 1 | import 'package:cw_core/amount/money.dart'; |
| 2 | import 'package:cw_core/crypto_currency.dart'; |
| 3 | import 'package:cw_core/transaction_info.dart'; |
| 4 | import 'package:cw_core/wownero_amount_format.dart'; |
| 5 | import 'package:cw_core/parseBoolFromString.dart'; |
| 6 | import 'package:cw_core/transaction_direction.dart'; |
| 7 | import 'package:cw_core/format_amount.dart'; |
| 8 | import 'package:cw_wownero/api/transaction_history.dart'; |
| 9 | |
| 10 | class WowneroTransactionInfo extends TransactionInfo { |
| 11 | WowneroTransactionInfo(this.txHash, this.height, this.direction, this.date, this.isPending, |
| 12 | this.amount, this.accountIndex, this.addressIndex, this.fee, this.confirmations) |
| 13 | : id = "${txHash}_${amount}_${accountIndex}_${addressIndex}"; |
| 14 | |
| 15 | WowneroTransactionInfo.fromMap(Map<String, Object?> map) |
| 16 | : id = "${map['hash']}_${map['amount']}_${map['accountIndex']}_${map['addressIndex']}", |
| 17 | txHash = map['hash'] as String, |
| 18 | height = (map['height'] ?? 0) as int, |
| 19 | direction = map['direction'] != null |
| 20 | ? parseTransactionDirectionFromNumber(map['direction'] as String) |
| 21 | : TransactionDirection.incoming, |
| 22 | date = DateTime.fromMillisecondsSinceEpoch( |
| 23 | (int.tryParse(map['timestamp'] as String? ?? '') ?? 0) * 1000), |
| 24 | isPending = parseBoolFromString(map['isPending'] as String), |
| 25 | amount = Money.fromInt(map['amount'] as int, CryptoCurrency.wow), |
| 26 | accountIndex = int.parse(map['accountIndex'] as String), |
| 27 | addressIndex = map['addressIndex'] as int, |
| 28 | confirmations = map['confirmations'] as int, |
| 29 | key = getTxKey((map['hash'] ?? '') as String), |
| 30 | fee = Money.fromInt(map['fee'] as int? ?? 0, CryptoCurrency.wow) { |
| 31 | additionalInfo = <String, dynamic>{ |
| 32 | 'key': key, |
| 33 | 'accountIndex': accountIndex, |
| 34 | 'addressIndex': addressIndex |
| 35 | }; |
| 36 | } |
| 37 | |
| 38 | final String id; |
| 39 | final String txHash; |
| 40 | final int height; |
| 41 | final TransactionDirection direction; |
| 42 | final DateTime date; |
| 43 | final int accountIndex; |
| 44 | final bool isPending; |
| 45 | final Money amount; |
| 46 | final Money fee; |
| 47 | final int addressIndex; |
| 48 | final int confirmations; |
| 49 | String? recipientAddress; |
| 50 | String? key; |
| 51 | String? _fiatAmount; |
| 52 | |
| 53 | @override |
| 54 | String fiatAmount() => _fiatAmount ?? ''; |
| 55 | |
| 56 | @override |
| 57 | void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount); |
| 58 | } |