Fixes for network based pairs for changenow. Fixes for address validation for ustd address.

M committed Feb 8, 2022 at 10:57 UTC 56cd6c26ed8a811fdc2b39b0f1685385e50ffff6
2 files changed +37 -7
lib/core/address_validator.dart
+1 -1
@@ -78,7 +78,7 @@ class AddressValidator extends TextValidator {
78 case CryptoCurrency.trx:
79 return [34];
80 case CryptoCurrency.usdt:
81 - return [42];
81 + return [34];
82 case CryptoCurrency.usdterc20:
83 return [42];
84 case CryptoCurrency.xlm:
lib/exchange/changenow/changenow_exchange_provider.dart
+36 -6
@@ -60,6 +60,8 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
60 final params = <String, String>{
61 'fromCurrency': normalizedFrom,
62 'toCurrency': normalizedTo,
63 + 'fromNetwork': networkFor(from),
64 + 'toNetwork': networkFor(to),
65 'flow': flow};
66 final uri = Uri.https(apiAuthority, rangePath, params);
67 final response = await get(uri, headers: headers);
@@ -90,7 +92,9 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
92 final flow = getFlow(isFixedRateMode);
93 final body = <String, String>{
94 'fromCurrency': normalizeCryptoCurrency(_request.from),
93 - 'toCurrency': normalizeCryptoCurrency(_request.to),
95 + 'toCurrency': normalizeCryptoCurrency(_request.to),
96 + 'fromNetwork': networkFor(_request.from),
97 + 'toNetwork': networkFor(_request.to),
98 'fromAmount': _request.fromAmount,
99 'toAmount': _request.toAmount,
100 'address': _request.address,
@@ -205,7 +209,9 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
209 final flow = getFlow(isFixedRateMode);
210 final params = <String, String>{
211 'fromCurrency': isReverse ? normalizeCryptoCurrency(to) : normalizeCryptoCurrency(from),
208 - 'toCurrency': isReverse ? normalizeCryptoCurrency(from) : normalizeCryptoCurrency(to) ,
212 + 'toCurrency': isReverse ? normalizeCryptoCurrency(from) : normalizeCryptoCurrency(to),
213 + 'fromNetwork': isReverse ? networkFor(to) : networkFor(from),
214 + 'toNetwork': isReverse ? networkFor(from) : networkFor(to),
215 'type': type,
216 'flow': flow};
217
@@ -232,11 +238,35 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
238 return 0.0;
239 }
240 }
241 +
242 + String networkFor(CryptoCurrency currency) {
243 + const bnbTitle = 'bnb';
244 +
245 + switch (currency) {
246 + case CryptoCurrency.usdt:
247 + return CryptoCurrency.btc.title.toLowerCase();
248 + case CryptoCurrency.usdterc20:
249 + return CryptoCurrency.eth.title.toLowerCase();
250 + case CryptoCurrency.bnb:
251 + return bnbTitle;
252 + case CryptoCurrency.dai:
253 + return CryptoCurrency.eth.title.toLowerCase();
254 + default:
255 + return currency.title.toLowerCase();
256 + }
257 + }
258
259 static String normalizeCryptoCurrency(CryptoCurrency currency) {
237 - const bnbTitle = 'bnbmainnet';
238 - final currencyTitle = currency == CryptoCurrency.bnb
239 - ? bnbTitle : currency.title.toLowerCase();
240 - return currencyTitle;
260 + const bnbTitle = 'bnb';
261 +
262 + switch(currency) {
263 + case CryptoCurrency.bnb:
264 + return bnbTitle;
265 + case CryptoCurrency.usdterc20:
266 + return CryptoCurrency.usdt.title.toLowerCase();
267 + default:
268 + return currency.title.toLowerCase();
269 + }
270 +
271 }
272 }