cast unlock_time type

This commit is contained in:
Serhii 2023-02-24 20:44:56 +02:00
parent 832ff62044
commit ec94c02148
4 changed files with 31 additions and 25 deletions

View file

@ -44,4 +44,5 @@ class TransactionInfoRow extends Struct {
String getHash() => hash.toDartString(); String getHash() => hash.toDartString();
String getPaymentId() => paymentId.toDartString(); String getPaymentId() => paymentId.toDartString();
String getAssetType() => assetType.toDartString(); String getAssetType() => assetType.toDartString();
int getUnlockTime() => unlockTime >> 32;
} }

View file

@ -8,11 +8,10 @@ import 'package:cw_haven/api/transaction_history.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
class HavenTransactionInfo extends TransactionInfo { class HavenTransactionInfo extends TransactionInfo {
HavenTransactionInfo(this.id, this.height, this.direction, this.date, HavenTransactionInfo(this.id, this.height, this.direction, this.date, this.isPending, this.amount,
this.isPending, this.amount, this.accountIndex, this.addressIndex, this.fee, this.unlockTime, this.accountIndex, this.addressIndex, this.fee, this.unlockTime, this.confirmations);
this.confirmations);
HavenTransactionInfo.fromRow(TransactionInfoRow row) HavenTransactionInfo.fromRow(TransactionInfoRow row)
: id = row.getHash(), : id = row.getHash(),
height = row.blockHeight, height = row.blockHeight,
direction = TransactionDirection.parseFromInt(row.direction), direction = TransactionDirection.parseFromInt(row.direction),
@ -21,9 +20,10 @@ class HavenTransactionInfo extends TransactionInfo {
amount = row.getAmount(), amount = row.getAmount(),
accountIndex = row.subaddrAccount, accountIndex = row.subaddrAccount,
addressIndex = row.subaddrIndex, addressIndex = row.subaddrIndex,
unlockTime = row.unlockTime, unlockTime = row.getUnlockTime(),
confirmations = row.confirmations, confirmations = row.confirmations,
key = null, //getTxKey(row.getHash()), key = null,
//getTxKey(row.getHash()),
fee = row.fee, fee = row.fee,
assetType = row.getAssetType(); assetType = row.getAssetType();
@ -44,8 +44,7 @@ class HavenTransactionInfo extends TransactionInfo {
String? key; String? key;
@override @override
String amountFormatted() => String amountFormatted() => '${formatAmount(moneroAmountToString(amount: amount))} $assetType';
'${formatAmount(moneroAmountToString(amount: amount))} $assetType';
@override @override
String fiatAmount() => _fiatAmount ?? ''; String fiatAmount() => _fiatAmount ?? '';
@ -54,8 +53,7 @@ class HavenTransactionInfo extends TransactionInfo {
void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount); void changeFiatAmount(String amount) => _fiatAmount = formatAmount(amount);
@override @override
String feeFormatted() => String feeFormatted() => '${formatAmount(moneroAmountToString(amount: fee))} $assetType';
'${formatAmount(moneroAmountToString(amount: fee))} $assetType';
@override @override
String? unlockTimeFormatted() { String? unlockTimeFormatted() {
@ -68,12 +66,15 @@ class HavenTransactionInfo extends TransactionInfo {
? '>1 year' ? '>1 year'
: '~${(unlockTime - height) * 2} minutes'; : '~${(unlockTime - height) * 2} minutes';
} }
try {
var locked = DateTime.fromMicrosecondsSinceEpoch(unlockTime).compareTo(DateTime.now()); var locked = DateTime.fromMicrosecondsSinceEpoch(unlockTime).compareTo(DateTime.now());
final DateFormat formatter = DateFormat('yyyy-MM-dd HH:mm:ss'); final DateFormat formatter = DateFormat('yyyy-MM-dd HH:mm:ss');
final String formattedUnlockTime = final String formattedUnlockTime =
formatter.format(DateTime.fromMicrosecondsSinceEpoch(unlockTime)); formatter.format(DateTime.fromMicrosecondsSinceEpoch(unlockTime));
return locked >= 0 ? '$formattedUnlockTime' : null;
return locked >= 0 ? '$formattedUnlockTime' : null; } catch (e) {
print(e);
return null;
}
} }
} }

View file

@ -41,4 +41,5 @@ class TransactionInfoRow extends Struct {
bool getIsPending() => isPending != 0; bool getIsPending() => isPending != 0;
String getHash() => hash.toDartString(); String getHash() => hash.toDartString();
String getPaymentId() => paymentId.toDartString(); String getPaymentId() => paymentId.toDartString();
int getUnlockTime() => unlockTime >> 32;
} }

View file

@ -21,7 +21,7 @@ class MoneroTransactionInfo extends TransactionInfo {
amount = row.getAmount(), amount = row.getAmount(),
accountIndex = row.subaddrAccount, accountIndex = row.subaddrAccount,
addressIndex = row.subaddrIndex, addressIndex = row.subaddrIndex,
unlockTime = row.unlockTime, unlockTime = row.getUnlockTime(),
confirmations = row.confirmations, confirmations = row.confirmations,
key = getTxKey(row.getHash()), key = getTxKey(row.getHash()),
fee = row.fee { fee = row.fee {
@ -72,12 +72,15 @@ class MoneroTransactionInfo extends TransactionInfo {
? '>1 year' ? '>1 year'
: '~${(unlockTime - height) * 2} minutes'; : '~${(unlockTime - height) * 2} minutes';
} }
try {
var locked = DateTime.fromMicrosecondsSinceEpoch(unlockTime).compareTo(DateTime.now()); var locked = DateTime.fromMillisecondsSinceEpoch(unlockTime).compareTo(DateTime.now());
final DateFormat formatter = DateFormat('yyyy-MM-dd HH:mm:ss'); final DateFormat formatter = DateFormat('yyyy-MM-dd HH:mm:ss');
final String formattedUnlockTime = final String formattedUnlockTime =
formatter.format(DateTime.fromMicrosecondsSinceEpoch(unlockTime)); formatter.format(DateTime.fromMillisecondsSinceEpoch(unlockTime));
return locked >= 0 ? '$formattedUnlockTime' : null;
return locked >= 0 ? '$formattedUnlockTime' : null; } catch (e) {
print(e);
return null;
}
} }
} }