Improve ChangeNOW and Trocador network mapping (#1058)

* Improve ChangeNOW network mapping

Follows Trocador code to use the title instead of the const name, and to allow normalizing across the tag level instead of needing to map the `legacyTicker`

I will test

* Missing `}`

* Remove `:`

* Add normalizeTitle for zec

* Missing `;`

* Make functions private and fix zec for Trocador

* Add supported assets [skip ci]

* Change name [skip ci]
This commit is contained in:
Justin Ehrenhofer 2023-08-24 16:30:53 -05:00 committed by GitHub
parent f6670c0236
commit 9999816850
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 36 deletions

View file

@ -68,14 +68,12 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
required CryptoCurrency to, required CryptoCurrency to,
required bool isFixedRateMode}) async { required bool isFixedRateMode}) async {
final headers = {apiHeaderKey: apiKey}; final headers = {apiHeaderKey: apiKey};
final normalizedFrom = normalizeCryptoCurrency(from);
final normalizedTo = normalizeCryptoCurrency(to);
final flow = getFlow(isFixedRateMode); final flow = getFlow(isFixedRateMode);
final params = <String, String>{ final params = <String, String>{
'fromCurrency': normalizedFrom, 'fromCurrency': _normalizeCurrency(from),
'toCurrency': normalizedTo, 'toCurrency': _normalizeCurrency(to),
'fromNetwork': networkFor(from), 'fromNetwork': _networkFor(from),
'toNetwork': networkFor(to), 'toNetwork': _networkFor(to),
'flow': flow 'flow': flow
}; };
final uri = Uri.https(apiAuthority, rangePath, params); final uri = Uri.https(apiAuthority, rangePath, params);
@ -112,10 +110,10 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
final flow = getFlow(isFixedRateMode); final flow = getFlow(isFixedRateMode);
final type = isFixedRateMode ? 'reverse' : 'direct'; final type = isFixedRateMode ? 'reverse' : 'direct';
final body = <String, dynamic>{ final body = <String, dynamic>{
'fromCurrency': normalizeCryptoCurrency(_request.from), 'fromCurrency': _normalizeCurrency(_request.from),
'toCurrency': normalizeCryptoCurrency(_request.to), 'toCurrency': _normalizeCurrency(_request.to),
'fromNetwork': networkFor(_request.from), 'fromNetwork': _networkFor(_request.from),
'toNetwork': networkFor(_request.to), 'toNetwork': _networkFor(_request.to),
if (!isFixedRateMode) 'fromAmount': _request.fromAmount, if (!isFixedRateMode) 'fromAmount': _request.fromAmount,
if (isFixedRateMode) 'toAmount': _request.toAmount, if (isFixedRateMode) 'toAmount': _request.toAmount,
'address': _request.address, 'address': _request.address,
@ -241,10 +239,10 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
final type = isReverse ? 'reverse' : 'direct'; final type = isReverse ? 'reverse' : 'direct';
final flow = getFlow(isFixedRateMode); final flow = getFlow(isFixedRateMode);
final params = <String, String>{ final params = <String, String>{
'fromCurrency': normalizeCryptoCurrency(from), 'fromCurrency': _normalizeCurrency(from),
'toCurrency': normalizeCryptoCurrency(to), 'toCurrency': _normalizeCurrency(to),
'fromNetwork': networkFor(from), 'fromNetwork': _networkFor(from),
'toNetwork': networkFor(to), 'toNetwork': _networkFor(to),
'type': type, 'type': type,
'flow': flow 'flow': flow
}; };
@ -273,25 +271,34 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
} }
} }
String networkFor(CryptoCurrency currency) { String _networkFor(CryptoCurrency currency) {
switch (currency) { switch (currency) {
case CryptoCurrency.usdt: case CryptoCurrency.usdt:
return CryptoCurrency.btc.title.toLowerCase(); return 'btc';
default: default:
return currency.tag != null ? currency.tag!.toLowerCase() : currency.title.toLowerCase(); return currency.tag != null ? _normalizeTag(currency.tag!) : currency.title.toLowerCase();
} }
} }
}
String normalizeCryptoCurrency(CryptoCurrency currency) { String _normalizeCurrency(CryptoCurrency currency) {
switch (currency) { switch (currency) {
case CryptoCurrency.zec: case CryptoCurrency.zec:
return 'zec'; return 'zec';
case CryptoCurrency.usdcpoly: default:
return 'usdcmatic'; return currency.title.toLowerCase();
case CryptoCurrency.maticpoly: }
return 'maticmainnet';
default:
return currency.title.toLowerCase();
} }
}
String _normalizeTag(String tag) {
switch (tag) {
case 'POLY':
return 'matic';
case 'LN':
return 'lightning';
case 'AVAXC':
return 'cchain';
default:
return tag.toLowerCase();
}
}
}

