From 753d164d6e4be165d09e0a6f07ad515f3a5239a6 Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Thu, 1 Apr 2021 21:08:11 +0300 Subject: [PATCH] CAKE-296 | removed xmr to xrp and xmr to xlm exchange pairs from ChangeNow pair list; disabled exchange button when pair is not exists --- .../changenow/changenow_exchange_provider.dart | 15 +++++++++++++-- lib/src/screens/exchange/exchange_page.dart | 1 + .../exchange/exchange_view_model.dart | 17 +++++++++++------ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/exchange/changenow/changenow_exchange_provider.dart b/lib/exchange/changenow/changenow_exchange_provider.dart index 69674131d..b7abe4cc7 100644 --- a/lib/exchange/changenow/changenow_exchange_provider.dart +++ b/lib/exchange/changenow/changenow_exchange_provider.dart @@ -17,12 +17,23 @@ import 'package:cake_wallet/exchange/trade_not_created_exeption.dart'; class ChangeNowExchangeProvider extends ExchangeProvider { ChangeNowExchangeProvider() : super( - pairList: CryptoCurrency.all + /*pairList: CryptoCurrency.all .map((i) => CryptoCurrency.all .map((k) => ExchangePair(from: i, to: k, reverse: true)) .where((c) => c != null)) .expand((i) => i) - .toList()); + .toList());*/ + pairList: CryptoCurrency.all + .map((i) => CryptoCurrency.all + .map((k) { + if ((i != CryptoCurrency.xmr)|| + ((k != CryptoCurrency.xrp)&&(k != CryptoCurrency.xlm))) { + return ExchangePair(from: i, to: k, reverse: true); + } + }) + .where((c) => c != null)) + .expand((i) => i) + .toList()); static const apiUri = 'https://changenow.io/api/v1'; static const apiKey = secrets.changeNowApiKey; diff --git a/lib/src/screens/exchange/exchange_page.dart b/lib/src/screens/exchange/exchange_page.dart index cfd115811..ab959c77f 100644 --- a/lib/src/screens/exchange/exchange_page.dart +++ b/lib/src/screens/exchange/exchange_page.dart @@ -464,6 +464,7 @@ class ExchangePage extends BasePage { }, color: Theme.of(context).accentTextTheme.body2.color, textColor: Colors.white, + isDisabled: exchangeViewModel.isDisabledExchangeButton, isLoading: exchangeViewModel.tradeState is TradeIsCreating)), ]), diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index e708e93e9..f02a5ca49 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -60,6 +60,7 @@ abstract class ExchangeViewModelBase with Store { _defineIsReceiveAmountEditable(); isFixedRateMode = false; isReceiveAmountEntered = false; + isDisabledExchangeButton = false; loadLimits(); } @@ -113,6 +114,9 @@ abstract class ExchangeViewModelBase with Store { @observable bool isFixedRateMode; + @observable + bool isDisabledExchangeButton; + @computed SyncStatus get status => wallet.syncStatus; @@ -369,19 +373,20 @@ abstract class ExchangeViewModelBase with Store { pair.from == depositCurrency && pair.to == receiveCurrency) .isNotEmpty; - if (!isPairExist) { + if (isPairExist) { final provider = _providerForPair(from: depositCurrency, to: receiveCurrency); if (provider != null) { + isDisabledExchangeButton = false; changeProvider(provider: provider); } + } else { + isDisabledExchangeButton = true; + depositAmount = ''; + receiveAmount = ''; + limitsState = LimitsLoadedFailure(error: 'Pair is not exists'); } - - _defineIsReceiveAmountEditable(); - depositAmount = ''; - receiveAmount = ''; - loadLimits(); } ExchangeProvider _providerForPair({CryptoCurrency from, CryptoCurrency to}) {