mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-07 03:19:31 +00:00
fix unlock time display
This commit is contained in:
parent
f8ed0f8a80
commit
efcfd625ec
7 changed files with 33 additions and 20 deletions
|
@ -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;
|
||||
|
|
|
@ -44,5 +44,4 @@ class TransactionInfoRow extends Struct {
|
|||
String getHash() => hash.toDartString();
|
||||
String getPaymentId() => paymentId.toDartString();
|
||||
String getAssetType() => assetType.toDartString();
|
||||
int getUnlockTime() => unlockTime * 2;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,5 +41,4 @@ class TransactionInfoRow extends Struct {
|
|||
bool getIsPending() => isPending != 0;
|
||||
String getHash() => hash.toDartString();
|
||||
String getPaymentId() => paymentId.toDartString();
|
||||
int getUnlockTime() => unlockTime * 2;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 = '';
|
||||
|
||||
|
|
Loading…
Reference in a new issue