2023-12-16 08:49:23 +00:00
|
|
|
import 'package:cw_core/format_amount.dart';
|
2023-10-02 14:17:35 +00:00
|
|
|
import 'package:cw_core/transaction_direction.dart';
|
2023-12-16 08:49:23 +00:00
|
|
|
import 'package:cw_core/transaction_info.dart';
|
2024-03-16 10:55:03 +00:00
|
|
|
import 'package:cw_zano/api/model/transfer.dart';
|
2024-03-18 12:15:54 +00:00
|
|
|
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,
|
|
|
|
required this.amount,
|
|
|
|
required this.fee,
|
|
|
|
required this.assetId,
|
|
|
|
required this.confirmations,
|
|
|
|
required this.tokenSymbol,
|
2024-03-18 12:15:54 +00:00
|
|
|
required this.decimalPoint,
|
2024-03-16 10:55:03 +00:00
|
|
|
});
|
|
|
|
|
2024-04-09 10:59:43 +00:00
|
|
|
ZanoTransactionInfo.fromTransfer(Transfer transfer,
|
|
|
|
{required int confirmations,
|
|
|
|
required bool isIncome,
|
|
|
|
required String assetId,
|
|
|
|
required int amount,
|
|
|
|
this.tokenSymbol = 'ZANO',
|
|
|
|
this.decimalPoint = ZanoFormatter.defaultDecimalPoint})
|
2024-03-16 10:55:03 +00:00
|
|
|
: id = transfer.txHash,
|
|
|
|
height = transfer.height,
|
2024-04-09 10:59:43 +00:00
|
|
|
direction = isIncome ? TransactionDirection.incoming : TransactionDirection.outgoing,
|
2024-03-16 10:55:03 +00:00
|
|
|
date = DateTime.fromMillisecondsSinceEpoch(transfer.timestamp * 1000),
|
2024-04-09 10:59:43 +00:00
|
|
|
amount = amount,
|
2024-03-16 10:55:03 +00:00
|
|
|
fee = transfer.fee,
|
2024-04-09 10:59:43 +00:00
|
|
|
assetId = assetId,
|
|
|
|
confirmations = confirmations,
|
|
|
|
isPending = false,
|
|
|
|
recipientAddress = transfer.remoteAddresses.isNotEmpty ? transfer.remoteAddresses.first : '' {
|
|
|
|
additionalInfo = <String, dynamic>{
|
|
|
|
'comment': transfer.comment,
|
|
|
|
};
|
|
|
|
}
|
2023-12-14 04:51:16 +00:00
|
|
|
|
2023-10-02 14:17:35 +00:00
|
|
|
final String id;
|
|
|
|
final int height;
|
|
|
|
final TransactionDirection direction;
|
|
|
|
final DateTime date;
|
|
|
|
final bool isPending;
|
|
|
|
final int amount;
|
|
|
|
final int fee;
|
|
|
|
final int confirmations;
|
2024-03-18 12:15:54 +00:00
|
|
|
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;
|
|
|
|
late String assetId;
|
2023-10-02 14:17:35 +00:00
|
|
|
String? _fiatAmount;
|
|
|
|
String? key;
|
|
|
|
|
|
|
|
@override
|
2024-03-18 12:15:54 +00:00
|
|
|
String amountFormatted() => '${formatAmount(ZanoFormatter.intAmountToString(amount, decimalPoint))} $tokenSymbol';
|
2023-10-02 14:17:35 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
String fiatAmount() => _fiatAmount ?? '';
|
|
|
|
|
|
|
|
@override
|
|
|
|
void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount);
|
|
|
|
|
|
|
|
@override
|
2024-03-18 12:15:54 +00:00
|
|
|
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
|
|
|
}
|