cake_wallet/cw_zano/lib/model/zano_transaction_info.dart

77 lines
2.5 KiB
Dart
Raw Normal View History

import 'package:cw_core/format_amount.dart';
2023-10-02 14:17:35 +00:00
import 'package:cw_core/transaction_direction.dart';
import 'package:cw_core/transaction_info.dart';
2024-03-16 10:55:03 +00:00
import 'package:cw_zano/api/model/transfer.dart';
import 'package:cw_zano/zano_formatter.dart';
2023-10-02 14:17:35 +00:00
class ZanoTransactionInfo extends TransactionInfo {
2024-03-16 10:55:03 +00:00
ZanoTransactionInfo({
required this.id,
required this.height,
required this.direction,
required this.date,
required this.isPending,
2024-08-07 12:32:47 +00:00
required this.zanoAmount,
2024-03-16 10:55:03 +00:00
required this.fee,
required this.confirmations,
required this.tokenSymbol,
required this.decimalPoint,
required String assetId,
}) : amount = zanoAmount.isValidInt ? zanoAmount.toInt() : 0 {
additionalInfo['assetId'] = assetId;
}
2024-03-16 10:55:03 +00:00
ZanoTransactionInfo.fromTransfer(Transfer transfer,
{required int confirmations,
required bool isIncome,
required String assetId,
2024-08-07 12:32:47 +00:00
required BigInt amount,
this.tokenSymbol = 'ZANO',
this.decimalPoint = ZanoFormatter.defaultDecimalPoint})
2024-03-16 10:55:03 +00:00
: id = transfer.txHash,
height = transfer.height,
direction = isIncome ? TransactionDirection.incoming : TransactionDirection.outgoing,
2024-03-16 10:55:03 +00:00
date = DateTime.fromMillisecondsSinceEpoch(transfer.timestamp * 1000),
2024-08-07 12:32:47 +00:00
zanoAmount = amount,
amount = amount.isValidInt ? amount.toInt() : 0,
2024-03-16 10:55:03 +00:00
fee = transfer.fee,
confirmations = confirmations,
isPending = false,
recipientAddress = transfer.remoteAddresses.isNotEmpty ? transfer.remoteAddresses.first : '' {
additionalInfo = <String, dynamic>{
'comment': transfer.comment,
'assetId': assetId,
};
}
String get assetId => additionalInfo["assetId"] as String;
set assetId(String newId) => additionalInfo["assetId"] = newId;
2023-10-02 14:17:35 +00:00
final String id;
final int height;
final TransactionDirection direction;
final DateTime date;
final bool isPending;
2024-08-07 12:32:47 +00:00
final BigInt zanoAmount;
2023-10-02 14:17:35 +00:00
final int amount;
final int fee;
final int confirmations;
final int decimalPoint;
2023-10-02 14:17:35 +00:00
late String recipientAddress;
2024-03-16 10:55:03 +00:00
final String tokenSymbol;
2023-10-02 14:17:35 +00:00
String? _fiatAmount;
String? key;
@override
2024-08-07 12:32:47 +00:00
String amountFormatted() => '${formatAmount(ZanoFormatter.bigIntAmountToString(zanoAmount, decimalPoint))} $tokenSymbol';
2023-10-02 14:17:35 +00:00
@override
String fiatAmount() => _fiatAmount ?? '';
@override
void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount);
@override
String feeFormatted() => '${formatAmount(ZanoFormatter.intAmountToString(fee))} $feeCurrency';
2024-03-16 10:55:03 +00:00
String get feeCurrency => 'ZANO';
2023-10-02 14:17:35 +00:00
}