From c10105872c2318df6a5738583cc57c31b2c389ed Mon Sep 17 00:00:00 2001 From: Serhii Date: Wed, 8 Feb 2023 18:47:12 +0200 Subject: [PATCH] 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 = '';