quick fixes for swap logic across providers (#2702)

* fix currency matching and network mapping

* add support for Arbitrum

* Update lib/exchange/provider/exolix_exchange_provider.dart [skip ci]

* Update lib/exchange/provider/exolix_exchange_provider.dart [skip ci]

---------

Co-authored-by: Serhii-Borodenko <17529954+Serhii-Borodenko@users.noreply.github.com>
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
Serhii
2025-12-03 23:24:33 +01:00
committed by GitHub
co-authored by Serhii-Borodenko Omar Hatem
parent da478b5421
commit bad88e9ce1
6 changed files with 50 additions and 7 deletions
+11
View File
@@ -357,6 +357,17 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> implemen
return null;
}
// Try for native currency with same title and tag
if (tag == null || tag.isEmpty) {
final match = CryptoCurrency.all.firstWhereOrNull(
(e) =>
e.title.toUpperCase() == raw.toUpperCase() && (e.tag == raw.toUpperCase()),
);
if (match != null) return match;
}
try {
return CryptoCurrency.fromString(raw, walletCurrency: walletCurrency);
} catch (_) {}
@@ -283,14 +283,14 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
final fromCurrency = responseJSON['fromCurrency'] as String;
final fromNetwork = responseJSON['fromNetwork'] as String?;
final _normalizedFromNetwork = _normalizeNetworkType(fromNetwork ?? '');
final fromTag = fromCurrency == _normalizedFromNetwork ? null : _normalizedFromNetwork;
final fromTag = fromCurrency.toUpperCase() == _normalizedFromNetwork.toUpperCase() ? null : _normalizedFromNetwork;
final from = CryptoCurrency.safeParseCurrencyFromString(fromCurrency, tag: fromTag);
// Parsing 'to' currency
final toCurrency = responseJSON['toCurrency'] as String;
final toNetwork = responseJSON['toNetwork'] as String?;
final _normalizedToNetwork = _normalizeNetworkType(toNetwork ?? '');
final toTag = toCurrency == _normalizedToNetwork ? null : _normalizedToNetwork;
final toTag = toCurrency.toUpperCase() == _normalizedToNetwork.toUpperCase() ? null : _normalizedToNetwork;
final to = CryptoCurrency.safeParseCurrencyFromString(toCurrency, tag: toTag);
final inputAddress = responseJSON['payinAddress'] as String;
@@ -326,6 +326,8 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
switch (currency) {
case CryptoCurrency.usdt:
return 'btc';
case CryptoCurrency.arb:
return 'arbitrum';
default:
return currency.tag != null ? _normalizeTag(currency.tag!) : currency.title.toLowerCase();
}
@@ -360,6 +362,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
return switch (network.toUpperCase()) {
'POLY' => 'MATIC',
'AVAXC' => 'CCHAIN',
'ARBITRUM' => 'ARB',
_ => network,
};
}
@@ -364,13 +364,15 @@ class ExolixExchangeProvider extends ExchangeProvider {
// Parsing 'from' currency
final coinFrom = responseJSON['coinFrom']['coinCode'] as String;
final coinFromNetwork = responseJSON['coinFrom']['network'] as String?;
final fromTag = coinFrom == coinFromNetwork ? null : coinFromNetwork;
final _normalizedFromNetwork = _normalizeNetworkType(coinFromNetwork ?? '');
final fromTag = coinFrom.toUpperCase() == _normalizedFromNetwork.toUpperCase() ? null : coinFromNetwork;
final from = CryptoCurrency.safeParseCurrencyFromString(coinFrom, tag: fromTag);
// Parsing 'to' currency
final coinTo = responseJSON['coinTo']['coinCode'] as String;
final coinToNetwork = responseJSON['coinTo']['network'] as String?;
final toTag = coinTo == coinToNetwork ? null : coinToNetwork;
final _normalizedToNetwork = _normalizeNetworkType(coinToNetwork ?? '');
final toTag = coinTo.toUpperCase() == _normalizedToNetwork.toUpperCase() ? null : coinToNetwork;
final to = CryptoCurrency.safeParseCurrencyFromString(coinTo, tag: toTag);
final inputAddress = responseJSON['depositAddress'] as String;
@@ -417,6 +419,13 @@ class ExolixExchangeProvider extends ExchangeProvider {
}
}
String _normalizeNetworkType(String network) {
return switch (network.toUpperCase()) {
'ARBITRUM' => 'ARB',
_ => network,
};
}
String _normalizeCurrency(CryptoCurrency currency) {
switch (currency) {
case CryptoCurrency.nano:
@@ -434,7 +434,8 @@ class LetsExchangeExchangeProvider extends ExchangeProvider {
return currency.tag!;
}
}
return currency.title;
return _normalizeTitleToNetwork(currency.title);
}
String _normalizeNetworkType(String network) {
@@ -442,10 +443,18 @@ class LetsExchangeExchangeProvider extends ExchangeProvider {
'ERC20' => 'ETH',
'TRC20' => 'TRX',
'BEP20' => 'BSC',
'ARBITRUM' => 'ARB',
_ => network,
};
}
String _normalizeTitleToNetwork(String title) {
return switch (title.toUpperCase()) {
'ARB' => 'ARBITRUM',
_ => title,
};
}
String _normalizeBchAddress(String address) =>
address.startsWith('bitcoincash:') ? address.substring(12) : address;
}
@@ -346,13 +346,15 @@ class StealthExExchangeProvider extends ExchangeProvider {
// Parsing 'from' currency with network tag
final fromCurrency = deposit['symbol'] as String;
final fromNetwork = deposit['network'] as String?;
final fromTag = fromNetwork == 'mainnet' ? null : fromNetwork;
final _normalizedFromNetwork = _normalizeNetworkType(fromNetwork ?? '');
final fromTag = _normalizedFromNetwork == 'mainnet' ? null : fromNetwork;
final from = CryptoCurrency.safeParseCurrencyFromString(fromCurrency, tag: fromTag);
// Parsing 'to' currency with network tag
final toCurrency = withdrawal['symbol'] as String;
final toNetwork = withdrawal['network'] as String?;
final toTag = toNetwork == 'mainnet' ? null : toNetwork;
final _normalizedToNetwork = _normalizeNetworkType(toNetwork ?? '');
final toTag = _normalizedToNetwork == 'mainnet' ? null : toNetwork;
final to = CryptoCurrency.safeParseCurrencyFromString(toCurrency, tag: toTag);
final payoutAddress = withdrawal['address'] as String;
@@ -440,7 +442,15 @@ class StealthExExchangeProvider extends ExchangeProvider {
return currency.title.toLowerCase();
}
String _normalizeNetworkType(String network) {
return switch (network.toUpperCase()) {
'ARBITRUM' => 'mainnet',
_ => network,
};
}
String _getNetwork(CryptoCurrency currency) {
if (currency == CryptoCurrency.arb) return 'arbitrum';
if (currency.tag == null) return 'mainnet';
if (currency == CryptoCurrency.maticpoly) return 'mainnet';
@@ -523,6 +523,7 @@ class TrocadorExchangeProvider extends ExchangeProvider {
'TRC20' => 'TRX',
'BEP20' => 'BSC',
'LIGHTNING' => 'LN',
'MATIC' => 'POL',
_ => network,
};
}