From c10105872c2318df6a5738583cc57c31b2c389ed Mon Sep 17 00:00:00 2001 From: Serhii Date: Wed, 8 Feb 2023 18:47:12 +0200 Subject: [PATCH 1/4] add number of confirmations to transactions --- cw_haven/lib/haven_transaction_info.dart | 6 +++- cw_monero/lib/monero_transaction_info.dart | 6 +++- .../dashboard/widgets/transaction_raw.dart | 9 ++---- .../dashboard/widgets/transactions_page.dart | 3 +- .../dashboard/transaction_list_item.dart | 31 +++++++++++++++++++ 5 files changed, 46 insertions(+), 9 deletions(-) diff --git a/cw_haven/lib/haven_transaction_info.dart b/cw_haven/lib/haven_transaction_info.dart index 277370467..6ffb60e6b 100644 --- a/cw_haven/lib/haven_transaction_info.dart +++ b/cw_haven/lib/haven_transaction_info.dart @@ -8,7 +8,8 @@ import 'package:cw_haven/api/transaction_history.dart'; class HavenTransactionInfo extends TransactionInfo { HavenTransactionInfo(this.id, this.height, this.direction, this.date, - this.isPending, this.amount, this.accountIndex, this.addressIndex, this.fee); + this.isPending, this.amount, this.accountIndex, this.addressIndex, this.fee, + this.confirmations); HavenTransactionInfo.fromMap(Map map) : id = (map['hash'] ?? '') as String, @@ -22,6 +23,7 @@ class HavenTransactionInfo extends TransactionInfo { amount = map['amount'] as int, accountIndex = int.parse(map['accountIndex'] as String), addressIndex = map['addressIndex'] as int, + confirmations = map['confirmations'] as int, key = getTxKey((map['hash'] ?? '') as String), fee = map['fee'] as int? ?? 0; @@ -35,6 +37,7 @@ class HavenTransactionInfo extends TransactionInfo { amount = row.getAmount(), accountIndex = row.subaddrAccount, addressIndex = row.subaddrIndex, + confirmations = row.confirmations, key = null, //getTxKey(row.getHash()), fee = row.fee, assetType = row.getAssetType(); @@ -48,6 +51,7 @@ class HavenTransactionInfo extends TransactionInfo { final int amount; final int fee; final int addressIndex; + final int confirmations; late String recipientAddress; late String assetType; String? _fiatAmount; diff --git a/cw_monero/lib/monero_transaction_info.dart b/cw_monero/lib/monero_transaction_info.dart index 2dfdaf408..90cc3c279 100644 --- a/cw_monero/lib/monero_transaction_info.dart +++ b/cw_monero/lib/monero_transaction_info.dart @@ -8,7 +8,8 @@ import 'package:cw_monero/api/transaction_history.dart'; class MoneroTransactionInfo extends TransactionInfo { MoneroTransactionInfo(this.id, this.height, this.direction, this.date, - this.isPending, this.amount, this.accountIndex, this.addressIndex, this.fee); + this.isPending, this.amount, this.accountIndex, this.addressIndex, this.fee, + this.confirmations); MoneroTransactionInfo.fromMap(Map map) : id = (map['hash'] ?? '') as String, @@ -22,6 +23,7 @@ class MoneroTransactionInfo extends TransactionInfo { amount = map['amount'] as int, accountIndex = int.parse(map['accountIndex'] as String), addressIndex = map['addressIndex'] as int, + confirmations = map['confirmations'] as int, key = getTxKey((map['hash'] ?? '') as String), fee = map['fee'] as int ?? 0 { additionalInfo = { @@ -41,6 +43,7 @@ class MoneroTransactionInfo extends TransactionInfo { amount = row.getAmount(), accountIndex = row.subaddrAccount, addressIndex = row.subaddrIndex, + confirmations = row.confirmations, key = getTxKey(row.getHash()), fee = row.fee { additionalInfo = { @@ -59,6 +62,7 @@ class MoneroTransactionInfo extends TransactionInfo { final int amount; final int fee; final int addressIndex; + final int confirmations; String? recipientAddress; String? key; String? _fiatAmount; diff --git a/lib/src/screens/dashboard/widgets/transaction_raw.dart b/lib/src/screens/dashboard/widgets/transaction_raw.dart index 7ba6cbf0e..b7d8cef93 100644 --- a/lib/src/screens/dashboard/widgets/transaction_raw.dart +++ b/lib/src/screens/dashboard/widgets/transaction_raw.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:cw_core/transaction_direction.dart'; -import 'package:cake_wallet/generated/i18n.dart'; class TransactionRow extends StatelessWidget { TransactionRow( @@ -9,6 +8,7 @@ class TransactionRow extends StatelessWidget { required this.formattedAmount, required this.formattedFiatAmount, required this.isPending, + required this.title, required this.onTap}); final VoidCallback onTap; @@ -17,6 +17,7 @@ class TransactionRow extends StatelessWidget { final String formattedAmount; final String formattedFiatAmount; final bool isPending; + final String title; @override Widget build(BuildContext context) { @@ -49,11 +50,7 @@ class TransactionRow extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( - (direction == TransactionDirection.incoming - ? S.of(context).received - : S.of(context).sent) + - (isPending ? S.of(context).pending : ''), + Text(title, style: TextStyle( fontSize: 16, fontWeight: FontWeight.w500, diff --git a/lib/src/screens/dashboard/widgets/transactions_page.dart b/lib/src/screens/dashboard/widgets/transactions_page.dart index 64f02c73c..cda23b8c9 100644 --- a/lib/src/screens/dashboard/widgets/transactions_page.dart +++ b/lib/src/screens/dashboard/widgets/transactions_page.dart @@ -60,7 +60,8 @@ class TransactionsPage extends StatelessWidget { formattedFiatAmount: dashboardViewModel.balanceViewModel.isFiatDisabled ? '' : item.formattedFiatAmount, - isPending: transaction.isPending)); + isPending: transaction.isPending, + title: item.formattedTitle + item.formattedStatus)); } 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 35f30a937..19e93218d 100644 --- a/lib/view_model/dashboard/transaction_list_item.dart +++ b/lib/view_model/dashboard/transaction_list_item.dart @@ -1,5 +1,6 @@ import 'package:cake_wallet/entities/balance_display_mode.dart'; import 'package:cake_wallet/entities/fiat_currency.dart'; +import 'package:cw_core/transaction_direction.dart'; import 'package:cw_core/transaction_info.dart'; import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/view_model/dashboard/action_list_item.dart'; @@ -11,6 +12,8 @@ import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart'; import 'package:cw_core/keyable.dart'; import 'package:cw_core/wallet_type.dart'; +import '../../generated/i18n.dart'; + class TransactionListItem extends ActionListItem with Keyable { TransactionListItem( {required this.transaction, @@ -35,6 +38,34 @@ class TransactionListItem extends ActionListItem with Keyable { ? '---' : transaction.amountFormatted(); } + String get formattedTitle { + if (transaction.direction == TransactionDirection.incoming) { + return S.current.received; + } + + return S.current.sent; + } + + String get formattedPendingStatus { + if (transaction.confirmations == 0) { + return S.current.pending; + } + if (transaction.confirmations > 0 && transaction.height < 10) { + return ' (${transaction.confirmations}/10)'; + } + return ''; + } + + String get formattedStatus { + if (transaction.direction == TransactionDirection.incoming) { + if (balanceViewModel.wallet.type == WalletType.monero || + balanceViewModel.wallet.type == WalletType.haven) { + return transaction.isPending ? formattedPendingStatus : ''; + } + return transaction.isPending ? S.current.pending : ''; + } + return transaction.isPending ? S.current.pending : ''; + } String get formattedFiatAmount { var amount = ''; From 25228eb633485acac3179f66463c87c899009f9b Mon Sep 17 00:00:00 2001 From: Serhii Date: Fri, 10 Feb 2023 00:01:58 +0200 Subject: [PATCH 2/4] fix confirmations --- lib/view_model/dashboard/transaction_list_item.dart | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/view_model/dashboard/transaction_list_item.dart b/lib/view_model/dashboard/transaction_list_item.dart index 19e93218d..52cf31105 100644 --- a/lib/view_model/dashboard/transaction_list_item.dart +++ b/lib/view_model/dashboard/transaction_list_item.dart @@ -1,5 +1,6 @@ import 'package:cake_wallet/entities/balance_display_mode.dart'; import 'package:cake_wallet/entities/fiat_currency.dart'; +import 'package:cake_wallet/generated/i18n.dart'; import 'package:cw_core/transaction_direction.dart'; import 'package:cw_core/transaction_info.dart'; import 'package:cake_wallet/store/settings_store.dart'; @@ -12,7 +13,6 @@ import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart'; import 'package:cw_core/keyable.dart'; import 'package:cw_core/wallet_type.dart'; -import '../../generated/i18n.dart'; class TransactionListItem extends ActionListItem with Keyable { TransactionListItem( @@ -47,10 +47,10 @@ class TransactionListItem extends ActionListItem with Keyable { } String get formattedPendingStatus { - if (transaction.confirmations == 0) { + if (transaction.confirmations == 0 || transaction.isPending) { return S.current.pending; } - if (transaction.confirmations > 0 && transaction.height < 10) { + if (transaction.confirmations > 0 && transaction.confirmations < 10) { return ' (${transaction.confirmations}/10)'; } return ''; @@ -60,9 +60,8 @@ class TransactionListItem extends ActionListItem with Keyable { if (transaction.direction == TransactionDirection.incoming) { if (balanceViewModel.wallet.type == WalletType.monero || balanceViewModel.wallet.type == WalletType.haven) { - return transaction.isPending ? formattedPendingStatus : ''; + return formattedPendingStatus; } - return transaction.isPending ? S.current.pending : ''; } return transaction.isPending ? S.current.pending : ''; } From 8bae7d2179b81927a637b1be3d940c9cf75c32ab Mon Sep 17 00:00:00 2001 From: Serhii Date: Sun, 12 Feb 2023 16:22:05 +0200 Subject: [PATCH 3/4] minor fix --- lib/view_model/dashboard/transaction_list_item.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/view_model/dashboard/transaction_list_item.dart b/lib/view_model/dashboard/transaction_list_item.dart index 52cf31105..b10af9279 100644 --- a/lib/view_model/dashboard/transaction_list_item.dart +++ b/lib/view_model/dashboard/transaction_list_item.dart @@ -48,7 +48,7 @@ class TransactionListItem extends ActionListItem with Keyable { String get formattedPendingStatus { if (transaction.confirmations == 0 || transaction.isPending) { - return S.current.pending; + return S.current.pending + ' (${transaction.confirmations}/10)'; } if (transaction.confirmations > 0 && transaction.confirmations < 10) { return ' (${transaction.confirmations}/10)'; From a3f332342f6fcc2ab266e08bbfd08f3273997e9e Mon Sep 17 00:00:00 2001 From: Serhii Date: Mon, 13 Feb 2023 18:46:53 +0200 Subject: [PATCH 4/4] minor fix --- lib/view_model/dashboard/transaction_list_item.dart | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/view_model/dashboard/transaction_list_item.dart b/lib/view_model/dashboard/transaction_list_item.dart index b10af9279..0f16bdfe8 100644 --- a/lib/view_model/dashboard/transaction_list_item.dart +++ b/lib/view_model/dashboard/transaction_list_item.dart @@ -47,10 +47,7 @@ class TransactionListItem extends ActionListItem with Keyable { } String get formattedPendingStatus { - if (transaction.confirmations == 0 || transaction.isPending) { - return S.current.pending + ' (${transaction.confirmations}/10)'; - } - if (transaction.confirmations > 0 && transaction.confirmations < 10) { + if (transaction.confirmations >= 0 && transaction.confirmations < 10) { return ' (${transaction.confirmations}/10)'; } return '';