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 bool isFixedRateMode}) async {
final headers = {apiHeaderKey: apiKey};
final normalizedFrom = normalizeCryptoCurrency(from);
final normalizedTo = normalizeCryptoCurrency(to);
final flow = getFlow(isFixedRateMode);
final params = <String, String>{
'fromCurrency': normalizedFrom,
'toCurrency': normalizedTo,
'fromNetwork': networkFor(from),
'toNetwork': networkFor(to),
'fromCurrency': _normalizeCurrency(from),
'toCurrency': _normalizeCurrency(to),
'fromNetwork': _networkFor(from),
'toNetwork': _networkFor(to),
'flow': flow
};
final uri = Uri.https(apiAuthority, rangePath, params);
@ -112,10 +110,10 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
final flow = getFlow(isFixedRateMode);
final type = isFixedRateMode ? 'reverse' : 'direct';
final body = <String, dynamic>{
'fromCurrency': normalizeCryptoCurrency(_request.from),
'toCurrency': normalizeCryptoCurrency(_request.to),
'fromNetwork': networkFor(_request.from),
'toNetwork': networkFor(_request.to),
'fromCurrency': _normalizeCurrency(_request.from),
'toCurrency': _normalizeCurrency(_request.to),
'fromNetwork': _networkFor(_request.from),
'toNetwork': _networkFor(_request.to),
if (!isFixedRateMode) 'fromAmount': _request.fromAmount,
if (isFixedRateMode) 'toAmount': _request.toAmount,
'address': _request.address,
@ -241,10 +239,10 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
final type = isReverse ? 'reverse' : 'direct';
final flow = getFlow(isFixedRateMode);
final params = <String, String>{
'fromCurrency': normalizeCryptoCurrency(from),
'toCurrency': normalizeCryptoCurrency(to),
'fromNetwork': networkFor(from),
'toNetwork': networkFor(to),
'fromCurrency': _normalizeCurrency(from),
'toCurrency': _normalizeCurrency(to),
'fromNetwork': _networkFor(from),
'toNetwork': _networkFor(to),
'type': type,
'flow': flow
};
@ -273,25 +271,34 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
}
}
String networkFor(CryptoCurrency currency) {
String _networkFor(CryptoCurrency currency) {
switch (currency) {
case CryptoCurrency.usdt:
return CryptoCurrency.btc.title.toLowerCase();
return 'btc';
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) {
switch (currency) {
case CryptoCurrency.zec:
return 'zec';
case CryptoCurrency.usdcpoly:
return 'usdcmatic';
case CryptoCurrency.maticpoly:
return 'maticmainnet';
default:
return currency.title.toLowerCase();
String _normalizeCurrency(CryptoCurrency currency) {
switch (currency) {
case CryptoCurrency.zec:
return 'zec';
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.dcr,
CryptoCurrency.kmd,
CryptoCurrency.mkr,
CryptoCurrency.oxt,
CryptoCurrency.pivx,
CryptoCurrency.rune,

View file

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