@@ -148,13 +148,12 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
148148
149149 @computed
150150 bool get isReadyToTrade {
151- final hasSelectedQuote = selectedQuote != null ;
151+ // final hasSelectedQuote = selectedQuote != null;
152152 final hasSelectedPaymentMethod = selectedPaymentMethod != null ;
153153 final isPaymentMethodLoaded = paymentMethodState is PaymentMethodLoaded ;
154154 final isBuySellQuotLoaded = buySellQuotState is BuySellQuotLoaded ;
155155
156- return hasSelectedQuote &&
157- hasSelectedPaymentMethod &&
156+ return hasSelectedPaymentMethod &&
158157 isPaymentMethodLoaded &&
159158 isBuySellQuotLoaded;
160159 }
@@ -219,7 +218,9 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
219218 .toString ()
220219 .replaceAll (RegExp ('\\ ,' ), '' );
221220 } else {
222- await calculateBestRate ();
221+ if (bestRateQuote != null || fiatCurrency == bestRateQuote? .fiatCurrency) {
222+ await calculateBestRate ();
223+ }
223224 }
224225 }
225226
@@ -249,7 +250,9 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
249250 .toString ()
250251 .replaceAll (RegExp ('\\ ,' ), '' );
251252 } else {
252- await calculateBestRate ();
253+ if (bestRateQuote != null || fiatCurrency == bestRateQuote? .fiatCurrency) {
254+ await calculateBestRate ();
255+ }
253256 }
254257 }
255258
@@ -307,7 +310,7 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
307310 }).toList ();
308311
309312 final updatedQuoteOptions = List <SelectableItem >.from ([
310- OptionTitle (title: 'Recommended' ),
313+ if (sortedRecommendedQuotes.isNotEmpty) OptionTitle (title: 'Recommended' ),
311314 ...sortedRecommendedQuotes,
312315 if (sortedQuotes.isNotEmpty) OptionTitle (title: 'All Providers' ),
313316 ...sortedQuotes,
@@ -351,15 +354,23 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
351354 Future <void > _getAvailablePaymentTypes () async {
352355 paymentMethodState = PaymentMethodLoading ();
353356 selectedPaymentMethod = null ;
354- final result = await Future .wait (providerList.map ((element) => element
357+ final resultNative = await Future .wait (providerList.map ((element) => element
355358 .getAvailablePaymentTypes (fiatCurrency.title, cryptoCurrency, isBuyAction)
356359 .timeout (
357360 Duration (seconds: 10 ),
358361 onTimeout: () => [],
359362 )));
360363
361364 final List <PaymentMethod > tempPaymentMethods = [];
362-
365+
366+ final resultSepa = await Future .wait (providerList.map ((element) => element
367+ .getAvailablePaymentTypes (FiatCurrency .eur.title, cryptoCurrency, isBuyAction)
368+ .timeout (
369+ Duration (seconds: 10 ),
370+ onTimeout: () => [],
371+ )));
372+ final result = [...resultNative, ...resultSepa];
373+ final Map <PaymentType , PaymentMethod > uniquePaymentMethods = {};
363374 for (var methods in result) {
364375 for (var method in methods) {
365376 final alreadyExists = tempPaymentMethods.any ((m) {
@@ -384,12 +395,26 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
384395 paymentMethodState = PaymentMethodFailed ();
385396 }
386397 }
398+ static const currenciesWithSepa = [
399+ // 'ALL', // Albanian lek
400+ FiatCurrency .bgn, // Bulgarian lev
401+ FiatCurrency .czk, // Czech koruna
402+ FiatCurrency .dkk, // Danish krone
403+ FiatCurrency .huf, // Hungarian forint
404+ FiatCurrency .isk, // Icelandic króna
405+ FiatCurrency .chf, // Liechtenstein/Swiss franc
406+ FiatCurrency .nok, // Norwegian krone
407+ FiatCurrency .pln, // Polish złoty
408+ FiatCurrency .ron, // Romanian leu
409+ FiatCurrency .sek, // Swedish krona
410+ FiatCurrency .gbp, // British pound sterling
411+ ];
387412
388413 @action
389414 Future <void > calculateBestRate () async {
390415 buySellQuotState = BuySellQuotLoading ();
391416
392- final List <BuyProvider > validProviders = providerList.where ((provider) {
417+ final List <BuyProvider > validProvidersNative = providerList.where ((provider) {
393418 if (isBuyAction) {
394419 return provider.supportedCryptoList.any ((pair) =>
395420 pair.from == cryptoCurrency && pair.to == fiatCurrency);
@@ -399,12 +424,25 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
399424 }
400425 }).toList ();
401426
402- if (validProviders.isEmpty) {
427+ final List <BuyProvider > validProvidersSepa = providerList.where ((provider) {
428+ if (currenciesWithSepa.contains (fiatCurrency)) {
429+ if (isBuyAction) {
430+ return provider.supportedCryptoList.any ((pair) =>
431+ pair.from == cryptoCurrency && pair.to == FiatCurrency .eur);
432+ } else {
433+ return provider.supportedFiatList.any ((pair) =>
434+ pair.from == FiatCurrency .eur && pair.to == cryptoCurrency);
435+ }
436+ }
437+ return false ;
438+ }).toList ();
439+
440+ if (validProvidersNative.isEmpty && validProvidersSepa.isEmpty) {
403441 buySellQuotState = BuySellQuotFailed ();
404442 return ;
405443 }
406444
407- final result = await Future .wait <List <Quote >?>(validProviders .map ((element) => element
445+ final result = await Future .wait <List <Quote >?>(validProvidersNative .map ((element) => element
408446 .fetchQuote (
409447 cryptoCurrency: cryptoCurrency,
410448 fiatCurrency: fiatCurrency,
@@ -418,44 +456,67 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
418456 Duration (seconds: 10 ),
419457 onTimeout: () => null ,
420458 )));
459+ final resultSepa = await Future .wait <List <Quote >?>(validProvidersSepa.map ((element) => element
460+ .fetchQuote (
461+ cryptoCurrency: cryptoCurrency,
462+ fiatCurrency: FiatCurrency .eur,
463+ amount: amount,
464+ paymentType: selectedPaymentMethod? .paymentMethodType,
465+ isBuyAction: isBuyAction,
466+ walletAddress: wallet.walletAddresses.address,
467+ )
468+ .timeout (
469+ Duration (seconds: 10 ),
470+ onTimeout: () => null ,
471+ )));
421472
422473 sortedRecommendedQuotes.clear ();
423474 sortedQuotes.clear ();
424475
425- final validQuotes = result
476+ final validQuotesNative = result
426477 .where ((element) => element != null && element.isNotEmpty)
427478 .expand ((element) => element! )
428479 .toList ();
429480
430- if (validQuotes.isEmpty) {
481+ final validQuotesSepa = resultSepa
482+ .where ((element) => element != null && element.isNotEmpty)
483+ .expand ((element) => element! )
484+ .toList ();
485+
486+ if (validQuotesNative.isEmpty && validQuotesSepa.isEmpty) {
431487 buySellQuotState = BuySellQuotFailed ();
432488 return ;
433489 }
434490
435- validQuotes.sort ((a, b) => a.rate.compareTo (b.rate));
491+ validQuotesNative.sort ((a, b) => a.rate.compareTo (b.rate));
492+ validQuotesSepa.sort ((a, b) => a.rate.compareTo (b.rate));
436493
437494 final Set <String > addedProviders = {};
438- final List <Quote > uniqueProviderQuotes = validQuotes.where ((element) {
495+
496+ final List <Quote > uniqueProviderQuotesNative = validQuotesNative.where ((element) {
439497 if (addedProviders.contains (element.provider.title)) return false ;
440498 addedProviders.add (element.provider.title);
441499 return true ;
442500 }).toList ();
443501
444- final List <Quote > successRateQuotes = validQuotes.where ((element) =>
502+
503+ final List <Quote > successRateQuotes = [...validQuotesNative, ...validQuotesSepa].where ((element) =>
445504 element.provider is OnRamperBuyProvider &&
446505 element.recommendations.contains (ProviderRecommendation .successRate)
447506 ).toList ();
448507
508+ final List <Quote > uniqueProviderQuotes = [];
509+
449510 for (final quote in successRateQuotes) {
450- if (! uniqueProviderQuotes .contains (quote)) {
511+ if (! uniqueProviderQuotesNative .contains (quote)) {
451512 uniqueProviderQuotes.add (quote);
452513 }
453514 }
454515
455516 sortedRecommendedQuotes.addAll (uniqueProviderQuotes);
456517
457518 sortedQuotes = ObservableList .of (
458- validQuotes .where ((element) => ! uniqueProviderQuotes.contains (element)).toList ());
519+ [...validQuotesNative, ...validQuotesSepa] .where ((element) => ! uniqueProviderQuotes.contains (element)).toList ());
459520
460521 if (sortedRecommendedQuotes.isNotEmpty) {
461522 sortedRecommendedQuotes.first
0 commit comments