cake_wallet/cw_haven/lib/haven_transaction_info.dart

83 lines
2.8 KiB
Dart
Raw Normal View History

2022-03-30 15:57:04 +00:00
import 'package:cw_core/transaction_info.dart';
import 'package:cw_core/monero_amount_format.dart';
import 'package:cw_haven/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_haven/api/transaction_history.dart';
2023-02-15 21:51:48 +00:00
import 'package:intl/intl.dart';
2023-02-28 11:26:21 +00:00
import 'package:cw_haven/api/wallet.dart' as haven_wallet;
2022-03-30 15:57:04 +00:00
class HavenTransactionInfo extends TransactionInfo {
2023-02-24 18:44:56 +00:00
HavenTransactionInfo(this.id, this.height, this.direction, this.date, this.isPending, this.amount,
this.accountIndex, this.addressIndex, this.fee, this.unlockTime, this.confirmations);
2022-03-30 15:57:04 +00:00
2023-02-24 18:44:56 +00:00
HavenTransactionInfo.fromRow(TransactionInfoRow row)
2022-03-30 15:57:04 +00:00
: id = row.getHash(),
height = row.blockHeight,
2023-02-06 19:42:24 +00:00
direction = TransactionDirection.parseFromInt(row.direction),
2022-03-30 15:57:04 +00:00
date = DateTime.fromMillisecondsSinceEpoch(row.getDatetime() * 1000),
isPending = row.isPending != 0,
amount = row.getAmount(),
accountIndex = row.subaddrAccount,
addressIndex = row.subaddrIndex,
2023-02-24 18:44:56 +00:00
unlockTime = row.getUnlockTime(),
confirmations = row.confirmations,
2023-02-24 18:44:56 +00:00
key = null,
//getTxKey(row.getHash()),
2022-03-30 15:57:04 +00:00
fee = row.fee,
assetType = row.getAssetType();
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;
final int confirmations;
2022-10-12 17:09:57 +00:00
late String recipientAddress;
late String assetType;
final int unlockTime;
2022-10-12 17:09:57 +00:00
String? _fiatAmount;
String? key;
2022-03-30 15:57:04 +00:00
@override
2023-02-24 18:44:56 +00:00
String amountFormatted() => '${formatAmount(moneroAmountToString(amount: amount))} $assetType';
2022-03-30 15:57:04 +00:00
@override
String fiatAmount() => _fiatAmount ?? '';
@override
void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount);
@override
2023-02-24 18:44:56 +00:00
String feeFormatted() => '${formatAmount(moneroAmountToString(amount: fee))} $assetType';
2023-02-06 11:27:36 +00:00
@override
String? unlockTimeFormatted() {
2023-02-28 11:26:21 +00:00
final currentHeight = haven_wallet.getCurrentHeight();
if (direction == TransactionDirection.outgoing || unlockTime < (currentHeight + 10)) {
return null;
}
2023-02-15 21:51:48 +00:00
if (unlockTime < 500000000) {
2023-02-28 11:26:21 +00:00
return (unlockTime - currentHeight) * 2 > 500000
2023-02-15 21:51:48 +00:00
? '>1 year'
2023-02-28 11:26:21 +00:00
: '~${(unlockTime - currentHeight) * 2} minutes';
}
2023-02-24 18:44:56 +00:00
try {
2023-02-27 13:49:53 +00:00
var locked = DateTime.fromMillisecondsSinceEpoch(unlockTime).compareTo(DateTime.now());
2023-02-24 18:44:56 +00:00
final DateFormat formatter = DateFormat('yyyy-MM-dd HH:mm:ss');
final String formattedUnlockTime =
2023-02-27 13:49:53 +00:00
formatter.format(DateTime.fromMillisecondsSinceEpoch(unlockTime));
return locked > 0 ? '$formattedUnlockTime' : null;
2023-02-24 18:44:56 +00:00
} catch (e) {
print(e);
return null;
}
2023-02-15 21:51:48 +00:00
}
2022-03-30 15:57:04 +00:00
}