Skip to content

Commit

Permalink
Merge pull request cake-tech#770 from cake-tech/CW-285-Show-number-of…
Browse files Browse the repository at this point in the history
…-confirmations-in-transactions-screen-for-Monero-and-Haven-if-10

add number of confirmations to transactions
  • Loading branch information
OmarHatem28 committed Feb 14, 2023
2 parents 4a94bc0 + a3f3323 commit 13ee217
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
6 changes: 5 additions & 1 deletion cw_haven/lib/haven_transaction_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> map)
: id = (map['hash'] ?? '') as String,
Expand All @@ -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;

Expand All @@ -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();
Expand All @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion cw_monero/lib/monero_transaction_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object?> map)
: id = (map['hash'] ?? '') as String,
Expand All @@ -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 = <String, dynamic>{
Expand All @@ -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 = <String, dynamic>{
Expand All @@ -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;
Expand Down
9 changes: 3 additions & 6 deletions lib/src/screens/dashboard/widgets/transaction_raw.dart
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -49,11 +50,7 @@ class TransactionRow extends StatelessWidget {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
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,
Expand Down
3 changes: 2 additions & 1 deletion lib/src/screens/dashboard/widgets/transactions_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
27 changes: 27 additions & 0 deletions lib/view_model/dashboard/transaction_list_item.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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';
import 'package:cake_wallet/view_model/dashboard/action_list_item.dart';
Expand All @@ -11,6 +13,7 @@ import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
import 'package:cw_core/keyable.dart';
import 'package:cw_core/wallet_type.dart';


class TransactionListItem extends ActionListItem with Keyable {
TransactionListItem(
{required this.transaction,
Expand All @@ -35,6 +38,30 @@ 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 && transaction.confirmations < 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 formattedPendingStatus;
}
}
return transaction.isPending ? S.current.pending : '';
}

String get formattedFiatAmount {
var amount = '';
Expand Down

0 comments on commit 13ee217

Please sign in to comment.