add number of confirmations to transactions
Serhii committed
Feb 8, 2023 at 18:47 UTC
c10105872c2318df6a5738583cc57c31b2c389ed
5 files changed
+46
-9
cw_haven/lib/haven_transaction_info.dart
+5
-1
@@ -8,7 +8,8 @@ import 'package:cw_haven/api/transaction_history.dart';
8
9
class HavenTransactionInfo extends TransactionInfo {
10
HavenTransactionInfo(this.id, this.height, this.direction, this.date,
11
- this.isPending, this.amount, this.accountIndex, this.addressIndex, this.fee);
11
+ this.isPending, this.amount, this.accountIndex, this.addressIndex, this.fee,
12
+ this.confirmations);
13
14
HavenTransactionInfo.fromMap(Map<String, Object> map)
15
: id = (map['hash'] ?? '') as String,
@@ -22,6 +23,7 @@ class HavenTransactionInfo extends TransactionInfo {
23
amount = map['amount'] as int,
24
accountIndex = int.parse(map['accountIndex'] as String),
25
addressIndex = map['addressIndex'] as int,
26
+ confirmations = map['confirmations'] as int,
27
key = getTxKey((map['hash'] ?? '') as String),
28
fee = map['fee'] as int? ?? 0;
29
@@ -35,6 +37,7 @@ class HavenTransactionInfo extends TransactionInfo {
37
amount = row.getAmount(),
38
accountIndex = row.subaddrAccount,
39
addressIndex = row.subaddrIndex,
40
+ confirmations = row.confirmations,
41
key = null, //getTxKey(row.getHash()),
42
fee = row.fee,
43
assetType = row.getAssetType();
@@ -48,6 +51,7 @@ class HavenTransactionInfo extends TransactionInfo {
51
final int amount;
52
final int fee;
53
final int addressIndex;
54
+ final int confirmations;
55
late String recipientAddress;
56
late String assetType;
57
String? _fiatAmount;
cw_monero/lib/monero_transaction_info.dart
+5
-1
@@ -8,7 +8,8 @@ import 'package:cw_monero/api/transaction_history.dart';
8
9
class MoneroTransactionInfo extends TransactionInfo {
10
MoneroTransactionInfo(this.id, this.height, this.direction, this.date,
11
- this.isPending, this.amount, this.accountIndex, this.addressIndex, this.fee);
11
+ this.isPending, this.amount, this.accountIndex, this.addressIndex, this.fee,
12
+ this.confirmations);
13
14
MoneroTransactionInfo.fromMap(Map<String, Object?> map)
15
: id = (map['hash'] ?? '') as String,
@@ -22,6 +23,7 @@ class MoneroTransactionInfo extends TransactionInfo {
23
amount = map['amount'] as int,
24
accountIndex = int.parse(map['accountIndex'] as String),
25
addressIndex = map['addressIndex'] as int,
26
+ confirmations = map['confirmations'] as int,
27
key = getTxKey((map['hash'] ?? '') as String),
28
fee = map['fee'] as int ?? 0 {
29
additionalInfo = <String, dynamic>{
@@ -41,6 +43,7 @@ class MoneroTransactionInfo extends TransactionInfo {
43
amount = row.getAmount(),
44
accountIndex = row.subaddrAccount,
45
addressIndex = row.subaddrIndex,
46
+ confirmations = row.confirmations,
47
key = getTxKey(row.getHash()),
48
fee = row.fee {
49
additionalInfo = <String, dynamic>{
@@ -59,6 +62,7 @@ class MoneroTransactionInfo extends TransactionInfo {
62
final int amount;
63
final int fee;
64
final int addressIndex;
65
+ final int confirmations;
66
String? recipientAddress;
67
String? key;
68
String? _fiatAmount;
lib/src/screens/dashboard/widgets/transaction_raw.dart
+3
-6
@@ -1,6 +1,5 @@
1
import 'package:flutter/material.dart';
2
import 'package:cw_core/transaction_direction.dart';
3
-import 'package:cake_wallet/generated/i18n.dart';
3
4
class TransactionRow extends StatelessWidget {
5
TransactionRow(
@@ -9,6 +8,7 @@ class TransactionRow extends StatelessWidget {
8
required this.formattedAmount,
9
required this.formattedFiatAmount,
10
required this.isPending,
11
+ required this.title,
12
required this.onTap});
13
14
final VoidCallback onTap;
@@ -17,6 +17,7 @@ class TransactionRow extends StatelessWidget {
17
final String formattedAmount;
18
final String formattedFiatAmount;
19
final bool isPending;
20
+ final String title;
21
22
@override
23
Widget build(BuildContext context) {
@@ -49,11 +50,7 @@ class TransactionRow extends StatelessWidget {
50
Row(
51
mainAxisAlignment: MainAxisAlignment.spaceBetween,
52
children: <Widget>[
52
- Text(
53
- (direction == TransactionDirection.incoming
54
- ? S.of(context).received
55
- : S.of(context).sent) +
56
- (isPending ? S.of(context).pending : ''),
53
+ Text(title,
54
style: TextStyle(
55
fontSize: 16,
56
fontWeight: FontWeight.w500,
lib/src/screens/dashboard/widgets/transactions_page.dart
+2
-1
@@ -60,7 +60,8 @@ class TransactionsPage extends StatelessWidget {
60
formattedFiatAmount:
61
dashboardViewModel.balanceViewModel.isFiatDisabled
62
? '' : item.formattedFiatAmount,
63
- isPending: transaction.isPending));
63
+ isPending: transaction.isPending,
64
+ title: item.formattedTitle + item.formattedStatus));
65
}
66
67
if (item is TradeListItem) {
lib/view_model/dashboard/transaction_list_item.dart
+31
@@ -1,5 +1,6 @@
1
import 'package:cake_wallet/entities/balance_display_mode.dart';
2
import 'package:cake_wallet/entities/fiat_currency.dart';
3
+import 'package:cw_core/transaction_direction.dart';
4
import 'package:cw_core/transaction_info.dart';
5
import 'package:cake_wallet/store/settings_store.dart';
6
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';
12
import 'package:cw_core/keyable.dart';
13
import 'package:cw_core/wallet_type.dart';
14
15
+import '../../generated/i18n.dart';
16
+
17
class TransactionListItem extends ActionListItem with Keyable {
18
TransactionListItem(
19
{required this.transaction,
@@ -35,6 +38,34 @@ class TransactionListItem extends ActionListItem with Keyable {
38
? '---'
39
: transaction.amountFormatted();
40
}
41
+ String get formattedTitle {
42
+ if (transaction.direction == TransactionDirection.incoming) {
43
+ return S.current.received;
44
+ }
45
+
46
+ return S.current.sent;
47
+ }
48
+
49
+ String get formattedPendingStatus {
50
+ if (transaction.confirmations == 0) {
51
+ return S.current.pending;
52
+ }
53
+ if (transaction.confirmations > 0 && transaction.height < 10) {
54
+ return ' (${transaction.confirmations}/10)';
55
+ }
56
+ return '';
57
+ }
58
+
59
+ String get formattedStatus {
60
+ if (transaction.direction == TransactionDirection.incoming) {
61
+ if (balanceViewModel.wallet.type == WalletType.monero ||
62
+ balanceViewModel.wallet.type == WalletType.haven) {
63
+ return transaction.isPending ? formattedPendingStatus : '';
64
+ }
65
+ return transaction.isPending ? S.current.pending : '';
66
+ }
67
+ return transaction.isPending ? S.current.pending : '';
68
+ }
69
70
String get formattedFiatAmount {
71
var amount = '';