Merge pull request #770 from cake-tech/CW-285-Show-number-of-confirmations-in-transactions-screen-for-Monero-and-Haven-if-10

add number of confirmations to transactions
This commit is contained in:
Omar Hatem 2023-02-14 16:02:39 +02:00 committed by GitHub
commit 13ee217502
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 9 deletions

View file

@ -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,
@ -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;

View file

@ -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,
@ -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>{
@ -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>{
@ -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;

View file

@ -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: <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,

View file

@ -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) {

View file

@ -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';
@ -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,
@ -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 = '';