From fecad7893be025b9768a5fa58517c03562377083 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Fri, 27 Jan 2023 17:40:30 -0600 Subject: [PATCH 01/12] did this TODO --- lib/pages/wallet_view/wallet_view.dart | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/pages/wallet_view/wallet_view.dart b/lib/pages/wallet_view/wallet_view.dart index bc63f0868..fd5473b11 100644 --- a/lib/pages/wallet_view/wallet_view.dart +++ b/lib/pages/wallet_view/wallet_view.dart @@ -774,9 +774,6 @@ class _WalletViewState extends ConsumerState { ); }, onBuyPressed: () { - // TODO set default coin to currently open wallet here by passing it as an argument - // final coin = ref.read(managerProvider).coin; - unawaited(Navigator.of(context).pushNamed( BuyInWalletView.routeName, arguments: coin, From 85d69c0cb29330e46c559bd2f070e5e93a0e4203 Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 30 Jan 2023 08:28:14 -0600 Subject: [PATCH 02/12] check all outputs for potential notification tx --- lib/services/mixins/electrum_x_parsing.dart | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/services/mixins/electrum_x_parsing.dart b/lib/services/mixins/electrum_x_parsing.dart index 23be3d80d..c0b572b20 100644 --- a/lib/services/mixins/electrum_x_parsing.dart +++ b/lib/services/mixins/electrum_x_parsing.dart @@ -189,14 +189,16 @@ mixin ElectrumXParsing { TransactionSubType txSubType = TransactionSubType.none; if (this is PaynymWalletInterface && outs.length > 1 && ins.isNotEmpty) { - List? scriptChunks = outs[1].scriptPubKeyAsm?.split(" "); - if (scriptChunks?.length == 2 && scriptChunks?[0] == "OP_RETURN") { - final blindedPaymentCode = scriptChunks![1]; - final bytes = blindedPaymentCode.fromHex; + for (int i = 0; i < outs.length; i++) { + List? scriptChunks = outs[i].scriptPubKeyAsm?.split(" "); + if (scriptChunks?.length == 2 && scriptChunks?[0] == "OP_RETURN") { + final blindedPaymentCode = scriptChunks![1]; + final bytes = blindedPaymentCode.fromHex; - // https://en.bitcoin.it/wiki/BIP_0047#Sending - if (bytes.length == 80 && bytes.first == 1) { - txSubType = TransactionSubType.bip47Notification; + // https://en.bitcoin.it/wiki/BIP_0047#Sending + if (bytes.length == 80 && bytes.first == 1) { + txSubType = TransactionSubType.bip47Notification; + } } } } From 17cbc390e4f90ce7d97ca4692b6d42d8003a7130 Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 30 Jan 2023 08:28:54 -0600 Subject: [PATCH 03/12] pass in correct values --- .../coins/bitcoin/bitcoin_wallet.dart | 2 ++ .../mixins/paynym_wallet_interface.dart | 20 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/services/coins/bitcoin/bitcoin_wallet.dart b/lib/services/coins/bitcoin/bitcoin_wallet.dart index 83188746e..1f32a945a 100644 --- a/lib/services/coins/bitcoin/bitcoin_wallet.dart +++ b/lib/services/coins/bitcoin/bitcoin_wallet.dart @@ -1314,6 +1314,8 @@ class BitcoinWallet extends CoinServiceAPI checkChangeAddressForTransactions: _checkChangeAddressForTransactions, addDerivation: addDerivation, addDerivations: addDerivations, + dustLimitP2PKH: DUST_LIMIT_P2PKH, + minConfirms: MINIMUM_CONFIRMATIONS, ); } diff --git a/lib/services/mixins/paynym_wallet_interface.dart b/lib/services/mixins/paynym_wallet_interface.dart index 3a9642cf0..2292f3ec5 100644 --- a/lib/services/mixins/paynym_wallet_interface.dart +++ b/lib/services/mixins/paynym_wallet_interface.dart @@ -15,7 +15,6 @@ import 'package:stackwallet/electrumx_rpc/electrumx.dart'; import 'package:stackwallet/exceptions/wallet/insufficient_balance_exception.dart'; import 'package:stackwallet/exceptions/wallet/paynym_send_exception.dart'; import 'package:stackwallet/models/isar/models/isar_models.dart'; -import 'package:stackwallet/services/coins/dogecoin/dogecoin_wallet.dart'; import 'package:stackwallet/utilities/bip32_utils.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; @@ -35,6 +34,8 @@ mixin PaynymWalletInterface { late final MainDB _db; late final ElectrumX _electrumXClient; late final SecureStorageInterface _secureStorage; + late final int _dustLimitP2PKH; + late final int _minConfirms; // passed in wallet functions late final Future> Function() _getMnemonic; @@ -79,6 +80,8 @@ mixin PaynymWalletInterface { required MainDB db, required ElectrumX electrumXClient, required SecureStorageInterface secureStorage, + required int dustLimitP2PKH, + required int minConfirms, required Future> Function() getMnemonic, required Future Function() getChainHeight, required Future Function() getCurrentChangeAddress, @@ -125,6 +128,8 @@ mixin PaynymWalletInterface { _db = db; _electrumXClient = electrumXClient; _secureStorage = secureStorage; + _dustLimitP2PKH = dustLimitP2PKH; + _minConfirms = minConfirms; _getMnemonic = getMnemonic; _getChainHeight = getChainHeight; _getCurrentChangeAddress = getCurrentChangeAddress; @@ -353,7 +358,7 @@ mixin PaynymWalletInterface { int additionalOutputs = 0, List? utxos, }) async { - const amountToSend = DUST_LIMIT; + final amountToSend = _dustLimitP2PKH; final List availableOutputs = utxos ?? await _db.getUTXOs(_walletId).findAll(); final List spendableOutputs = []; @@ -362,8 +367,8 @@ mixin PaynymWalletInterface { // Build list of spendable outputs and totaling their satoshi amount for (var i = 0; i < availableOutputs.length; i++) { if (availableOutputs[i].isBlocked == false && - availableOutputs[i].isConfirmed( - await _getChainHeight(), MINIMUM_CONFIRMATIONS) == + availableOutputs[i] + .isConfirmed(await _getChainHeight(), _minConfirms) == true) { spendableOutputs.add(availableOutputs[i]); spendableSatoshiValue += availableOutputs[i].value; @@ -440,13 +445,13 @@ mixin PaynymWalletInterface { feeForWithChange = vSizeForWithChange * 1000; } - if (satoshisBeingUsed - amountToSend > feeForNoChange + DUST_LIMIT) { + if (satoshisBeingUsed - amountToSend > feeForNoChange + _dustLimitP2PKH) { // try to add change output due to "left over" amount being greater than // the estimated fee + the dust limit int changeAmount = satoshisBeingUsed - amountToSend - feeForWithChange; // check estimates are correct and build notification tx - if (changeAmount >= DUST_LIMIT && + if (changeAmount >= _dustLimitP2PKH && satoshisBeingUsed - amountToSend - changeAmount == feeForWithChange) { final txn = await _createNotificationTx( targetPaymentCodeString: targetPaymentCodeString, @@ -572,7 +577,8 @@ mixin PaynymWalletInterface { ); // todo: modify address once segwit support is in our bip47 - txb.addOutput(targetPaymentCode.notificationAddressP2PKH(), DUST_LIMIT); + txb.addOutput( + targetPaymentCode.notificationAddressP2PKH(), _dustLimitP2PKH); txb.addOutput(opReturnScript, 0); // TODO: add possible change output and mark output as dangerous From 6e54ddec865843fb0674bf11e84d8051add5dacd Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 30 Jan 2023 09:13:30 -0600 Subject: [PATCH 04/12] wallet bottom nav bar fixes --- .../sub_widgets/wallet_navigation_bar.dart | 117 +++++++++--------- 1 file changed, 58 insertions(+), 59 deletions(-) diff --git a/lib/pages/wallet_view/sub_widgets/wallet_navigation_bar.dart b/lib/pages/wallet_view/sub_widgets/wallet_navigation_bar.dart index a50c7bb3c..4e6be9e97 100644 --- a/lib/pages/wallet_view/sub_widgets/wallet_navigation_bar.dart +++ b/lib/pages/wallet_view/sub_widgets/wallet_navigation_bar.dart @@ -360,62 +360,6 @@ class _WalletNavigationBarState extends ConsumerState { ), ), ), - if (ref.watch(walletsChangeNotifierProvider.select((value) => - value.getManager(widget.walletId).hasPaynymSupport))) - RawMaterialButton( - constraints: const BoxConstraints( - minWidth: 66, - ), - onPressed: () { - if (scale == 0) { - setState(() { - scale = 1; - }); - } else if (scale == 1) { - setState(() { - scale = 0; - }); - } - }, - splashColor: - Theme.of(context).extension()!.highlight, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular( - widget.height / 2.0, - ), - ), - child: Container( - color: Colors.transparent, - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 2.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - const Spacer(), - const SizedBox( - height: 2, - ), - SvgPicture.asset( - Assets.svg.bars, - width: 20, - height: 20, - ), - const SizedBox( - height: 6, - ), - Text( - "More", - style: STextStyles.buttonSmall(context), - ), - const Spacer(), - ], - ), - ), - ), - ), - const SizedBox( - width: 12, - ), if (widget.coin.hasBuySupport) RawMaterialButton( constraints: const BoxConstraints( @@ -455,10 +399,65 @@ class _WalletNavigationBarState extends ConsumerState { ), ), ), - if (widget.coin.hasBuySupport) - const SizedBox( - width: 12, + if (ref.watch(walletsChangeNotifierProvider.select((value) => + value.getManager(widget.walletId).hasPaynymSupport))) + RawMaterialButton( + constraints: const BoxConstraints( + minWidth: 66, + ), + onPressed: () { + if (scale == 0) { + setState(() { + scale = 1; + }); + } else if (scale == 1) { + setState(() { + scale = 0; + }); + } + }, + splashColor: + Theme.of(context).extension()!.highlight, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular( + widget.height / 2.0, + ), + ), + child: Container( + color: Colors.transparent, + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 2.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const Spacer(), + const SizedBox( + height: 2, + ), + SvgPicture.asset( + Assets.svg.bars, + width: 20, + height: 20, + color: Theme.of(context) + .extension()! + .bottomNavIconIcon, + ), + const SizedBox( + height: 6, + ), + Text( + "More", + style: STextStyles.buttonSmall(context), + ), + const Spacer(), + ], + ), + ), + ), ), + const SizedBox( + width: 12, + ), ], ), ), From 1e5f624c8b9cbcc1dd3930653aade78a3b1703f2 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Mon, 30 Jan 2023 09:30:57 -0600 Subject: [PATCH 05/12] remove unused functions --- lib/pages/buy_view/buy_form.dart | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/pages/buy_view/buy_form.dart b/lib/pages/buy_view/buy_form.dart index 029bc9aa4..0aa8170f8 100644 --- a/lib/pages/buy_view/buy_form.dart +++ b/lib/pages/buy_view/buy_form.dart @@ -108,10 +108,6 @@ class _BuyFormState extends ConsumerState { static Decimal maxCrypto = Decimal.parse((10000.00000000).toString()); static String boundedCryptoTicker = ''; - void fiatFieldOnChanged(String value) async {} - - void cryptoFieldOnChanged(String value) async {} - void selectCrypto() async { if (ref.read(simplexProvider).supportedCryptos.isEmpty) { bool shouldPop = false; From a41f80ac557d78a19432cae09c1c4adfc48ea65c Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 30 Jan 2023 11:06:28 -0600 Subject: [PATCH 06/12] add height change notify --- lib/services/coins/bitcoin/bitcoin_wallet.dart | 8 ++++++++ lib/services/coins/bitcoincash/bitcoincash_wallet.dart | 8 ++++++++ lib/services/coins/dogecoin/dogecoin_wallet.dart | 8 ++++++++ lib/services/coins/epiccash/epiccash_wallet.dart | 8 ++++++++ lib/services/coins/firo/firo_wallet.dart | 8 ++++++++ lib/services/coins/litecoin/litecoin_wallet.dart | 8 ++++++++ lib/services/coins/namecoin/namecoin_wallet.dart | 8 ++++++++ lib/services/coins/particl/particl_wallet.dart | 8 ++++++++ 8 files changed, 64 insertions(+) diff --git a/lib/services/coins/bitcoin/bitcoin_wallet.dart b/lib/services/coins/bitcoin/bitcoin_wallet.dart index 1f32a945a..32c24686b 100644 --- a/lib/services/coins/bitcoin/bitcoin_wallet.dart +++ b/lib/services/coins/bitcoin/bitcoin_wallet.dart @@ -251,6 +251,14 @@ class BitcoinWallet extends CoinServiceAPI final result = await _electrumXClient.getBlockHeadTip(); final height = result["height"] as int; await updateCachedChainHeight(height); + if (height > storedChainHeight) { + GlobalEventBus.instance.fire( + UpdatedInBackgroundEvent( + "Updated current chain height in $walletId $walletName!", + walletId, + ), + ); + } return height; } catch (e, s) { Logging.instance.log("Exception caught in chainHeight: $e\n$s", diff --git a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart index 969eb1815..a84c8f09e 100644 --- a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart +++ b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart @@ -217,6 +217,14 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB { final result = await _electrumXClient.getBlockHeadTip(); final height = result["height"] as int; await updateCachedChainHeight(height); + if (height > storedChainHeight) { + GlobalEventBus.instance.fire( + UpdatedInBackgroundEvent( + "Updated current chain height in $walletId $walletName!", + walletId, + ), + ); + } return height; } catch (e, s) { Logging.instance.log("Exception caught in chainHeight: $e\n$s", diff --git a/lib/services/coins/dogecoin/dogecoin_wallet.dart b/lib/services/coins/dogecoin/dogecoin_wallet.dart index 90d2764ac..7dc3bc6f9 100644 --- a/lib/services/coins/dogecoin/dogecoin_wallet.dart +++ b/lib/services/coins/dogecoin/dogecoin_wallet.dart @@ -226,6 +226,14 @@ class DogecoinWallet extends CoinServiceAPI final result = await _electrumXClient.getBlockHeadTip(); final height = result["height"] as int; await updateCachedChainHeight(height); + if (height > storedChainHeight) { + GlobalEventBus.instance.fire( + UpdatedInBackgroundEvent( + "Updated current chain height in $walletId $walletName!", + walletId, + ), + ); + } return height; } catch (e, s) { Logging.instance.log("Exception caught in chainHeight: $e\n$s", diff --git a/lib/services/coins/epiccash/epiccash_wallet.dart b/lib/services/coins/epiccash/epiccash_wallet.dart index 86ed2979b..d6505889b 100644 --- a/lib/services/coins/epiccash/epiccash_wallet.dart +++ b/lib/services/coins/epiccash/epiccash_wallet.dart @@ -1416,6 +1416,14 @@ class EpicCashWallet extends CoinServiceAPI }); await updateCachedChainHeight(latestHeight!); + if (latestHeight! > storedChainHeight) { + GlobalEventBus.instance.fire( + UpdatedInBackgroundEvent( + "Updated current chain height in $walletId $walletName!", + walletId, + ), + ); + } return latestHeight!; } catch (e, s) { Logging.instance.log("Exception caught in chainHeight: $e\n$s", diff --git a/lib/services/coins/firo/firo_wallet.dart b/lib/services/coins/firo/firo_wallet.dart index ec63db186..7758d4e0c 100644 --- a/lib/services/coins/firo/firo_wallet.dart +++ b/lib/services/coins/firo/firo_wallet.dart @@ -4897,6 +4897,14 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive { final result = await _electrumXClient.getBlockHeadTip(); final height = result["height"] as int; await updateCachedChainHeight(height); + if (height > storedChainHeight) { + GlobalEventBus.instance.fire( + UpdatedInBackgroundEvent( + "Updated current chain height in $walletId $walletName!", + walletId, + ), + ); + } return height; } catch (e, s) { Logging.instance.log("Exception caught in chainHeight: $e\n$s", diff --git a/lib/services/coins/litecoin/litecoin_wallet.dart b/lib/services/coins/litecoin/litecoin_wallet.dart index be93d478f..779a9ba54 100644 --- a/lib/services/coins/litecoin/litecoin_wallet.dart +++ b/lib/services/coins/litecoin/litecoin_wallet.dart @@ -241,6 +241,14 @@ class LitecoinWallet extends CoinServiceAPI final result = await _electrumXClient.getBlockHeadTip(); final height = result["height"] as int; await updateCachedChainHeight(height); + if (height > storedChainHeight) { + GlobalEventBus.instance.fire( + UpdatedInBackgroundEvent( + "Updated current chain height in $walletId $walletName!", + walletId, + ), + ); + } return height; } catch (e, s) { Logging.instance.log("Exception caught in chainHeight: $e\n$s", diff --git a/lib/services/coins/namecoin/namecoin_wallet.dart b/lib/services/coins/namecoin/namecoin_wallet.dart index 2cf0e8ef5..f074ca0ef 100644 --- a/lib/services/coins/namecoin/namecoin_wallet.dart +++ b/lib/services/coins/namecoin/namecoin_wallet.dart @@ -236,6 +236,14 @@ class NamecoinWallet extends CoinServiceAPI final result = await _electrumXClient.getBlockHeadTip(); final height = result["height"] as int; await updateCachedChainHeight(height); + if (height > storedChainHeight) { + GlobalEventBus.instance.fire( + UpdatedInBackgroundEvent( + "Updated current chain height in $walletId $walletName!", + walletId, + ), + ); + } return height; } catch (e, s) { Logging.instance.log("Exception caught in chainHeight: $e\n$s", diff --git a/lib/services/coins/particl/particl_wallet.dart b/lib/services/coins/particl/particl_wallet.dart index 4f822d87a..e4e419892 100644 --- a/lib/services/coins/particl/particl_wallet.dart +++ b/lib/services/coins/particl/particl_wallet.dart @@ -231,6 +231,14 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB { final result = await _electrumXClient.getBlockHeadTip(); final height = result["height"] as int; await updateCachedChainHeight(height); + if (height > storedChainHeight) { + GlobalEventBus.instance.fire( + UpdatedInBackgroundEvent( + "Updated current chain height in $walletId $walletName!", + walletId, + ), + ); + } return height; } catch (e, s) { Logging.instance.log("Exception caught in chainHeight: $e\n$s", From 225aec176306dacf91770b5abd2751c8930463d0 Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 30 Jan 2023 12:03:23 -0600 Subject: [PATCH 07/12] update ui transaction state fix --- .../sub_widgets/transactions_list.dart | 29 +++++++++---------- .../all_transactions_view.dart | 8 +++-- .../transaction_details_view.dart | 4 +-- .../dogecoin/current_height_provider.dart | 6 ---- lib/widgets/transaction_card.dart | 4 +-- 5 files changed, 23 insertions(+), 28 deletions(-) delete mode 100644 lib/providers/blockchain/dogecoin/current_height_provider.dart diff --git a/lib/pages/wallet_view/sub_widgets/transactions_list.dart b/lib/pages/wallet_view/sub_widgets/transactions_list.dart index 71f56ccad..360b3028b 100644 --- a/lib/pages/wallet_view/sub_widgets/transactions_list.dart +++ b/lib/pages/wallet_view/sub_widgets/transactions_list.dart @@ -5,7 +5,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:stackwallet/models/isar/models/isar_models.dart'; import 'package:stackwallet/pages/exchange_view/trade_details_view.dart'; import 'package:stackwallet/pages/wallet_view/sub_widgets/no_transactions_found.dart'; -import 'package:stackwallet/providers/blockchain/dogecoin/current_height_provider.dart'; import 'package:stackwallet/providers/global/trades_service_provider.dart'; import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/route_generator.dart'; @@ -85,7 +84,13 @@ class _TransactionsListState extends ConsumerState { children: [ TransactionCard( // this may mess with combined firo transactions - key: Key(tx.txid + tx.type.name + tx.address.value.toString()), // + key: Key(tx.txid + + tx.type.name + + tx.address.value.toString() + + ref + .watch(widget.managerProvider + .select((value) => value.currentHeight)) + .toString()), // transaction: tx, walletId: widget.walletId, ), @@ -180,7 +185,13 @@ class _TransactionsListState extends ConsumerState { ), child: TransactionCard( // this may mess with combined firo transactions - key: Key(tx.txid + tx.type.name + tx.address.value.toString()), // + key: Key(tx.txid + + tx.type.name + + tx.address.value.toString() + + ref + .watch(widget.managerProvider + .select((value) => value.currentHeight)) + .toString()), // transaction: tx, walletId: widget.walletId, ), @@ -188,13 +199,6 @@ class _TransactionsListState extends ConsumerState { } } - void updateHeightProvider(Manager manager) { - WidgetsBinding.instance.addPostFrameCallback((timeStamp) { - ref.read(currentHeightProvider(manager.coin).state).state = - manager.currentHeight; - }); - } - @override void initState() { managerProvider = widget.managerProvider; @@ -203,14 +207,9 @@ class _TransactionsListState extends ConsumerState { @override Widget build(BuildContext context) { - // final managerProvider = ref - // .watch(walletsChangeNotifierProvider) - // .getManagerProvider(widget.walletId); - final manager = ref.watch(walletsChangeNotifierProvider .select((value) => value.getManager(widget.walletId))); - updateHeightProvider(manager); return FutureBuilder( future: manager.transactions, builder: (fbContext, AsyncSnapshot> snapshot) { diff --git a/lib/pages/wallet_view/transaction_views/all_transactions_view.dart b/lib/pages/wallet_view/transaction_views/all_transactions_view.dart index 6ebb5bd1c..c9ba6181b 100644 --- a/lib/pages/wallet_view/transaction_views/all_transactions_view.dart +++ b/lib/pages/wallet_view/transaction_views/all_transactions_view.dart @@ -10,7 +10,6 @@ import 'package:stackwallet/notifications/show_flush_bar.dart'; import 'package:stackwallet/pages/wallet_view/sub_widgets/tx_icon.dart'; import 'package:stackwallet/pages/wallet_view/transaction_views/transaction_details_view.dart'; import 'package:stackwallet/pages/wallet_view/transaction_views/transaction_search_filter_view.dart'; -import 'package:stackwallet/providers/blockchain/dogecoin/current_height_provider.dart'; import 'package:stackwallet/providers/global/address_book_service_provider.dart'; import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/providers/ui/transaction_filter_provider.dart'; @@ -131,7 +130,9 @@ class _TransactionDetailsViewState extends ConsumerState { // check if address book name contains contains |= contacts .where((e) => - e.addresses.where((a) => a.address == tx.address).isNotEmpty && + e.addresses + .where((a) => a.address == tx.address.value?.value) + .isNotEmpty && e.name.toLowerCase().contains(keyword)) .isNotEmpty; @@ -853,7 +854,8 @@ class _DesktopTransactionCardRowState prefix = ""; } - final currentHeight = ref.watch(currentHeightProvider(coin).state).state; + final currentHeight = ref.watch(walletsChangeNotifierProvider + .select((value) => value.getManager(walletId).currentHeight)); return Material( color: Theme.of(context).extension()!.popupBG, diff --git a/lib/pages/wallet_view/transaction_views/transaction_details_view.dart b/lib/pages/wallet_view/transaction_views/transaction_details_view.dart index f2755f547..af82a250d 100644 --- a/lib/pages/wallet_view/transaction_views/transaction_details_view.dart +++ b/lib/pages/wallet_view/transaction_views/transaction_details_view.dart @@ -11,7 +11,6 @@ import 'package:stackwallet/pages/wallet_view/sub_widgets/tx_icon.dart'; import 'package:stackwallet/pages/wallet_view/transaction_views/dialogs/cancelling_transaction_progress_dialog.dart'; import 'package:stackwallet/pages/wallet_view/transaction_views/edit_note_view.dart'; import 'package:stackwallet/pages/wallet_view/wallet_view.dart'; -import 'package:stackwallet/providers/blockchain/dogecoin/current_height_provider.dart'; import 'package:stackwallet/providers/global/address_book_service_provider.dart'; import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/services/coins/epiccash/epiccash_wallet.dart'; @@ -298,7 +297,8 @@ class _TransactionDetailsViewState @override Widget build(BuildContext context) { - final currentHeight = ref.watch(currentHeightProvider(coin).state).state; + final currentHeight = ref.watch(walletsChangeNotifierProvider + .select((value) => value.getManager(walletId).currentHeight)); return ConditionalParent( condition: !isDesktop, diff --git a/lib/providers/blockchain/dogecoin/current_height_provider.dart b/lib/providers/blockchain/dogecoin/current_height_provider.dart deleted file mode 100644 index 22b6711db..000000000 --- a/lib/providers/blockchain/dogecoin/current_height_provider.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'package:dart_numerics/dart_numerics.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:stackwallet/utilities/enums/coin_enum.dart'; - -final currentHeightProvider = - StateProvider.family((ref, coin) => int64MaxValue); diff --git a/lib/widgets/transaction_card.dart b/lib/widgets/transaction_card.dart index 031234142..1b19a2380 100644 --- a/lib/widgets/transaction_card.dart +++ b/lib/widgets/transaction_card.dart @@ -6,7 +6,6 @@ import 'package:stackwallet/models/isar/models/isar_models.dart'; import 'package:stackwallet/notifications/show_flush_bar.dart'; import 'package:stackwallet/pages/wallet_view/sub_widgets/tx_icon.dart'; import 'package:stackwallet/pages/wallet_view/transaction_views/transaction_details_view.dart'; -import 'package:stackwallet/providers/blockchain/dogecoin/current_height_provider.dart'; import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; @@ -121,7 +120,8 @@ class _TransactionCardState extends ConsumerState { } } - final currentHeight = ref.watch(currentHeightProvider(coin).state).state; + final currentHeight = ref.watch(walletsChangeNotifierProvider + .select((value) => value.getManager(walletId).currentHeight)); return Material( color: Theme.of(context).extension()!.popupBG, From 47fb446b2e6460f97c9eebc73c5f3193d279cdd5 Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 30 Jan 2023 13:08:44 -0600 Subject: [PATCH 08/12] changed amount validation and (hopefully) fixed preview quote button --- lib/pages/buy_view/buy_form.dart | 245 ++++++++++++++++++------------- 1 file changed, 143 insertions(+), 102 deletions(-) diff --git a/lib/pages/buy_view/buy_form.dart b/lib/pages/buy_view/buy_form.dart index 0aa8170f8..3ec462ca7 100644 --- a/lib/pages/buy_view/buy_form.dart +++ b/lib/pages/buy_view/buy_form.dart @@ -108,6 +108,37 @@ class _BuyFormState extends ConsumerState { static Decimal maxCrypto = Decimal.parse((10000.00000000).toString()); static String boundedCryptoTicker = ''; + String _amountOutOfRangeErrorString = ""; + void validateAmount() { + if (_buyAmountController.text.isEmpty) { + setState(() { + _amountOutOfRangeErrorString = ""; + }); + return; + } + + final value = Decimal.tryParse(_buyAmountController.text); + if (value == null) { + setState(() { + _amountOutOfRangeErrorString = "Invalid amount"; + }); + } else if (value > maxFiat) { + setState(() { + _amountOutOfRangeErrorString = + "Maximum amount: ${maxFiat.toStringAsFixed(2)}"; + }); + } else if (value < minFiat) { + setState(() { + _amountOutOfRangeErrorString = + "Minimum amount: ${minFiat.toStringAsFixed(2)}"; + }); + } else { + setState(() { + _amountOutOfRangeErrorString = ""; + }); + } + } + void selectCrypto() async { if (ref.read(simplexProvider).supportedCryptos.isEmpty) { bool shouldPop = false; @@ -355,11 +386,11 @@ class _BuyFormState extends ConsumerState { } } - String? _fetchIconUrlFromTicker(String? ticker) { - if (ticker == null) return null; - - return null; - } + // String? _fetchIconUrlFromTicker(String? ticker) { + // if (ticker == null) return null; + // + // return null; + // } bool isStackCoin(String? ticker) { if (ticker == null) return false; @@ -373,13 +404,15 @@ class _BuyFormState extends ConsumerState { } Widget? getIconForTicker(String ticker) { - String? iconAsset = /*isStackCoin(ticker) + String iconAsset = /*isStackCoin(ticker) ?*/ Assets.svg.iconFor(coin: coinFromTickerCaseInsensitive(ticker)); // : Assets.svg.buyIconFor(ticker); - return (iconAsset != null) - ? SvgPicture.asset(iconAsset, height: 20, width: 20) - : null; + // return (iconAsset != null) + // ? SvgPicture.asset(iconAsset, height: 20, width: 20) + // : null; + + return SvgPicture.asset(iconAsset, height: 20, width: 20); } Future previewQuote(SimplexQuote quote) async { @@ -500,7 +533,7 @@ class _BuyFormState extends ConsumerState { String errorMessage = "${quoteResponse.exception?.errorMessage}"; if (errorMessage.contains('must be between')) { errorMessage = errorMessage.substring( - (errorMessage.indexOf('getQuote exception: ') ?? 19) + 20, + errorMessage.indexOf('getQuote exception: ') + 20, errorMessage.indexOf(", value: null")); _BuyFormState.boundedCryptoTicker = errorMessage.substring( errorMessage.indexOf('The ') + 4, @@ -848,7 +881,11 @@ class _BuyFormState extends ConsumerState { .textFieldDefaultBG, child: Padding( padding: const EdgeInsets.only( - left: 12.0, top: 12.0, right: 12.0, bottom: 12.0), + left: 12.0, + top: 12.0, + right: 12.0, + bottom: 12.0, + ), child: Row( children: [ Container( @@ -874,7 +911,7 @@ class _BuyFormState extends ConsumerState { width: 8, ), Text( - "${selectedFiat?.ticker ?? 'ERR'}", + selectedFiat?.ticker ?? 'ERR', style: STextStyles.largeMedium14(context), ), const SizedBox( @@ -882,7 +919,7 @@ class _BuyFormState extends ConsumerState { ), Expanded( child: Text( - "${selectedFiat?.name ?? 'Error'}", + selectedFiat?.name ?? 'Error', style: STextStyles.largeMedium14(context), ), ), @@ -934,10 +971,11 @@ class _BuyFormState extends ConsumerState { color: Theme.of(context).extension()!.textDark, ), key: const Key("buyAmountInputFieldTextFieldKey"), - controller: _buyAmountController - ..text = _BuyFormState.buyWithFiat - ? _BuyFormState.minFiat.toStringAsFixed(2) ?? '50.00' - : _BuyFormState.minCrypto.toStringAsFixed(8), + controller: _buyAmountController, + // note: setting the text value here will set it every time this widget rebuilds + // ..text = _BuyFormState.buyWithFiat + // ? _BuyFormState.minFiat.toStringAsFixed(2) ?? '50.00' + // : _BuyFormState.minCrypto.toStringAsFixed(8), focusNode: _buyAmountFocusNode, keyboardType: Util.isDesktop ? null @@ -946,7 +984,10 @@ class _BuyFormState extends ConsumerState { decimal: true, ), textAlign: TextAlign.left, - inputFormatters: [NumericalRangeFormatter()], + // inputFormatters: [NumericalRangeFormatter()], + onChanged: (_) { + validateAmount(); + }, decoration: InputDecoration( contentPadding: const EdgeInsets.only( // top: 22, @@ -981,8 +1022,8 @@ class _BuyFormState extends ConsumerState { ), child: Text( format.simpleCurrencySymbol( - selectedFiat?.ticker ?? - "ERR".toUpperCase()), + selectedFiat?.ticker.toUpperCase() ?? + "ERR"), textAlign: TextAlign.center, style: STextStyles.smallMed12(context).copyWith( color: Theme.of(context) @@ -1019,18 +1060,20 @@ class _BuyFormState extends ConsumerState { key: const Key( "buyViewClearAmountFieldButtonKey"), onTap: () { - if (_BuyFormState.buyWithFiat) { - _buyAmountController.text = _BuyFormState - .minFiat - .toStringAsFixed(2); - } else { - if (selectedCrypto?.ticker == - _BuyFormState.boundedCryptoTicker) { - _buyAmountController.text = _BuyFormState - .minCrypto - .toStringAsFixed(8); - } - } + // if (_BuyFormState.buyWithFiat) { + // _buyAmountController.text = _BuyFormState + // .minFiat + // .toStringAsFixed(2); + // } else { + // if (selectedCrypto?.ticker == + // _BuyFormState.boundedCryptoTicker) { + // _buyAmountController.text = _BuyFormState + // .minCrypto + // .toStringAsFixed(8); + // } + // } + _buyAmountController.text = ""; + validateAmount(); }, child: const XIcon(), ) @@ -1047,7 +1090,7 @@ class _BuyFormState extends ConsumerState { _buyAmountController.text = amountString.toString(); - setState(() {}); + validateAmount(); } }, child: _buyAmountController.text.isEmpty @@ -1060,6 +1103,14 @@ class _BuyFormState extends ConsumerState { ), ), ), + SizedBox( + height: isDesktop ? 10 : 4, + ), + if (_amountOutOfRangeErrorString.isNotEmpty) + Text( + _amountOutOfRangeErrorString, + style: STextStyles.errorSmall(context), + ), SizedBox( height: isDesktop ? 20 : 12, ), @@ -1167,7 +1218,7 @@ class _BuyFormState extends ConsumerState { _receiveAddressController.text = ""; _address = ""; setState(() { - _addressToggleFlag = true; + _addressToggleFlag = false; }); }, child: const XIcon(), @@ -1338,27 +1389,15 @@ class _BuyFormState extends ConsumerState { SizedBox( height: isDesktop ? 20 : 12, ), - MouseRegion( - cursor: SystemMouseCursors.click, - child: GestureDetector( - onTap: () { - if (_receiveAddressController.text.isNotEmpty && - _buyAmountController.text.isNotEmpty) { - previewQuote(quote); - } - }, - child: PrimaryButton( - buttonHeight: isDesktop ? ButtonHeight.l : null, - enabled: _receiveAddressController.text.isNotEmpty && - _buyAmountController.text.isNotEmpty, - onPressed: () { - if (_receiveAddressController.text.isNotEmpty && - _buyAmountController.text.isNotEmpty) { - previewQuote(quote); - } - }, - label: "Preview quote", - )), + PrimaryButton( + buttonHeight: isDesktop ? ButtonHeight.l : null, + enabled: _addressToggleFlag && + _amountOutOfRangeErrorString.isEmpty && + _buyAmountController.text.isNotEmpty, + onPressed: () { + previewQuote(quote); + }, + label: "Preview quote", ), ], ), @@ -1367,51 +1406,53 @@ class _BuyFormState extends ConsumerState { } } -// See https://stackoverflow.com/a/68072967 -class NumericalRangeFormatter extends TextInputFormatter { - NumericalRangeFormatter(); +// might need this again in the future - @override - TextEditingValue formatEditUpdate( - TextEditingValue oldValue, - TextEditingValue newValue, - ) { - TextSelection newSelection = newValue.selection; - String newVal = _BuyFormState.buyWithFiat - ? Decimal.parse(newValue.text).toStringAsFixed(2) - : Decimal.parse(newValue.text).toStringAsFixed(8); - if (newValue.text == '') { - return newValue; - } else { - if (_BuyFormState.buyWithFiat) { - if (Decimal.parse(newValue.text) < _BuyFormState.minFiat) { - newVal = _BuyFormState.minFiat.toStringAsFixed(2); - // _BuyFormState._buyAmountController.selection = - // TextSelection.collapsed( - // offset: _BuyFormState.buyWithFiat - // ? _BuyFormState._buyAmountController.text.length - 2 - // : _BuyFormState._buyAmountController.text.length - 8); - } else if (Decimal.parse(newValue.text) > _BuyFormState.maxFiat) { - newVal = _BuyFormState.maxFiat.toStringAsFixed(2); - } - } else if (!_BuyFormState.buyWithFiat && - _BuyFormState.selectedCrypto?.ticker == - _BuyFormState.boundedCryptoTicker) { - if (Decimal.parse(newValue.text) < _BuyFormState.minCrypto) { - newVal = _BuyFormState.minCrypto.toStringAsFixed(8); - } else if (Decimal.parse(newValue.text) > _BuyFormState.maxCrypto) { - newVal = _BuyFormState.maxCrypto.toStringAsFixed(8); - } - } - } - - final regexString = _BuyFormState.buyWithFiat - ? r'^([0-9]*[,.]?[0-9]{0,2}|[,.][0-9]{0,2})$' - : r'^([0-9]*[,.]?[0-9]{0,8}|[,.][0-9]{0,8})$'; - - // return RegExp(r'^([0-9]*[,.]?[0-9]{0,8}|[,.][0-9]{0,8})$') - return RegExp(regexString).hasMatch(newVal) - ? TextEditingValue(text: newVal, selection: newSelection) - : oldValue; - } -} +// // See https://stackoverflow.com/a/68072967 +// class NumericalRangeFormatter extends TextInputFormatter { +// NumericalRangeFormatter(); +// +// @override +// TextEditingValue formatEditUpdate( +// TextEditingValue oldValue, +// TextEditingValue newValue, +// ) { +// TextSelection newSelection = newValue.selection; +// String newVal = _BuyFormState.buyWithFiat +// ? Decimal.parse(newValue.text).toStringAsFixed(2) +// : Decimal.parse(newValue.text).toStringAsFixed(8); +// if (newValue.text == '') { +// return newValue; +// } else { +// if (_BuyFormState.buyWithFiat) { +// if (Decimal.parse(newValue.text) < _BuyFormState.minFiat) { +// newVal = _BuyFormState.minFiat.toStringAsFixed(2); +// // _BuyFormState._buyAmountController.selection = +// // TextSelection.collapsed( +// // offset: _BuyFormState.buyWithFiat +// // ? _BuyFormState._buyAmountController.text.length - 2 +// // : _BuyFormState._buyAmountController.text.length - 8); +// } else if (Decimal.parse(newValue.text) > _BuyFormState.maxFiat) { +// newVal = _BuyFormState.maxFiat.toStringAsFixed(2); +// } +// } else if (!_BuyFormState.buyWithFiat && +// _BuyFormState.selectedCrypto?.ticker == +// _BuyFormState.boundedCryptoTicker) { +// if (Decimal.parse(newValue.text) < _BuyFormState.minCrypto) { +// newVal = _BuyFormState.minCrypto.toStringAsFixed(8); +// } else if (Decimal.parse(newValue.text) > _BuyFormState.maxCrypto) { +// newVal = _BuyFormState.maxCrypto.toStringAsFixed(8); +// } +// } +// } +// +// final regexString = _BuyFormState.buyWithFiat +// ? r'^([0-9]*[,.]?[0-9]{0,2}|[,.][0-9]{0,2})$' +// : r'^([0-9]*[,.]?[0-9]{0,8}|[,.][0-9]{0,8})$'; +// +// // return RegExp(r'^([0-9]*[,.]?[0-9]{0,8}|[,.][0-9]{0,8})$') +// return RegExp(regexString).hasMatch(newVal) +// ? TextEditingValue(text: newVal, selection: newSelection) +// : oldValue; +// } +// } From bed518d061a49b1f80b27aaa3e5574705d11cf42 Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 30 Jan 2023 13:40:40 -0600 Subject: [PATCH 09/12] ensure fiat amount validation updates on fiat type changed --- lib/pages/buy_view/buy_form.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/pages/buy_view/buy_form.dart b/lib/pages/buy_view/buy_form.dart index 3ec462ca7..a882c1475 100644 --- a/lib/pages/buy_view/buy_form.dart +++ b/lib/pages/buy_view/buy_form.dart @@ -122,12 +122,12 @@ class _BuyFormState extends ConsumerState { setState(() { _amountOutOfRangeErrorString = "Invalid amount"; }); - } else if (value > maxFiat) { + } else if (value > maxFiat && buyWithFiat) { setState(() { _amountOutOfRangeErrorString = "Maximum amount: ${maxFiat.toStringAsFixed(2)}"; }); - } else if (value < minFiat) { + } else if (value < minFiat && buyWithFiat) { setState(() { _amountOutOfRangeErrorString = "Minimum amount: ${minFiat.toStringAsFixed(2)}"; @@ -280,6 +280,7 @@ class _BuyFormState extends ConsumerState { minFiat = fiat.minAmount != minFiat ? fiat.minAmount : minFiat; maxFiat = fiat.maxAmount != maxFiat ? fiat.maxAmount : maxFiat; }); + validateAmount(); }, ); } From 13721df803bfbc1a75d02f45602fdfe8ad2e8c83 Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 30 Jan 2023 13:42:19 -0600 Subject: [PATCH 10/12] ensure fiat amount validation updates on use fiat amount selected --- lib/pages/buy_view/buy_form.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pages/buy_view/buy_form.dart b/lib/pages/buy_view/buy_form.dart index a882c1475..a46238188 100644 --- a/lib/pages/buy_view/buy_form.dart +++ b/lib/pages/buy_view/buy_form.dart @@ -958,6 +958,7 @@ class _BuyFormState extends ConsumerState { setState(() { buyWithFiat = !buyWithFiat; }); + validateAmount(); }, ) ], From 4f58483e82223e34b2356e5bd2bc2c27f33979c3 Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 30 Jan 2023 14:08:21 -0600 Subject: [PATCH 11/12] show min/max crypto amounts returned by simplex api on quote request --- lib/pages/buy_view/buy_form.dart | 49 ++++++++++++----------- lib/services/buy/buy_response.dart | 6 ++- lib/services/buy/simplex/simplex_api.dart | 21 ++++++++-- 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/lib/pages/buy_view/buy_form.dart b/lib/pages/buy_view/buy_form.dart index a46238188..051afcf71 100644 --- a/lib/pages/buy_view/buy_form.dart +++ b/lib/pages/buy_view/buy_form.dart @@ -531,25 +531,25 @@ class _BuyFormState extends ConsumerState { } } else { // Error; probably amount out of bounds - String errorMessage = "${quoteResponse.exception?.errorMessage}"; - if (errorMessage.contains('must be between')) { - errorMessage = errorMessage.substring( - errorMessage.indexOf('getQuote exception: ') + 20, - errorMessage.indexOf(", value: null")); - _BuyFormState.boundedCryptoTicker = errorMessage.substring( - errorMessage.indexOf('The ') + 4, - errorMessage.indexOf(' amount must be between')); - _BuyFormState.minCrypto = Decimal.parse(errorMessage.substring( - errorMessage.indexOf('must be between ') + 16, - errorMessage.indexOf(' and '))); - _BuyFormState.maxCrypto = Decimal.parse(errorMessage.substring( - errorMessage.indexOf("$minCrypto and ") + "$minCrypto and ".length, - errorMessage.length)); - if (Decimal.parse(_buyAmountController.text) > - _BuyFormState.maxCrypto) { - _buyAmountController.text = _BuyFormState.maxCrypto.toString(); - } - } + // String errorMessage = "${quoteResponse.exception?.errorMessage}"; + // if (errorMessage.contains('must be between')) { + // errorMessage = errorMessage.substring( + // errorMessage.indexOf('getQuote exception: ') + 20, + // errorMessage.indexOf(", value: null")); + // _BuyFormState.boundedCryptoTicker = errorMessage.substring( + // errorMessage.indexOf('The ') + 4, + // errorMessage.indexOf(' amount must be between')); + // _BuyFormState.minCrypto = Decimal.parse(errorMessage.substring( + // errorMessage.indexOf('must be between ') + 16, + // errorMessage.indexOf(' and '))); + // _BuyFormState.maxCrypto = Decimal.parse(errorMessage.substring( + // errorMessage.indexOf("$minCrypto and ") + "$minCrypto and ".length, + // errorMessage.length)); + // if (Decimal.parse(_buyAmountController.text) > + // _BuyFormState.maxCrypto) { + // _buyAmountController.text = _BuyFormState.maxCrypto.toString(); + // } + // } await showDialog( context: context, barrierDismissible: true, @@ -571,7 +571,7 @@ class _BuyFormState extends ConsumerState { height: 24, ), Text( - errorMessage, + quoteResponse.exception!.errorMessage, style: STextStyles.smallMed14(context), ), const SizedBox( @@ -633,10 +633,11 @@ class _BuyFormState extends ConsumerState { level: LogLevel.Warning, ); return BuyResponse( - exception: BuyException( - response.toString(), - BuyExceptionType.generic, - ), + exception: response.exception ?? + BuyException( + response.toString(), + BuyExceptionType.generic, + ), ); } } diff --git a/lib/services/buy/buy_response.dart b/lib/services/buy/buy_response.dart index 3198d0a19..6510ece4c 100644 --- a/lib/services/buy/buy_response.dart +++ b/lib/services/buy/buy_response.dart @@ -1,4 +1,8 @@ -enum BuyExceptionType { generic, serializeResponseError } +enum BuyExceptionType { + generic, + serializeResponseError, + cryptoAmountOutOfRange, +} class BuyException implements Exception { String errorMessage; diff --git a/lib/services/buy/simplex/simplex_api.dart b/lib/services/buy/simplex/simplex_api.dart index 4060567f0..85b4d5d9e 100644 --- a/lib/services/buy/simplex/simplex_api.dart +++ b/lib/services/buy/simplex/simplex_api.dart @@ -210,7 +210,20 @@ class SimplexAPI { BuyResponse _parseQuote(dynamic jsonArray) { try { - String cryptoAmount = "${jsonArray['digital_money']['amount']}"; + // final Map lol = + // Map.from(jsonArray as Map); + + String? cryptoAmount = jsonArray['digital_money']?['amount'] as String?; + + if (cryptoAmount == null) { + String error = jsonArray['error'] as String; + return BuyResponse( + exception: BuyException( + error, + BuyExceptionType.cryptoAmountOutOfRange, + ), + ); + } SimplexQuote quote = jsonArray['quote'] as SimplexQuote; final SimplexQuote _quote = SimplexQuote( @@ -277,9 +290,9 @@ class SimplexAPI { } final jsonArray = jsonDecode(res.body); // TODO check if valid json if (jsonArray.containsKey('error') as bool) { - if (jsonArray['error'] == true || jsonArray['error'] == 'true') { - throw Exception(jsonArray['message']); - } + if (jsonArray['error'] == true || jsonArray['error'] == 'true') { + throw Exception(jsonArray['message']); + } } SimplexOrder _order = SimplexOrder( From 1f7bd41d8eb23dc0039432941279fccf49151c6f Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 30 Jan 2023 14:15:44 -0600 Subject: [PATCH 12/12] update tests mock calls --- test/widget_tests/transaction_card_test.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/widget_tests/transaction_card_test.dart b/test/widget_tests/transaction_card_test.dart index 0ab7e4477..84b6372d5 100644 --- a/test/widget_tests/transaction_card_test.dart +++ b/test/widget_tests/transaction_card_test.dart @@ -80,6 +80,8 @@ void main() { when(wallets.getManager("wallet-id")) .thenAnswer((realInvocation) => Manager(wallet)); + + when(wallet.storedChainHeight).thenAnswer((_) => 6000000); // await tester.pumpWidget( ProviderScope( @@ -173,6 +175,7 @@ void main() { .thenAnswer((realInvocation) => Tuple2(Decimal.ten, 0.00)); when(wallet.coin).thenAnswer((_) => Coin.firo); + when(wallet.storedChainHeight).thenAnswer((_) => 6000000); when(wallets.getManager("wallet-id")) .thenAnswer((realInvocation) => Manager(wallet)); @@ -271,6 +274,8 @@ void main() { when(wallets.getManager("wallet-id")) .thenAnswer((realInvocation) => Manager(wallet)); + when(wallet.storedChainHeight).thenAnswer((_) => 6000000); + await tester.pumpWidget( ProviderScope( overrides: [ @@ -358,6 +363,8 @@ void main() { when(wallets.getManager("wallet id")) .thenAnswer((realInvocation) => Manager(wallet)); + when(wallet.storedChainHeight).thenAnswer((_) => 6000000); + mockingjay .when(() => navigator.pushNamed("/transactionDetails", arguments: Tuple3(tx, Coin.firo, "wallet id"))) @@ -395,6 +402,7 @@ void main() { verify(mockPrefs.currency).called(2); verify(mockLocaleService.locale).called(4); verify(wallet.coin.ticker).called(2); + verify(wallet.storedChainHeight).called(2); verifyNoMoreInteractions(wallet); verifyNoMoreInteractions(mockLocaleService);