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]
Justin Ehrenhofer committed
Aug 24, 2023 at 16:30 UTC
9999816850560da68040f3150ead330fc92e1518
3 files changed
+51
-37
lib/exchange/changenow/changenow_exchange_provider.dart
+37
-30
@@ -68,14 +68,12 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
68
required CryptoCurrency to,
69
required bool isFixedRateMode}) async {
70
final headers = {apiHeaderKey: apiKey};
71
- final normalizedFrom = normalizeCryptoCurrency(from);
72
- final normalizedTo = normalizeCryptoCurrency(to);
71
final flow = getFlow(isFixedRateMode);
72
final params = <String, String>{
75
- 'fromCurrency': normalizedFrom,
76
- 'toCurrency': normalizedTo,
77
- 'fromNetwork': networkFor(from),
78
- 'toNetwork': networkFor(to),
73
+ 'fromCurrency': _normalizeCurrency(from),
74
+ 'toCurrency': _normalizeCurrency(to),
75
+ 'fromNetwork': _networkFor(from),
76
+ 'toNetwork': _networkFor(to),
77
'flow': flow
78
};
79
final uri = Uri.https(apiAuthority, rangePath, params);
@@ -112,10 +110,10 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
110
final flow = getFlow(isFixedRateMode);
111
final type = isFixedRateMode ? 'reverse' : 'direct';
112
final body = <String, dynamic>{
115
- 'fromCurrency': normalizeCryptoCurrency(_request.from),
116
- 'toCurrency': normalizeCryptoCurrency(_request.to),
117
- 'fromNetwork': networkFor(_request.from),
118
- 'toNetwork': networkFor(_request.to),
113
+ 'fromCurrency': _normalizeCurrency(_request.from),
114
+ 'toCurrency': _normalizeCurrency(_request.to),
115
+ 'fromNetwork': _networkFor(_request.from),
116
+ 'toNetwork': _networkFor(_request.to),
117
if (!isFixedRateMode) 'fromAmount': _request.fromAmount,
118
if (isFixedRateMode) 'toAmount': _request.toAmount,
119
'address': _request.address,
@@ -241,10 +239,10 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
239
final type = isReverse ? 'reverse' : 'direct';
240
final flow = getFlow(isFixedRateMode);
241
final params = <String, String>{
244
- 'fromCurrency': normalizeCryptoCurrency(from),
245
- 'toCurrency': normalizeCryptoCurrency(to),
246
- 'fromNetwork': networkFor(from),
247
- 'toNetwork': networkFor(to),
242
+ 'fromCurrency': _normalizeCurrency(from),
243
+ 'toCurrency': _normalizeCurrency(to),
244
+ 'fromNetwork': _networkFor(from),
245
+ 'toNetwork': _networkFor(to),
246
'type': type,
247
'flow': flow
248
};
@@ -273,25 +271,34 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
271
}
272
}
273
276
- String networkFor(CryptoCurrency currency) {
274
+ String _networkFor(CryptoCurrency currency) {
275
switch (currency) {
276
case CryptoCurrency.usdt:
279
- return CryptoCurrency.btc.title.toLowerCase();
277
+ return 'btc';
278
default:
281
- return currency.tag != null ? currency.tag!.toLowerCase() : currency.title.toLowerCase();
279
+ return currency.tag != null ? _normalizeTag(currency.tag!) : currency.title.toLowerCase();
280
}
281
}
284
-}
285
-
286
-String normalizeCryptoCurrency(CryptoCurrency currency) {
287
- switch (currency) {
288
- case CryptoCurrency.zec:
289
- return 'zec';
290
- case CryptoCurrency.usdcpoly:
291
- return 'usdcmatic';
292
- case CryptoCurrency.maticpoly:
293
- return 'maticmainnet';
294
- default:
295
- return currency.title.toLowerCase();
282
+
283
+ String _normalizeCurrency(CryptoCurrency currency) {
284
+ switch (currency) {
285
+ case CryptoCurrency.zec:
286
+ return 'zec';
287
+ default:
288
+ return currency.title.toLowerCase();
289
+ }
290
+ }
291
+
292
+ String _normalizeTag(String tag) {
293
+ switch (tag) {
294
+ case 'POLY':
295
+ return 'matic';
296
+ case 'LN':
297
+ return 'lightning';
298
+ case 'AVAXC':
299
+ return 'cchain';
300
+ default:
301
+ return tag.toLowerCase();
302
+ }
303
}
297
-}
304
+}
\ No newline at end of file
lib/exchange/sideshift/sideshift_exchange_provider.dart
-1
@@ -28,7 +28,6 @@ class SideShiftExchangeProvider extends ExchangeProvider {
28
CryptoCurrency.xhv,
29
CryptoCurrency.dcr,
30
CryptoCurrency.kmd,
31
- CryptoCurrency.mkr,
31
CryptoCurrency.oxt,
32
CryptoCurrency.pivx,
33
CryptoCurrency.rune,
lib/exchange/trocador/trocador_exchange_provider.dart
+14
-6
@@ -20,7 +20,6 @@ class TrocadorExchangeProvider extends ExchangeProvider {
20
bool useTorOnly;
21
22
static const List<CryptoCurrency> _notSupported = [
23
- CryptoCurrency.scrt,
23
CryptoCurrency.stx,
24
CryptoCurrency.zaddr,
25
];
@@ -60,8 +59,8 @@ class TrocadorExchangeProvider extends ExchangeProvider {
59
}) async {
60
final params = <String, String>{
61
'api_key': apiKey,
63
- 'ticker_from': request.from.title.toLowerCase(),
64
- 'ticker_to': request.to.title.toLowerCase(),
62
+ 'ticker_from': _normalizeCurrency(request.from),
63
+ 'ticker_to': _normalizeCurrency(request.to),
64
'network_from': _networkFor(request.from),
65
'network_to': _networkFor(request.to),
66
'payment': isFixedRateMode ? 'True' : 'False',
@@ -137,7 +136,7 @@ class TrocadorExchangeProvider extends ExchangeProvider {
136
required bool isFixedRateMode}) async {
137
final params = <String, String>{
138
'api_key': apiKey,
140
- 'ticker': from.title.toLowerCase(),
139
+ 'ticker': _normalizeCurrency(from),
140
'name': from.name,
141
};
142
@@ -177,8 +176,8 @@ class TrocadorExchangeProvider extends ExchangeProvider {
176
177
final params = <String, String>{
178
'api_key': apiKey,
180
- 'ticker_from': from.title.toLowerCase(),
181
- 'ticker_to': to.title.toLowerCase(),
179
+ 'ticker_from': _normalizeCurrency(from),
180
+ 'ticker_to': _normalizeCurrency(to),
181
'network_from': _networkFor(from),
182
'network_to': _networkFor(to),
183
if (!isFixedRateMode) 'amount_from': amount.toString(),
@@ -279,6 +278,15 @@ class TrocadorExchangeProvider extends ExchangeProvider {
278
}
279
}
280
281
+ String _normalizeCurrency(CryptoCurrency currency) {
282
+ switch (currency) {
283
+ case CryptoCurrency.zec:
284
+ return 'zec';
285
+ default:
286
+ return currency.title.toLowerCase();
287
+ }
288
+ }
289
+
290
String _normalizeTag(String tag) {
291
switch (tag) {
292
case 'ETH':