@@ -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
}
@@ -220,7 +219,9 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
220
219
.toString ()
221
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
@@ -250,7 +251,9 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
250
251
.toString ()
251
252
.replaceAll (RegExp ('\\ ,' ), '' );
252
253
} else {
253
- await calculateBestRate ();
254
+ if (bestRateQuote != null || fiatCurrency == bestRateQuote? .fiatCurrency) {
255
+ await calculateBestRate ();
256
+ }
254
257
}
255
258
}
256
259
@@ -308,7 +311,7 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
308
311
}).toList ();
309
312
310
313
final updatedQuoteOptions = List <SelectableItem >.from ([
311
- OptionTitle (title: 'Recommended' ),
314
+ if (sortedRecommendedQuotes.isNotEmpty) OptionTitle (title: 'Recommended' ),
312
315
...sortedRecommendedQuotes,
313
316
if (sortedQuotes.isNotEmpty) OptionTitle (title: 'All Providers' ),
314
317
...sortedQuotes,
@@ -352,13 +355,20 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
352
355
Future <void > _getAvailablePaymentTypes () async {
353
356
paymentMethodState = PaymentMethodLoading ();
354
357
selectedPaymentMethod = null ;
355
- final result = await Future .wait (providerList.map ((element) => element
358
+ final resultNative = await Future .wait (providerList.map ((element) => element
356
359
.getAvailablePaymentTypes (fiatCurrency.title, cryptoCurrency, isBuyAction)
357
360
.timeout (
358
361
Duration (seconds: 10 ),
359
362
onTimeout: () => [],
360
363
)));
361
-
364
+
365
+ final resultSepa = await Future .wait (providerList.map ((element) => element
366
+ .getAvailablePaymentTypes (FiatCurrency .eur.title, cryptoCurrency, isBuyAction)
367
+ .timeout (
368
+ Duration (seconds: 10 ),
369
+ onTimeout: () => [],
370
+ )));
371
+ final result = [...resultNative, ...resultSepa];
362
372
final Map <PaymentType , PaymentMethod > uniquePaymentMethods = {};
363
373
for (var methods in result) {
364
374
for (var method in methods) {
@@ -376,12 +386,26 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
376
386
paymentMethodState = PaymentMethodFailed ();
377
387
}
378
388
}
389
+ static const currenciesWithSepa = [
390
+ // 'ALL', // Albanian lek
391
+ FiatCurrency .bgn, // Bulgarian lev
392
+ FiatCurrency .czk, // Czech koruna
393
+ FiatCurrency .dkk, // Danish krone
394
+ FiatCurrency .huf, // Hungarian forint
395
+ FiatCurrency .isk, // Icelandic króna
396
+ FiatCurrency .chf, // Liechtenstein/Swiss franc
397
+ FiatCurrency .nok, // Norwegian krone
398
+ FiatCurrency .pln, // Polish złoty
399
+ FiatCurrency .ron, // Romanian leu
400
+ FiatCurrency .sek, // Swedish krona
401
+ FiatCurrency .gbp, // British pound sterling
402
+ ];
379
403
380
404
@action
381
405
Future <void > calculateBestRate () async {
382
406
buySellQuotState = BuySellQuotLoading ();
383
407
384
- final List <BuyProvider > validProviders = providerList.where ((provider) {
408
+ final List <BuyProvider > validProvidersNative = providerList.where ((provider) {
385
409
if (isBuyAction) {
386
410
return provider.supportedCryptoList.any ((pair) =>
387
411
pair.from == cryptoCurrency && pair.to == fiatCurrency);
@@ -391,12 +415,25 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
391
415
}
392
416
}).toList ();
393
417
394
- if (validProviders.isEmpty) {
418
+ final List <BuyProvider > validProvidersSepa = providerList.where ((provider) {
419
+ if (currenciesWithSepa.contains (fiatCurrency)) {
420
+ if (isBuyAction) {
421
+ return provider.supportedCryptoList.any ((pair) =>
422
+ pair.from == cryptoCurrency && pair.to == FiatCurrency .eur);
423
+ } else {
424
+ return provider.supportedFiatList.any ((pair) =>
425
+ pair.from == FiatCurrency .eur && pair.to == cryptoCurrency);
426
+ }
427
+ }
428
+ return false ;
429
+ }).toList ();
430
+
431
+ if (validProvidersNative.isEmpty && validProvidersSepa.isEmpty) {
395
432
buySellQuotState = BuySellQuotFailed ();
396
433
return ;
397
434
}
398
435
399
- final result = await Future .wait <List <Quote >?>(validProviders .map ((element) => element
436
+ final result = await Future .wait <List <Quote >?>(validProvidersNative .map ((element) => element
400
437
.fetchQuote (
401
438
cryptoCurrency: cryptoCurrency,
402
439
fiatCurrency: fiatCurrency,
@@ -409,44 +446,67 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
409
446
Duration (seconds: 10 ),
410
447
onTimeout: () => null ,
411
448
)));
449
+ final resultSepa = await Future .wait <List <Quote >?>(validProvidersSepa.map ((element) => element
450
+ .fetchQuote (
451
+ cryptoCurrency: cryptoCurrency,
452
+ fiatCurrency: FiatCurrency .eur,
453
+ amount: amount,
454
+ paymentType: selectedPaymentMethod? .paymentMethodType,
455
+ isBuyAction: isBuyAction,
456
+ walletAddress: wallet.walletAddresses.address,
457
+ )
458
+ .timeout (
459
+ Duration (seconds: 10 ),
460
+ onTimeout: () => null ,
461
+ )));
412
462
413
463
sortedRecommendedQuotes.clear ();
414
464
sortedQuotes.clear ();
415
465
416
- final validQuotes = result
466
+ final validQuotesNative = result
417
467
.where ((element) => element != null && element.isNotEmpty)
418
468
.expand ((element) => element! )
419
469
.toList ();
420
470
421
- if (validQuotes.isEmpty) {
471
+ final validQuotesSepa = resultSepa
472
+ .where ((element) => element != null && element.isNotEmpty)
473
+ .expand ((element) => element! )
474
+ .toList ();
475
+
476
+ if (validQuotesNative.isEmpty && validQuotesSepa.isEmpty) {
422
477
buySellQuotState = BuySellQuotFailed ();
423
478
return ;
424
479
}
425
480
426
- validQuotes.sort ((a, b) => a.rate.compareTo (b.rate));
481
+ validQuotesNative.sort ((a, b) => a.rate.compareTo (b.rate));
482
+ validQuotesSepa.sort ((a, b) => a.rate.compareTo (b.rate));
427
483
428
484
final Set <String > addedProviders = {};
429
- final List <Quote > uniqueProviderQuotes = validQuotes.where ((element) {
485
+
486
+ final List <Quote > uniqueProviderQuotesNative = validQuotesNative.where ((element) {
430
487
if (addedProviders.contains (element.provider.title)) return false ;
431
488
addedProviders.add (element.provider.title);
432
489
return true ;
433
490
}).toList ();
434
491
435
- final List <Quote > successRateQuotes = validQuotes.where ((element) =>
492
+
493
+ final List <Quote > successRateQuotes = [...validQuotesNative, ...validQuotesSepa].where ((element) =>
436
494
element.provider is OnRamperBuyProvider &&
437
495
element.recommendations.contains (ProviderRecommendation .successRate)
438
496
).toList ();
439
497
498
+ final List <Quote > uniqueProviderQuotes = [];
499
+
440
500
for (final quote in successRateQuotes) {
441
- if (! uniqueProviderQuotes .contains (quote)) {
501
+ if (! uniqueProviderQuotesNative .contains (quote)) {
442
502
uniqueProviderQuotes.add (quote);
443
503
}
444
504
}
445
505
446
506
sortedRecommendedQuotes.addAll (uniqueProviderQuotes);
447
507
448
508
sortedQuotes = ObservableList .of (
449
- validQuotes .where ((element) => ! uniqueProviderQuotes.contains (element)).toList ());
509
+ [...validQuotesNative, ...validQuotesSepa] .where ((element) => ! uniqueProviderQuotes.contains (element)).toList ());
450
510
451
511
if (sortedRecommendedQuotes.isNotEmpty) {
452
512
sortedRecommendedQuotes.first
0 commit comments