fix unlock time display

This commit is contained in:
Serhii 2023-02-15 23:51:48 +02:00
parent f8ed0f8a80
commit efcfd625ec
7 changed files with 33 additions and 20 deletions

View file

@ -16,7 +16,6 @@ abstract class TransactionInfo extends Object with Keyable {
String? feeFormatted();
void changeFiatAmount(String amount);
String? unlockTimeFormatted();
bool get isLocked;
@override
dynamic get keyIndex => id;

View file

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

View file

@ -5,6 +5,7 @@ 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';
import 'package:intl/intl.dart';
class HavenTransactionInfo extends TransactionInfo {
HavenTransactionInfo(this.id, this.height, this.direction, this.date,
@ -20,7 +21,7 @@ class HavenTransactionInfo extends TransactionInfo {
amount = row.getAmount(),
accountIndex = row.subaddrAccount,
addressIndex = row.subaddrIndex,
unlockTime = row.getUnlockTime(),
unlockTime = row.unlockTime,
confirmations = row.confirmations,
key = null, //getTxKey(row.getHash()),
fee = row.fee,
@ -58,16 +59,21 @@ class HavenTransactionInfo extends TransactionInfo {
@override
String? unlockTimeFormatted() {
if (direction == TransactionDirection.outgoing || unlockTime == 0) {
if (direction == TransactionDirection.outgoing || unlockTime < (height + 10)) {
return null;
}
if (unlockTime > 500000) {
return '>1 year';
if (unlockTime < 500000000) {
return (unlockTime - height) * 2 > 500000
? '>1 year'
: '~${(unlockTime - height) * 2} minutes';
}
return '~ $unlockTime minutes';
}
@override
bool get isLocked => direction == TransactionDirection.incoming && unlockTime > 0;
var locked = DateTime.fromMillisecondsSinceEpoch(unlockTime).compareTo(DateTime.now());
final DateFormat formatter = DateFormat('yyyy-MM-dd HH:mm:ss');
final String formattedUnlockTime =
formatter.format(DateTime.fromMillisecondsSinceEpoch(unlockTime));
return locked >= 0 ? '$formattedUnlockTime' : null;
}
}

View file

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

View file

@ -5,6 +5,7 @@ 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';
import 'package:intl/intl.dart';
class MoneroTransactionInfo extends TransactionInfo {
MoneroTransactionInfo(this.id, this.height, this.direction, this.date,
@ -20,7 +21,7 @@ class MoneroTransactionInfo extends TransactionInfo {
amount = row.getAmount(),
accountIndex = row.subaddrAccount,
addressIndex = row.subaddrIndex,
unlockTime = row.getUnlockTime(),
unlockTime = row.unlockTime,
confirmations = row.confirmations,
key = getTxKey(row.getHash()),
fee = row.fee {
@ -62,16 +63,21 @@ class MoneroTransactionInfo extends TransactionInfo {
@override
String? unlockTimeFormatted() {
if (direction == TransactionDirection.outgoing || unlockTime == 0) {
if (direction == TransactionDirection.outgoing || unlockTime < (height + 10)) {
return null;
}
if (unlockTime > 500000) {
return '>1 year';
if (unlockTime < 500000000) {
return (unlockTime - height) * 2 > 500000
? '>1 year'
: '~${(unlockTime - height) * 2} minutes';
}
return '~ $unlockTime minutes';
}
@override
bool get isLocked => direction == TransactionDirection.incoming && unlockTime > 0;
var locked = DateTime.fromMillisecondsSinceEpoch(unlockTime).compareTo(DateTime.now());
final DateFormat formatter = DateFormat('yyyy-MM-dd HH:mm:ss');
final String formattedUnlockTime =
formatter.format(DateTime.fromMillisecondsSinceEpoch(unlockTime));
return locked >= 0 ? '$formattedUnlockTime' : null;
}
}

View file

@ -62,7 +62,8 @@ class TransactionsPage extends StatelessWidget {
dashboardViewModel.balanceViewModel.isFiatDisabled
? '' : item.formattedFiatAmount,
isPending: transaction.isPending,
title: item.formattedTitle + item.formattedStatus));
title: item.formattedTitle + item.formattedStatus
+ item.formattedLockedStatus));
}
if (item is TradeListItem) {

View file

@ -63,6 +63,9 @@ class TransactionListItem extends ActionListItem with Keyable {
return transaction.isPending ? S.current.pending : '';
}
String get formattedLockedStatus => transaction.unlockTimeFormatted() == null ? ''
: ' ' + S.current.locked;
String get formattedFiatAmount {
var amount = '';