From efcfd625eccab597e653e5603f8c752d4f77eaf2 Mon Sep 17 00:00:00 2001 From: Serhii Date: Wed, 15 Feb 2023 23:51:48 +0200 Subject: [PATCH] fix unlock time display --- cw_core/lib/transaction_info.dart | 1 - .../lib/api/structs/transaction_info_row.dart | 1 - cw_haven/lib/haven_transaction_info.dart | 22 ++++++++++++------- .../lib/api/structs/transaction_info_row.dart | 1 - cw_monero/lib/monero_transaction_info.dart | 22 ++++++++++++------- .../dashboard/widgets/transactions_page.dart | 3 ++- .../dashboard/transaction_list_item.dart | 3 +++ 7 files changed, 33 insertions(+), 20 deletions(-) diff --git a/cw_core/lib/transaction_info.dart b/cw_core/lib/transaction_info.dart index ef3be8404..f1900ee49 100644 --- a/cw_core/lib/transaction_info.dart +++ b/cw_core/lib/transaction_info.dart @@ -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; diff --git a/cw_haven/lib/api/structs/transaction_info_row.dart b/cw_haven/lib/api/structs/transaction_info_row.dart index 913632d8e..a5c3835b7 100644 --- a/cw_haven/lib/api/structs/transaction_info_row.dart +++ b/cw_haven/lib/api/structs/transaction_info_row.dart @@ -44,5 +44,4 @@ class TransactionInfoRow extends Struct { String getHash() => hash.toDartString(); String getPaymentId() => paymentId.toDartString(); String getAssetType() => assetType.toDartString(); - int getUnlockTime() => unlockTime * 2; } diff --git a/cw_haven/lib/haven_transaction_info.dart b/cw_haven/lib/haven_transaction_info.dart index 57cd33c9b..ebac6f624 100644 --- a/cw_haven/lib/haven_transaction_info.dart +++ b/cw_haven/lib/haven_transaction_info.dart @@ -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; + } } diff --git a/cw_monero/lib/api/structs/transaction_info_row.dart b/cw_monero/lib/api/structs/transaction_info_row.dart index 809fb3d9d..cd7f4dacb 100644 --- a/cw_monero/lib/api/structs/transaction_info_row.dart +++ b/cw_monero/lib/api/structs/transaction_info_row.dart @@ -41,5 +41,4 @@ class TransactionInfoRow extends Struct { bool getIsPending() => isPending != 0; String getHash() => hash.toDartString(); String getPaymentId() => paymentId.toDartString(); - int getUnlockTime() => unlockTime * 2; } diff --git a/cw_monero/lib/monero_transaction_info.dart b/cw_monero/lib/monero_transaction_info.dart index 69b9ec630..1c72d79ab 100644 --- a/cw_monero/lib/monero_transaction_info.dart +++ b/cw_monero/lib/monero_transaction_info.dart @@ -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; + } } diff --git a/lib/src/screens/dashboard/widgets/transactions_page.dart b/lib/src/screens/dashboard/widgets/transactions_page.dart index 8b604082e..28bd037c0 100644 --- a/lib/src/screens/dashboard/widgets/transactions_page.dart +++ b/lib/src/screens/dashboard/widgets/transactions_page.dart @@ -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) { diff --git a/lib/view_model/dashboard/transaction_list_item.dart b/lib/view_model/dashboard/transaction_list_item.dart index 0f16bdfe8..b4e647691 100644 --- a/lib/view_model/dashboard/transaction_list_item.dart +++ b/lib/view_model/dashboard/transaction_list_item.dart @@ -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 = '';