CAKE-314 | changed bnb crypto currency to bnb bep2; removed bnb bep2 from receive currency list on exchange page

OleksandrSobol committed Apr 30, 2021 at 12:46 UTC 367535045293be1d52eeff563a8e698757654ca2
3 files changed +29 -14
lib/entities/crypto_currency.dart
+2 -2
@@ -29,7 +29,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> {
29 static const xmr = CryptoCurrency(title: 'XMR', raw: 0);
30 static const ada = CryptoCurrency(title: 'ADA', raw: 1);
31 static const bch = CryptoCurrency(title: 'BCH', raw: 2);
32 - static const bnb = CryptoCurrency(title: 'BNB', raw: 3);
32 + static const bnb = CryptoCurrency(title: 'BNB BEP2', raw: 3);
33 static const btc = CryptoCurrency(title: 'BTC', raw: 4);
34 static const dai = CryptoCurrency(title: 'DAI', raw: 5);
35 static const dash = CryptoCurrency(title: 'DASH', raw: 6);
@@ -90,7 +90,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> {
90 return CryptoCurrency.ada;
91 case 'bch':
92 return CryptoCurrency.bch;
93 - case 'bnb':
93 + case 'bnbmainnet':
94 return CryptoCurrency.bnb;
95 case 'btc':
96 return CryptoCurrency.btc;
lib/exchange/changenow/changenow_exchange_provider.dart
+25 -11
@@ -48,7 +48,9 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
48 @override
49 Future<Limits> fetchLimits({CryptoCurrency from, CryptoCurrency to,
50 bool isFixedRateMode}) async {
51 - final symbol = from.toString() + '_' + to.toString();
51 + final fromTitle = defineCurrencyTitle(from);
52 + final toTitle = defineCurrencyTitle(to);
53 + final symbol = fromTitle + '_' + toTitle;
54 final url = isFixedRateMode
55 ? apiUri + _marketInfoUriSufix + _fixedRateUriSufix + apiKey
56 : apiUri + _minAmountUriSufix + symbol;
@@ -61,8 +63,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
63 final elemFrom = elem["from"] as String;
64 final elemTo = elem["to"] as String;
65
64 - if ((elemFrom == from.toString().toLowerCase()) &&
65 - (elemTo == to.toString().toLowerCase())) {
66 + if ((elemFrom == fromTitle) && (elemTo == toTitle)) {
67 final min = elem["min"] as double;
68 final max = elem["max"] as double;
69
@@ -84,9 +85,11 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
85 ? apiUri + _transactionsUriSufix + _fixedRateUriSufix + apiKey
86 : apiUri + _transactionsUriSufix + apiKey;
87 final _request = request as ChangeNowRequest;
88 + final fromTitle = defineCurrencyTitle(_request.from);
89 + final toTitle = defineCurrencyTitle(_request.to);
90 final body = {
88 - 'from': _request.from.toString(),
89 - 'to': _request.to.toString(),
91 + 'from': fromTitle,
92 + 'to': toTitle,
93 'address': _request.address,
94 'amount': _request.amount,
95 'refundAddress': _request.refundAddress
@@ -182,6 +185,8 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
185 final url = apiUri + _marketInfoUriSufix + _fixedRateUriSufix + apiKey;
186 final response = await get(url);
187 final responseJSON = json.decode(response.body) as List<dynamic>;
188 + final fromTitle = defineCurrencyTitle(from);
189 + final toTitle = defineCurrencyTitle(to);
190 var rate = 0.0;
191 var fee = 0.0;
192
@@ -189,8 +194,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
194 final elemFrom = elem["from"] as String;
195 final elemTo = elem["to"] as String;
196
192 - if ((elemFrom == to.toString().toLowerCase()) &&
193 - (elemTo == from.toString().toLowerCase())) {
197 + if ((elemFrom == toTitle) && (elemTo == fromTitle)) {
198 rate = elem["rate"] as double;
199 fee = elem["minerFee"] as double;
200 break;
@@ -216,22 +220,32 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
220 CryptoCurrency to,
221 double amount,
222 bool isFixedRateMode) {
223 + final fromTitle = defineCurrencyTitle(from);
224 + final toTitle = defineCurrencyTitle(to);
225 +
226 return isFixedRateMode
227 ? apiUri +
228 _exchangeAmountUriSufix +
229 _fixedRateUriSufix +
230 amount.toString() +
231 '/' +
225 - from.toString() +
232 + fromTitle +
233 '_' +
227 - to.toString() +
234 + toTitle +
235 '?api_key=' + apiKey
236 : apiUri +
237 _exchangeAmountUriSufix +
238 amount.toString() +
239 '/' +
233 - from.toString() +
240 + fromTitle +
241 '_' +
235 - to.toString();
242 + toTitle;
243 + }
244 +
245 + static String defineCurrencyTitle(CryptoCurrency currency) {
246 + const bnbTitle = 'bnbmainnet';
247 + final currencyTitle = currency == CryptoCurrency.bnb
248 + ? bnbTitle : currency.title.toLowerCase();
249 + return currencyTitle;
250 }
251 }
lib/view_model/exchange/exchange_view_model.dart
+2 -1
@@ -59,7 +59,8 @@ abstract class ExchangeViewModelBase with Store {
59 });
60 receiveCurrencies = CryptoCurrency.all.where((cryptoCurrency) =>
61 (cryptoCurrency != CryptoCurrency.xlm)&&
62 - (cryptoCurrency != CryptoCurrency.xrp)).toList();
62 + (cryptoCurrency != CryptoCurrency.xrp)&&
63 + (cryptoCurrency != CryptoCurrency.bnb)).toList();
64 _defineIsReceiveAmountEditable();
65 isFixedRateMode = false;
66 isReceiveAmountEntered = false;