From 3cf0d820858198125ce2464c4be19c227a54deb6 Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 5 Jan 2024 08:41:22 -0600 Subject: [PATCH] spark send to self hide spark change amount on tx card --- .../tx_v2/all_transactions_v2_view.dart | 13 +++++++++++++ .../tx_v2/transaction_v2_card.dart | 12 ++++++++++++ .../tx_v2/transaction_v2_details_view.dart | 12 ++++++++++++ lib/wallets/wallet/impl/firo_wallet.dart | 2 +- 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/pages/wallet_view/transaction_views/tx_v2/all_transactions_v2_view.dart b/lib/pages/wallet_view/transaction_views/tx_v2/all_transactions_v2_view.dart index 3953bfc7b..c9b6b202f 100644 --- a/lib/pages/wallet_view/transaction_views/tx_v2/all_transactions_v2_view.dart +++ b/lib/pages/wallet_view/transaction_views/tx_v2/all_transactions_v2_view.dart @@ -31,10 +31,12 @@ import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/amount/amount_formatter.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; +import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/format.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart'; +import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart'; import 'package:stackwallet/widgets/conditional_parent.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/desktop/desktop_app_bar.dart'; @@ -903,6 +905,17 @@ class _DesktopTransactionCardRowState case TransactionType.sentToSelf: if (_transaction.subType == TransactionSubType.sparkMint) { amount = _transaction.getAmountSparkSelfMinted(coin: coin); + } else if (_transaction.subType == TransactionSubType.sparkSpend) { + final changeAddress = + (ref.watch(pWallets).getWallet(walletId) as SparkInterface) + .sparkChangeAddress; + amount = Amount( + rawValue: _transaction.outputs + .where((e) => + e.walletOwns && !e.addresses.contains(changeAddress)) + .fold(BigInt.zero, (p, e) => p + e.value), + fractionDigits: coin.decimals, + ); } else { amount = _transaction.getAmountReceivedInThisWallet(coin: coin); } diff --git a/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_card.dart b/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_card.dart index 89dd74f8b..9782d3cab 100644 --- a/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_card.dart +++ b/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_card.dart @@ -19,6 +19,7 @@ import 'package:stackwallet/utilities/format.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart'; +import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart'; import 'package:stackwallet/widgets/desktop/desktop_dialog.dart'; class TransactionCardV2 extends ConsumerStatefulWidget { @@ -103,6 +104,17 @@ class _TransactionCardStateV2 extends ConsumerState { case TransactionType.sentToSelf: if (_transaction.subType == TransactionSubType.sparkMint) { amount = _transaction.getAmountSparkSelfMinted(coin: coin); + } else if (_transaction.subType == TransactionSubType.sparkSpend) { + final changeAddress = + (ref.watch(pWallets).getWallet(walletId) as SparkInterface) + .sparkChangeAddress; + amount = Amount( + rawValue: _transaction.outputs + .where((e) => + e.walletOwns && !e.addresses.contains(changeAddress)) + .fold(BigInt.zero, (p, e) => p + e.value), + fractionDigits: coin.decimals, + ); } else { amount = _transaction.getAmountReceivedInThisWallet(coin: coin); } diff --git a/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart b/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart index 205f331d0..eda2f2bc0 100644 --- a/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart +++ b/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart @@ -34,6 +34,7 @@ import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart'; +import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart'; import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/conditional_parent.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; @@ -138,6 +139,17 @@ class _TransactionV2DetailsViewState case TransactionType.sentToSelf: if (_transaction.subType == TransactionSubType.sparkMint) { amount = _transaction.getAmountSparkSelfMinted(coin: coin); + } else if (_transaction.subType == TransactionSubType.sparkSpend) { + final changeAddress = + (ref.read(pWallets).getWallet(walletId) as SparkInterface) + .sparkChangeAddress; + amount = Amount( + rawValue: _transaction.outputs + .where((e) => + e.walletOwns && !e.addresses.contains(changeAddress)) + .fold(BigInt.zero, (p, e) => p + e.value), + fractionDigits: coin.decimals, + ); } else { amount = _transaction.getAmountReceivedInThisWallet(coin: coin); } diff --git a/lib/wallets/wallet/impl/firo_wallet.dart b/lib/wallets/wallet/impl/firo_wallet.dart index e77d1d3e9..8a2447db7 100644 --- a/lib/wallets/wallet/impl/firo_wallet.dart +++ b/lib/wallets/wallet/impl/firo_wallet.dart @@ -426,7 +426,7 @@ class FiroWallet extends Bip39HDWallet TransactionType type; TransactionSubType subType = TransactionSubType.none; - // TODO integrate the following with the next bit + // TODO integrate the following with the next bit (maybe) if (isSparkSpend) { subType = TransactionSubType.sparkSpend; } else if (isSparkMint) {