@@ -149,12 +149,13 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
149
149
150
150
@computed
151
151
bool get isReadyToTrade {
152
- // final hasSelectedQuote = selectedQuote != null;
152
+ final hasSelectedQuote = selectedQuote != null ;
153
153
final hasSelectedPaymentMethod = selectedPaymentMethod != null ;
154
154
final isPaymentMethodLoaded = paymentMethodState is PaymentMethodLoaded ;
155
155
final isBuySellQuotLoaded = buySellQuotState is BuySellQuotLoaded ;
156
156
157
- return hasSelectedPaymentMethod &&
157
+ return hasSelectedQuote &&
158
+ hasSelectedPaymentMethod &&
158
159
isPaymentMethodLoaded &&
159
160
isBuySellQuotLoaded;
160
161
}
@@ -213,15 +214,17 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
213
214
}
214
215
215
216
if (bestRateQuote != null ) {
217
+ if (bestRateQuote! .fiatCurrency != fiatCurrency) {
218
+ cryptoAmount = '' ;
219
+ return ;
220
+ }
216
221
_cryptoNumberFormat.maximumFractionDigits = cryptoCurrency.decimals;
217
222
cryptoAmount = _cryptoNumberFormat
218
223
.format (enteredAmount / bestRateQuote! .rate)
219
224
.toString ()
220
225
.replaceAll (RegExp ('\\ ,' ), '' );
221
226
} else {
222
- if (bestRateQuote != null || fiatCurrency == bestRateQuote? .fiatCurrency) {
223
- await calculateBestRate ();
224
- }
227
+ await calculateBestRate ();
225
228
}
226
229
}
227
230
@@ -246,14 +249,16 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
246
249
}
247
250
248
251
if (bestRateQuote != null ) {
252
+ if (bestRateQuote! .cryptoCurrency != cryptoCurrency) {
253
+ fiatAmount = '' ;
254
+ return ;
255
+ }
249
256
fiatAmount = _cryptoNumberFormat
250
257
.format (enteredAmount * bestRateQuote! .rate)
251
258
.toString ()
252
259
.replaceAll (RegExp ('\\ ,' ), '' );
253
260
} else {
254
- if (bestRateQuote != null || fiatCurrency == bestRateQuote? .fiatCurrency) {
255
- await calculateBestRate ();
256
- }
261
+ await calculateBestRate ();
257
262
}
258
263
}
259
264
@@ -433,7 +438,7 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
433
438
return ;
434
439
}
435
440
436
- final result = await Future .wait <List <Quote >?>(validProvidersNative.map ((element) => element
441
+ final resultNative = await Future .wait <List <Quote >?>(validProvidersNative.map ((element) => element
437
442
.fetchQuote (
438
443
cryptoCurrency: cryptoCurrency,
439
444
fiatCurrency: fiatCurrency,
@@ -446,6 +451,7 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
446
451
Duration (seconds: 10 ),
447
452
onTimeout: () => null ,
448
453
)));
454
+
449
455
final resultSepa = await Future .wait <List <Quote >?>(validProvidersSepa.map ((element) => element
450
456
.fetchQuote (
451
457
cryptoCurrency: cryptoCurrency,
@@ -463,7 +469,7 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
463
469
sortedRecommendedQuotes.clear ();
464
470
sortedQuotes.clear ();
465
471
466
- final validQuotesNative = result
472
+ final validQuotesNative = resultNative
467
473
.where ((element) => element != null && element.isNotEmpty)
468
474
.expand ((element) => element! )
469
475
.toList ();
@@ -489,6 +495,12 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
489
495
return true ;
490
496
}).toList ();
491
497
498
+ final List <Quote > uniqueProviderQuotesSepa = validQuotesSepa.where ((element) {
499
+ if (addedProviders.contains (element.provider.title)) return false ;
500
+ addedProviders.add (element.provider.title);
501
+ return true ;
502
+ }).toList ();
503
+
492
504
493
505
final List <Quote > successRateQuotes = [...validQuotesNative, ...validQuotesSepa].where ((element) =>
494
506
element.provider is OnRamperBuyProvider &&
@@ -498,7 +510,7 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
498
510
final List <Quote > uniqueProviderQuotes = [];
499
511
500
512
for (final quote in successRateQuotes) {
501
- if (! uniqueProviderQuotesNative.contains (quote)) {
513
+ if (! [... uniqueProviderQuotesNative, ...uniqueProviderQuotesSepa] .contains (quote)) {
502
514
uniqueProviderQuotes.add (quote);
503
515
}
504
516
}
@@ -522,6 +534,10 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
522
534
523
535
selectedQuote = sortedRecommendedQuotes.first;
524
536
sortedRecommendedQuotes.first.setIsSelected = true ;
537
+ } else if (sortedQuotes.isNotEmpty) {
538
+ sortedQuotes.first.setIsSelected = true ;
539
+ bestRateQuote = sortedQuotes.first;
540
+ selectedQuote = sortedQuotes.first;
525
541
}
526
542
527
543
buySellQuotState = BuySellQuotLoaded ();
0 commit comments