@@ -149,13 +149,12 @@ 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 hasSelectedQuote &&
158
- hasSelectedPaymentMethod &&
157
+ return hasSelectedPaymentMethod &&
159
158
isPaymentMethodLoaded &&
160
159
isBuySellQuotLoaded;
161
160
}
@@ -215,12 +214,14 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
215
214
216
215
if (bestRateQuote != null ) {
217
216
_cryptoNumberFormat.maximumFractionDigits = cryptoCurrency.decimals;
218
- cryptoAmount = _cryptoNumberFormat
219
- .format (enteredAmount / bestRateQuote! .rate)
220
- .toString ()
221
- .replaceAll (RegExp ('\\ ,' ), '' );
217
+ cryptoAmount = _cryptoNumberFormat
218
+ .format (enteredAmount / bestRateQuote! .rate)
219
+ .toString ()
220
+ .replaceAll (RegExp ('\\ ,' ), '' );
222
221
} else {
223
- await calculateBestRate ();
222
+ if (bestRateQuote != null || fiatCurrency == bestRateQuote? .fiatCurrency) {
223
+ await calculateBestRate ();
224
+ }
224
225
}
225
226
}
226
227
@@ -243,14 +244,15 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
243
244
fiatAmount = '' ;
244
245
return ;
245
246
}
246
-
247
247
if (bestRateQuote != null ) {
248
248
fiatAmount = _cryptoNumberFormat
249
249
.format (enteredAmount * bestRateQuote! .rate)
250
250
.toString ()
251
251
.replaceAll (RegExp ('\\ ,' ), '' );
252
252
} else {
253
- await calculateBestRate ();
253
+ if (bestRateQuote != null || fiatCurrency == bestRateQuote? .fiatCurrency) {
254
+ await calculateBestRate ();
255
+ }
254
256
}
255
257
}
256
258
@@ -308,7 +310,7 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
308
310
}).toList ();
309
311
310
312
final updatedQuoteOptions = List <SelectableItem >.from ([
311
- OptionTitle (title: 'Recommended' ),
313
+ if (sortedRecommendedQuotes.isNotEmpty) OptionTitle (title: 'Recommended' ),
312
314
...sortedRecommendedQuotes,
313
315
if (sortedQuotes.isNotEmpty) OptionTitle (title: 'All Providers' ),
314
316
...sortedQuotes,
@@ -352,13 +354,20 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
352
354
Future <void > _getAvailablePaymentTypes () async {
353
355
paymentMethodState = PaymentMethodLoading ();
354
356
selectedPaymentMethod = null ;
355
- final result = await Future .wait (providerList.map ((element) => element
357
+ final resultNative = await Future .wait (providerList.map ((element) => element
356
358
.getAvailablePaymentTypes (fiatCurrency.title, cryptoCurrency, isBuyAction)
357
359
.timeout (
358
360
Duration (seconds: 10 ),
359
361
onTimeout: () => [],
360
362
)));
361
-
363
+
364
+ final resultSepa = await Future .wait (providerList.map ((element) => element
365
+ .getAvailablePaymentTypes (FiatCurrency .eur.title, cryptoCurrency, isBuyAction)
366
+ .timeout (
367
+ Duration (seconds: 10 ),
368
+ onTimeout: () => [],
369
+ )));
370
+ final result = [...resultNative, ...resultSepa];
362
371
final Map <PaymentType , PaymentMethod > uniquePaymentMethods = {};
363
372
for (var methods in result) {
364
373
for (var method in methods) {
@@ -395,36 +404,35 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
395
404
Future <void > calculateBestRate () async {
396
405
buySellQuotState = BuySellQuotLoading ();
397
406
398
- final List <BuyProvider > validProviders = providerList.where ((provider) {
399
- bool isValid = false ;
407
+ final List <BuyProvider > validProvidersNative = providerList.where ((provider) {
400
408
if (isBuyAction) {
401
- isValid = provider.supportedCryptoList.any ((pair) =>
409
+ return provider.supportedCryptoList.any ((pair) =>
402
410
pair.from == cryptoCurrency && pair.to == fiatCurrency);
403
411
} else {
404
- isValid = provider.supportedFiatList.any ((pair) =>
412
+ return provider.supportedFiatList.any ((pair) =>
405
413
pair.from == fiatCurrency && pair.to == cryptoCurrency);
406
414
}
407
- if (isValid) {
408
- return true ;
409
- }
415
+ }). toList ();
416
+
417
+ final List < BuyProvider > validProvidersSepa = providerList. where ((provider) {
410
418
if (currenciesWithSepa.contains (fiatCurrency)) {
411
419
if (isBuyAction) {
412
- isValid = provider.supportedCryptoList.any ((pair) =>
413
- pair.from == cryptoCurrency && pair.to == fiatCurrency );
420
+ return provider.supportedCryptoList.any ((pair) =>
421
+ pair.from == cryptoCurrency && pair.to == FiatCurrency .eur );
414
422
} else {
415
- isValid = provider.supportedFiatList.any ((pair) =>
416
- pair.from == fiatCurrency && pair.to == cryptoCurrency);
423
+ return provider.supportedFiatList.any ((pair) =>
424
+ pair.from == FiatCurrency .eur && pair.to == cryptoCurrency);
417
425
}
418
426
}
419
427
return false ;
420
428
}).toList ();
421
429
422
- if (validProviders .isEmpty) {
430
+ if (validProvidersNative.isEmpty && validProvidersSepa .isEmpty) {
423
431
buySellQuotState = BuySellQuotFailed ();
424
432
return ;
425
433
}
426
434
427
- final result = await Future .wait <List <Quote >?>(validProviders .map ((element) => element
435
+ final result = await Future .wait <List <Quote >?>(validProvidersNative .map ((element) => element
428
436
.fetchQuote (
429
437
cryptoCurrency: cryptoCurrency,
430
438
fiatCurrency: fiatCurrency,
@@ -437,44 +445,72 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
437
445
Duration (seconds: 10 ),
438
446
onTimeout: () => null ,
439
447
)));
448
+ final resultSepa = await Future .wait <List <Quote >?>(validProvidersSepa.map ((element) => element
449
+ .fetchQuote (
450
+ cryptoCurrency: cryptoCurrency,
451
+ fiatCurrency: FiatCurrency .eur,
452
+ amount: amount,
453
+ paymentType: selectedPaymentMethod? .paymentMethodType,
454
+ isBuyAction: isBuyAction,
455
+ walletAddress: wallet.walletAddresses.address,
456
+ )
457
+ .timeout (
458
+ Duration (seconds: 10 ),
459
+ onTimeout: () => null ,
460
+ )));
440
461
441
462
sortedRecommendedQuotes.clear ();
442
463
sortedQuotes.clear ();
443
464
444
- final validQuotes = result
465
+ final validQuotesNative = result
445
466
.where ((element) => element != null && element.isNotEmpty)
446
467
.expand ((element) => element! )
447
468
.toList ();
448
469
449
- if (validQuotes.isEmpty) {
470
+ final validQuotesSepa = resultSepa
471
+ .where ((element) => element != null && element.isNotEmpty)
472
+ .expand ((element) => element! )
473
+ .toList ();
474
+
475
+ if (validQuotesNative.isEmpty && validQuotesSepa.isEmpty) {
450
476
buySellQuotState = BuySellQuotFailed ();
451
477
return ;
452
478
}
453
479
454
- validQuotes.sort ((a, b) => a.rate.compareTo (b.rate));
480
+ validQuotesNative.sort ((a, b) => a.rate.compareTo (b.rate));
481
+ validQuotesSepa.sort ((a, b) => a.rate.compareTo (b.rate));
455
482
456
483
final Set <String > addedProviders = {};
457
- final List <Quote > uniqueProviderQuotes = validQuotes.where ((element) {
484
+
485
+ final List <Quote > uniqueProviderQuotesNative = validQuotesNative.where ((element) {
486
+ if (addedProviders.contains (element.provider.title)) return false ;
487
+ addedProviders.add (element.provider.title);
488
+ return true ;
489
+ }).toList ();
490
+
491
+ final List <Quote > uniqueProviderQuotesSepa = validQuotesSepa.where ((element) {
458
492
if (addedProviders.contains (element.provider.title)) return false ;
459
493
addedProviders.add (element.provider.title);
460
494
return true ;
461
495
}).toList ();
462
496
463
- final List <Quote > successRateQuotes = validQuotes .where ((element) =>
497
+ final List <Quote > successRateQuotes = [...validQuotesNative, ...validQuotesSepa] .where ((element) =>
464
498
element.provider is OnRamperBuyProvider &&
465
499
element.recommendations.contains (ProviderRecommendation .successRate)
466
500
).toList ();
467
501
502
+ final List <Quote > uniqueProviderQuotes = [];
503
+
468
504
for (final quote in successRateQuotes) {
469
- if (! uniqueProviderQuotes .contains (quote)) {
505
+ if (! uniqueProviderQuotesNative .contains (quote)) {
470
506
uniqueProviderQuotes.add (quote);
471
507
}
472
508
}
473
509
474
510
sortedRecommendedQuotes.addAll (uniqueProviderQuotes);
475
511
476
512
sortedQuotes = ObservableList .of (
477
- validQuotes .where ((element) => ! uniqueProviderQuotes.contains (element)).toList ());
513
+ [...validQuotesNative, ...validQuotesSepa] .where ((element) => ! uniqueProviderQuotes.contains (element)).toList ());
478
514
479
515
if (sortedRecommendedQuotes.isNotEmpty) {
480
516
sortedRecommendedQuotes.first
0 commit comments