2023-07-25 15:21:49 +00:00
|
|
|
import 'package:cw_core/format_amount.dart';
|
2023-07-27 17:02:10 +00:00
|
|
|
import 'package:cw_core/transaction_direction.dart';
|
|
|
|
import 'package:cw_core/transaction_info.dart';
|
|
|
|
import 'package:cw_nano/nano_util.dart';
|
2023-07-25 15:21:49 +00:00
|
|
|
|
|
|
|
class NanoTransactionInfo extends TransactionInfo {
|
2023-07-27 17:02:10 +00:00
|
|
|
NanoTransactionInfo({
|
|
|
|
required this.id,
|
|
|
|
required this.height,
|
|
|
|
required this.amountRaw,
|
|
|
|
this.tokenSymbol = "XNO",
|
|
|
|
required this.direction,
|
|
|
|
required this.confirmed,
|
|
|
|
required this.date,
|
|
|
|
required this.confirmations,
|
|
|
|
}) : this.amount = amountRaw.toInt();
|
2023-07-25 15:21:49 +00:00
|
|
|
|
|
|
|
final String id;
|
|
|
|
final int height;
|
|
|
|
final int amount;
|
|
|
|
final BigInt amountRaw;
|
2023-07-27 17:02:10 +00:00
|
|
|
final TransactionDirection direction;
|
|
|
|
final DateTime date;
|
|
|
|
final bool confirmed;
|
2023-07-25 15:21:49 +00:00
|
|
|
final int confirmations;
|
2023-07-27 17:02:10 +00:00
|
|
|
final String tokenSymbol;
|
2023-07-25 15:21:49 +00:00
|
|
|
String? _fiatAmount;
|
|
|
|
|
2023-07-27 17:02:10 +00:00
|
|
|
bool get isPending => !this.confirmed;
|
|
|
|
|
2023-07-25 15:21:49 +00:00
|
|
|
@override
|
2023-07-27 17:02:10 +00:00
|
|
|
String amountFormatted() {
|
|
|
|
final String amt = NanoUtil.getRawAsUsableString(amountRaw.toString(), NanoUtil.rawPerNano);
|
|
|
|
final String acc = NanoUtil.getRawAccuracy(amountRaw.toString(), NanoUtil.rawPerNano);
|
|
|
|
return "$acc$amt $tokenSymbol";
|
|
|
|
}
|
2023-07-25 15:21:49 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
String fiatAmount() => _fiatAmount ?? '';
|
|
|
|
|
|
|
|
@override
|
|
|
|
void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount);
|
|
|
|
|
|
|
|
@override
|
2023-07-27 17:02:10 +00:00
|
|
|
String feeFormatted() => "0 XNO";
|
|
|
|
|
|
|
|
factory NanoTransactionInfo.fromJson(Map<String, dynamic> data) {
|
|
|
|
return NanoTransactionInfo(
|
|
|
|
id: data['id'] as String,
|
|
|
|
height: data['height'] as int,
|
2023-08-01 17:48:22 +00:00
|
|
|
amountRaw: BigInt.parse(data['amountRaw'] as String),
|
2023-07-27 17:02:10 +00:00
|
|
|
direction: parseTransactionDirectionFromInt(data['direction'] as int),
|
|
|
|
date: DateTime.fromMillisecondsSinceEpoch(data['date'] as int),
|
|
|
|
confirmed: data['confirmed'] as bool,
|
|
|
|
confirmations: data['confirmations'] as int,
|
|
|
|
tokenSymbol: data['tokenSymbol'] as String,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
|
|
'id': id,
|
|
|
|
'height': height,
|
2023-08-01 17:48:22 +00:00
|
|
|
'amountRaw': amountRaw.toString(),
|
2023-07-27 17:02:10 +00:00
|
|
|
'direction': direction.index,
|
|
|
|
'date': date.millisecondsSinceEpoch,
|
|
|
|
'confirmed': confirmed,
|
|
|
|
'confirmations': confirmations,
|
|
|
|
'tokenSymbol': tokenSymbol,
|
|
|
|
};
|
2023-07-25 15:21:49 +00:00
|
|
|
}
|