cake_wallet/cw_monero/lib/monero_transaction_info.dart

73 lines
2.2 KiB
Dart
Raw Normal View History

import 'package:cw_core/transaction_info.dart';
2022-03-30 15:57:04 +00:00
import 'package:cw_core/monero_amount_format.dart';
import 'package:cw_monero/api/structs/transaction_info_row.dart';
import 'package:cw_core/parseBoolFromString.dart';
import 'package:cw_core/transaction_direction.dart';
import 'package:cw_core/format_amount.dart';
import 'package:cw_monero/api/transaction_history.dart';
class MoneroTransactionInfo extends TransactionInfo {
MoneroTransactionInfo(this.id, this.height, this.direction, this.date,
2023-02-06 11:27:36 +00:00
this.isPending, this.amount, this.accountIndex, this.addressIndex, this.fee, this.unlockTime);
MoneroTransactionInfo.fromRow(TransactionInfoRow row)
: id = row.getHash(),
height = row.blockHeight,
2023-02-06 19:42:24 +00:00
direction = TransactionDirection.parseFromInt(row.direction),
date = DateTime.fromMillisecondsSinceEpoch(row.getDatetime() * 1000),
isPending = row.isPending != 0,
amount = row.getAmount(),
accountIndex = row.subaddrAccount,
addressIndex = row.subaddrIndex,
2023-02-06 11:27:36 +00:00
unlockTime = row.unlockTime,
key = getTxKey(row.getHash()),
2022-01-31 12:08:38 +00:00
fee = row.fee {
2022-10-12 17:09:57 +00:00
additionalInfo = <String, dynamic>{
2022-01-31 12:08:38 +00:00
'key': key,
'accountIndex': accountIndex,
'addressIndex': addressIndex
};
}
final String id;
final int height;
final TransactionDirection direction;
final DateTime date;
final int accountIndex;
final bool isPending;
final int amount;
final int fee;
final int addressIndex;
2023-02-06 11:27:36 +00:00
final int unlockTime;
2022-10-12 17:09:57 +00:00
String? recipientAddress;
String? key;
String? _fiatAmount;
@override
String amountFormatted() =>
'${formatAmount(moneroAmountToString(amount: amount))} XMR';
@override
String fiatAmount() => _fiatAmount ?? '';
@override
void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount);
@override
String feeFormatted() =>
'${formatAmount(moneroAmountToString(amount: fee))} XMR';
2023-02-06 11:27:36 +00:00
@override
String? unlockTimeFormatted() {
final formattedTime = unlockTime * 2;
if (direction == TransactionDirection.outgoing || unlockTime == 0) {
return null;
}
if (formattedTime > 500000) {
return '>1 year';
}
return '~ $formattedTime minutes';
}
}