From 367535045293be1d52eeff563a8e698757654ca2 Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Fri, 30 Apr 2021 12:46:15 +0300 Subject: [PATCH] CAKE-314 | changed bnb crypto currency to bnb bep2; removed bnb bep2 from receive currency list on exchange page --- lib/entities/crypto_currency.dart | 4 +-- .../changenow_exchange_provider.dart | 36 +++++++++++++------ .../exchange/exchange_view_model.dart | 3 +- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/lib/entities/crypto_currency.dart b/lib/entities/crypto_currency.dart index d5f23a0fa..74694ed77 100644 --- a/lib/entities/crypto_currency.dart +++ b/lib/entities/crypto_currency.dart @@ -29,7 +29,7 @@ class CryptoCurrency extends EnumerableItem with Serializable { static const xmr = CryptoCurrency(title: 'XMR', raw: 0); static const ada = CryptoCurrency(title: 'ADA', raw: 1); static const bch = CryptoCurrency(title: 'BCH', raw: 2); - static const bnb = CryptoCurrency(title: 'BNB', raw: 3); + static const bnb = CryptoCurrency(title: 'BNB BEP2', raw: 3); static const btc = CryptoCurrency(title: 'BTC', raw: 4); static const dai = CryptoCurrency(title: 'DAI', raw: 5); static const dash = CryptoCurrency(title: 'DASH', raw: 6); @@ -90,7 +90,7 @@ class CryptoCurrency extends EnumerableItem with Serializable { return CryptoCurrency.ada; case 'bch': return CryptoCurrency.bch; - case 'bnb': + case 'bnbmainnet': return CryptoCurrency.bnb; case 'btc': return CryptoCurrency.btc; diff --git a/lib/exchange/changenow/changenow_exchange_provider.dart b/lib/exchange/changenow/changenow_exchange_provider.dart index 69674131d..0adaf6c83 100644 --- a/lib/exchange/changenow/changenow_exchange_provider.dart +++ b/lib/exchange/changenow/changenow_exchange_provider.dart @@ -48,7 +48,9 @@ class ChangeNowExchangeProvider extends ExchangeProvider { @override Future fetchLimits({CryptoCurrency from, CryptoCurrency to, bool isFixedRateMode}) async { - final symbol = from.toString() + '_' + to.toString(); + final fromTitle = defineCurrencyTitle(from); + final toTitle = defineCurrencyTitle(to); + final symbol = fromTitle + '_' + toTitle; final url = isFixedRateMode ? apiUri + _marketInfoUriSufix + _fixedRateUriSufix + apiKey : apiUri + _minAmountUriSufix + symbol; @@ -61,8 +63,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider { final elemFrom = elem["from"] as String; final elemTo = elem["to"] as String; - if ((elemFrom == from.toString().toLowerCase()) && - (elemTo == to.toString().toLowerCase())) { + if ((elemFrom == fromTitle) && (elemTo == toTitle)) { final min = elem["min"] as double; final max = elem["max"] as double; @@ -84,9 +85,11 @@ class ChangeNowExchangeProvider extends ExchangeProvider { ? apiUri + _transactionsUriSufix + _fixedRateUriSufix + apiKey : apiUri + _transactionsUriSufix + apiKey; final _request = request as ChangeNowRequest; + final fromTitle = defineCurrencyTitle(_request.from); + final toTitle = defineCurrencyTitle(_request.to); final body = { - 'from': _request.from.toString(), - 'to': _request.to.toString(), + 'from': fromTitle, + 'to': toTitle, 'address': _request.address, 'amount': _request.amount, 'refundAddress': _request.refundAddress @@ -182,6 +185,8 @@ class ChangeNowExchangeProvider extends ExchangeProvider { final url = apiUri + _marketInfoUriSufix + _fixedRateUriSufix + apiKey; final response = await get(url); final responseJSON = json.decode(response.body) as List; + final fromTitle = defineCurrencyTitle(from); + final toTitle = defineCurrencyTitle(to); var rate = 0.0; var fee = 0.0; @@ -189,8 +194,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider { final elemFrom = elem["from"] as String; final elemTo = elem["to"] as String; - if ((elemFrom == to.toString().toLowerCase()) && - (elemTo == from.toString().toLowerCase())) { + if ((elemFrom == toTitle) && (elemTo == fromTitle)) { rate = elem["rate"] as double; fee = elem["minerFee"] as double; break; @@ -216,22 +220,32 @@ class ChangeNowExchangeProvider extends ExchangeProvider { CryptoCurrency to, double amount, bool isFixedRateMode) { + final fromTitle = defineCurrencyTitle(from); + final toTitle = defineCurrencyTitle(to); + return isFixedRateMode ? apiUri + _exchangeAmountUriSufix + _fixedRateUriSufix + amount.toString() + '/' + - from.toString() + + fromTitle + '_' + - to.toString() + + toTitle + '?api_key=' + apiKey : apiUri + _exchangeAmountUriSufix + amount.toString() + '/' + - from.toString() + + fromTitle + '_' + - to.toString(); + toTitle; + } + + static String defineCurrencyTitle(CryptoCurrency currency) { + const bnbTitle = 'bnbmainnet'; + final currencyTitle = currency == CryptoCurrency.bnb + ? bnbTitle : currency.title.toLowerCase(); + return currencyTitle; } } diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index fc860e011..d93213c45 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -59,7 +59,8 @@ abstract class ExchangeViewModelBase with Store { }); receiveCurrencies = CryptoCurrency.all.where((cryptoCurrency) => (cryptoCurrency != CryptoCurrency.xlm)&& - (cryptoCurrency != CryptoCurrency.xrp)).toList(); + (cryptoCurrency != CryptoCurrency.xrp)&& + (cryptoCurrency != CryptoCurrency.bnb)).toList(); _defineIsReceiveAmountEditable(); isFixedRateMode = false; isReceiveAmountEntered = false;