View file

@ -28,7 +28,6 @@ class SideShiftExchangeProvider extends ExchangeProvider {
CryptoCurrency.xhv, CryptoCurrency.xhv,
CryptoCurrency.dcr, CryptoCurrency.dcr,
CryptoCurrency.kmd, CryptoCurrency.kmd,
CryptoCurrency.mkr,
CryptoCurrency.oxt, CryptoCurrency.oxt,
CryptoCurrency.pivx, CryptoCurrency.pivx,
CryptoCurrency.rune, CryptoCurrency.rune,

View file

@ -20,7 +20,6 @@ class TrocadorExchangeProvider extends ExchangeProvider {
bool useTorOnly; bool useTorOnly;
static const List<CryptoCurrency> _notSupported = [ static const List<CryptoCurrency> _notSupported = [
CryptoCurrency.scrt,
CryptoCurrency.stx, CryptoCurrency.stx,
CryptoCurrency.zaddr, CryptoCurrency.zaddr,
]; ];
@ -60,8 +59,8 @@ class TrocadorExchangeProvider extends ExchangeProvider {
}) async { }) async {
final params = <String, String>{ final params = <String, String>{
'api_key': apiKey, 'api_key': apiKey,
'ticker_from': request.from.title.toLowerCase(), 'ticker_from': _normalizeCurrency(request.from),
'ticker_to': request.to.title.toLowerCase(), 'ticker_to': _normalizeCurrency(request.to),
'network_from': _networkFor(request.from), 'network_from': _networkFor(request.from),
'network_to': _networkFor(request.to), 'network_to': _networkFor(request.to),
'payment': isFixedRateMode ? 'True' : 'False', 'payment': isFixedRateMode ? 'True' : 'False',
@ -137,7 +136,7 @@ class TrocadorExchangeProvider extends ExchangeProvider {
required bool isFixedRateMode}) async { required bool isFixedRateMode}) async {
final params = <String, String>{ final params = <String, String>{
'api_key': apiKey, 'api_key': apiKey,
'ticker': from.title.toLowerCase(), 'ticker': _normalizeCurrency(from),
'name': from.name, 'name': from.name,
}; };
@ -177,8 +176,8 @@ class TrocadorExchangeProvider extends ExchangeProvider {
final params = <String, String>{ final params = <String, String>{
'api_key': apiKey, 'api_key': apiKey,
'ticker_from': from.title.toLowerCase(), 'ticker_from': _normalizeCurrency(from),
'ticker_to': to.title.toLowerCase(), 'ticker_to': _normalizeCurrency(to),
'network_from': _networkFor(from), 'network_from': _networkFor(from),
'network_to': _networkFor(to), 'network_to': _networkFor(to),
if (!isFixedRateMode) 'amount_from': amount.toString(), if (!isFixedRateMode) 'amount_from': amount.toString(),
@ -279,6 +278,15 @@ class TrocadorExchangeProvider extends ExchangeProvider {
} }
} }
String _normalizeCurrency(CryptoCurrency currency) {
switch (currency) {
case CryptoCurrency.zec:
return 'zec';
default:
return currency.title.toLowerCase();
}
}
String _normalizeTag(String tag) { String _normalizeTag(String tag) {
switch (tag) { switch (tag) {
case 'ETH': case 'ETH':