mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-09 12:29:31 +00:00
- Fix RangeError due to changes in _tradeAvailableProviders while the Futures complete
- Silently catch "Concurrent modification during iteration"
This commit is contained in:
parent
74b571fc77
commit
e67b484613
1 changed files with 11 additions and 5 deletions
|
@ -192,7 +192,7 @@ abstract class ExchangeViewModelBase with Store {
|
||||||
ObservableList<ExchangeTemplate> get templates =>
|
ObservableList<ExchangeTemplate> get templates =>
|
||||||
_exchangeTemplateStore.templates;
|
_exchangeTemplateStore.templates;
|
||||||
|
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
TransactionPriority get transactionPriority {
|
TransactionPriority get transactionPriority {
|
||||||
final priority = _settingsStore.priority[wallet.type];
|
final priority = _settingsStore.priority[wallet.type];
|
||||||
|
@ -308,10 +308,11 @@ abstract class ExchangeViewModelBase with Store {
|
||||||
Future<void> _calculateBestRate() async {
|
Future<void> _calculateBestRate() async {
|
||||||
final amount = double.tryParse(isFixedRateMode ? receiveAmount : depositAmount) ?? 1;
|
final amount = double.tryParse(isFixedRateMode ? receiveAmount : depositAmount) ?? 1;
|
||||||
|
|
||||||
|
final _providers = _tradeAvailableProviders
|
||||||
|
.where((element) => !isFixedRateMode || element.supportsFixedRate).toList();
|
||||||
|
|
||||||
final result = await Future.wait<double>(
|
final result = await Future.wait<double>(
|
||||||
_tradeAvailableProviders
|
_providers.map((element) => element.fetchRate(
|
||||||
.where((element) => !isFixedRateMode || element.supportsFixedRate)
|
|
||||||
.map((element) => element.fetchRate(
|
|
||||||
from: depositCurrency,
|
from: depositCurrency,
|
||||||
to: receiveCurrency,
|
to: receiveCurrency,
|
||||||
amount: amount,
|
amount: amount,
|
||||||
|
@ -324,7 +325,12 @@ abstract class ExchangeViewModelBase with Store {
|
||||||
for (int i=0;i<result.length;i++) {
|
for (int i=0;i<result.length;i++) {
|
||||||
if (result[i] != 0) {
|
if (result[i] != 0) {
|
||||||
/// add this provider as its valid for this trade
|
/// add this provider as its valid for this trade
|
||||||
_sortedAvailableProviders[result[i]] = _tradeAvailableProviders[i];
|
try {
|
||||||
|
_sortedAvailableProviders[result[i]] = _providers[i];
|
||||||
|
} catch (e) {
|
||||||
|
// will throw "Concurrent modification during iteration" error if modified at the same
|
||||||
|
// time [createTrade] is called, as this is not a normal map, but a sorted map
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_sortedAvailableProviders.isNotEmpty) {
|
if (_sortedAvailableProviders.isNotEmpty) {
|
||||||
|
|
Loading…
Reference in a new issue