From 98b6db7284067f5ca661c4e93c3bdf433f171fac Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 20 Sep 2023 08:53:32 -0600 Subject: [PATCH] ensure usable exchanges are up to date when `update()` is called --- lib/pages/exchange_view/exchange_form.dart | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/pages/exchange_view/exchange_form.dart b/lib/pages/exchange_view/exchange_form.dart index a81f758a6..49a44071d 100644 --- a/lib/pages/exchange_view/exchange_form.dart +++ b/lib/pages/exchange_view/exchange_form.dart @@ -43,7 +43,6 @@ import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/exchange_rate_type_enum.dart'; -import 'package:stackwallet/utilities/prefs.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/widgets/conditional_parent.dart'; @@ -80,11 +79,17 @@ class _ExchangeFormState extends ConsumerState { late final Coin? coin; late final bool walletInitiated; - var exchanges = [ - MajesticBankExchange.instance, - ChangeNowExchange.instance, - TrocadorExchange.instance, - ]; + List get usableExchanges { + if (ref.read(prefsChangeNotifierProvider).useTor) { + return Exchange.exchangesWithTorSupport; + } else { + return [ + MajesticBankExchange.instance, + ChangeNowExchange.instance, + TrocadorExchange.instance, + ]; + } + } late final TextEditingController _sendController; late final TextEditingController _receiveController; @@ -623,7 +628,7 @@ class _ExchangeFormState extends ConsumerState { final uuid = const Uuid().v1(); _latestUuid = uuid; _addUpdate(uuid); - for (final exchange in exchanges) { + for (final exchange in usableExchanges) { ref.read(efEstimatesListProvider(exchange.name).notifier).state = null; } @@ -644,7 +649,7 @@ class _ExchangeFormState extends ConsumerState { final Map>, Range?>> results = {}; - for (final exchange in exchanges) { + for (final exchange in usableExchanges) { final sendCurrency = pair.send?.forExchange(exchange.name); final receiveCurrency = pair.receive?.forExchange(exchange.name); @@ -674,7 +679,7 @@ class _ExchangeFormState extends ConsumerState { } } - for (final exchange in exchanges) { + for (final exchange in usableExchanges) { if (uuid == _latestUuid) { ref.read(efEstimatesListProvider(exchange.name).notifier).state = results[exchange.name]; @@ -778,11 +783,6 @@ class _ExchangeFormState extends ConsumerState { // Instantiate the Tor service. torService = TorService.sharedInstance; - // Filter exchanges based on Tor support. - if (Prefs.instance.useTor) { - exchanges = Exchange.exchangesWithTorSupport; - } - super.initState(); }