From e67b484613445d7efb2d5dbcde05eefc956b5d0a Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Tue, 7 Feb 2023 23:48:10 +0200 Subject: [PATCH] - Fix RangeError due to changes in _tradeAvailableProviders while the Futures complete - Silently catch "Concurrent modification during iteration" --- lib/view_model/exchange/exchange_view_model.dart | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index 5c1f696b8..d310e6278 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -192,7 +192,7 @@ abstract class ExchangeViewModelBase with Store { ObservableList get templates => _exchangeTemplateStore.templates; - + @computed TransactionPriority get transactionPriority { final priority = _settingsStore.priority[wallet.type]; @@ -308,10 +308,11 @@ abstract class ExchangeViewModelBase with Store { Future _calculateBestRate() async { final amount = double.tryParse(isFixedRateMode ? receiveAmount : depositAmount) ?? 1; + final _providers = _tradeAvailableProviders + .where((element) => !isFixedRateMode || element.supportsFixedRate).toList(); + final result = await Future.wait( - _tradeAvailableProviders - .where((element) => !isFixedRateMode || element.supportsFixedRate) - .map((element) => element.fetchRate( + _providers.map((element) => element.fetchRate( from: depositCurrency, to: receiveCurrency, amount: amount, @@ -324,7 +325,12 @@ abstract class ExchangeViewModelBase with Store { for (int i=0;i