From 90cc8ced9c3b4160ccb9497942f7eac03efc4b49 Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 11 Jan 2024 11:31:28 -0600 Subject: [PATCH] add token support to tx v2 card --- .../tx_v2/transaction_v2_card.dart | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) 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 9782d3cab..f9561b740 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 @@ -6,6 +6,7 @@ import 'package:stackwallet/models/isar/models/blockchain_data/v2/transaction_v2 import 'package:stackwallet/models/isar/models/isar_models.dart'; import 'package:stackwallet/pages/wallet_view/sub_widgets/tx_icon.dart'; import 'package:stackwallet/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart'; +import 'package:stackwallet/providers/db/main_db_provider.dart'; import 'package:stackwallet/providers/global/locale_provider.dart'; import 'package:stackwallet/providers/global/prefs_provider.dart'; import 'package:stackwallet/providers/global/price_provider.dart'; @@ -41,21 +42,41 @@ class _TransactionCardStateV2 extends ConsumerState { late final String unit; late final Coin coin; late final TransactionType txType; + late final EthContract? tokenContract; + + bool get isTokenTx => tokenContract != null; String whatIsIt( Coin coin, int currentHeight, ) => - _transaction.statusLabel( - currentChainHeight: currentHeight, - minConfirms: - ref.read(pWallets).getWallet(walletId).cryptoCurrency.minConfirms, - ); + _transaction.isCancelled && coin == Coin.ethereum + ? "Failed" + : _transaction.statusLabel( + currentChainHeight: currentHeight, + minConfirms: ref + .read(pWallets) + .getWallet(walletId) + .cryptoCurrency + .minConfirms, + ); @override void initState() { _transaction = widget.transaction; walletId = _transaction.walletId; + coin = ref.read(pWalletCoin(walletId)); + + if (_transaction.subType == TransactionSubType.ethToken) { + tokenContract = ref + .read(mainDBProvider) + .getEthContractSync(_transaction.contractAddress!); + + unit = tokenContract!.symbol; + } else { + tokenContract == null; + unit = coin.ticker; + } if (Util.isDesktop) { if (_transaction.type == TransactionType.outgoing && @@ -69,9 +90,7 @@ class _TransactionCardStateV2 extends ConsumerState { } else { prefix = ""; } - coin = ref.read(pWalletCoin(walletId)); - unit = coin.ticker; super.initState(); } @@ -84,8 +103,9 @@ class _TransactionCardStateV2 extends ConsumerState { .watch(prefsChangeNotifierProvider.select((value) => value.currency)); final price = ref - .watch(priceAnd24hChangeNotifierProvider - .select((value) => value.getPrice(coin))) + .watch(priceAnd24hChangeNotifierProvider.select((value) => isTokenTx + ? value.getTokenPrice(_transaction.otherData!) + : value.getPrice(coin))) .item1; final currentHeight = ref.watch(pWalletChainHeight(walletId)); @@ -209,7 +229,7 @@ class _TransactionCardStateV2 extends ConsumerState { child: Builder( builder: (_) { return Text( - "$prefix${ref.watch(pAmountFormatter(coin)).format(amount)}", + "$prefix${ref.watch(pAmountFormatter(coin)).format(amount, ethContract: tokenContract)}", style: STextStyles.itemSubtitle12(context), ); },