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>

Serhii committed Dec 4, 2025 at 00:24 UTC bad88e9ce1fa6f48ce0ee2e72d5840f21468839d
6 files changed +50 -7
cw_core/lib/crypto_currency.dart
+11
@@ -357,6 +357,17 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> implemen
357 return null;
358 }
359
360 +
361 + // Try for native currency with same title and tag
362 + if (tag == null || tag.isEmpty) {
363 + final match = CryptoCurrency.all.firstWhereOrNull(
364 + (e) =>
365 + e.title.toUpperCase() == raw.toUpperCase() && (e.tag == raw.toUpperCase()),
366 + );
367 +
368 + if (match != null) return match;
369 + }
370 +
371 try {
372 return CryptoCurrency.fromString(raw, walletCurrency: walletCurrency);
373 } catch (_) {}
lib/exchange/provider/changenow_exchange_provider.dart
+5 -2
@@ -283,14 +283,14 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
283 final fromCurrency = responseJSON['fromCurrency'] as String;
284 final fromNetwork = responseJSON['fromNetwork'] as String?;
285 final _normalizedFromNetwork = _normalizeNetworkType(fromNetwork ?? '');
286 - final fromTag = fromCurrency == _normalizedFromNetwork ? null : _normalizedFromNetwork;
286 + final fromTag = fromCurrency.toUpperCase() == _normalizedFromNetwork.toUpperCase() ? null : _normalizedFromNetwork;
287 final from = CryptoCurrency.safeParseCurrencyFromString(fromCurrency, tag: fromTag);
288
289 // Parsing 'to' currency
290 final toCurrency = responseJSON['toCurrency'] as String;
291 final toNetwork = responseJSON['toNetwork'] as String?;
292 final _normalizedToNetwork = _normalizeNetworkType(toNetwork ?? '');
293 - final toTag = toCurrency == _normalizedToNetwork ? null : _normalizedToNetwork;
293 + final toTag = toCurrency.toUpperCase() == _normalizedToNetwork.toUpperCase() ? null : _normalizedToNetwork;
294 final to = CryptoCurrency.safeParseCurrencyFromString(toCurrency, tag: toTag);
295
296 final inputAddress = responseJSON['payinAddress'] as String;
@@ -326,6 +326,8 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
326 switch (currency) {
327 case CryptoCurrency.usdt:
328 return 'btc';
329 + case CryptoCurrency.arb:
330 + return 'arbitrum';
331 default:
332 return currency.tag != null ? _normalizeTag(currency.tag!) : currency.title.toLowerCase();
333 }
@@ -360,6 +362,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
362 return switch (network.toUpperCase()) {
363 'POLY' => 'MATIC',
364 'AVAXC' => 'CCHAIN',
365 + 'ARBITRUM' => 'ARB',
366 _ => network,
367 };
368 }
lib/exchange/provider/exolix_exchange_provider.dart
+11 -2
@@ -364,13 +364,15 @@ class ExolixExchangeProvider extends ExchangeProvider {
364 // Parsing 'from' currency
365 final coinFrom = responseJSON['coinFrom']['coinCode'] as String;
366 final coinFromNetwork = responseJSON['coinFrom']['network'] as String?;
367 - final fromTag = coinFrom == coinFromNetwork ? null : coinFromNetwork;
367 + final _normalizedFromNetwork = _normalizeNetworkType(coinFromNetwork ?? '');
368 + final fromTag = coinFrom.toUpperCase() == _normalizedFromNetwork.toUpperCase() ? null : coinFromNetwork;
369 final from = CryptoCurrency.safeParseCurrencyFromString(coinFrom, tag: fromTag);
370
371 // Parsing 'to' currency
372 final coinTo = responseJSON['coinTo']['coinCode'] as String;
373 final coinToNetwork = responseJSON['coinTo']['network'] as String?;
373 - final toTag = coinTo == coinToNetwork ? null : coinToNetwork;
374 + final _normalizedToNetwork = _normalizeNetworkType(coinToNetwork ?? '');
375 + final toTag = coinTo.toUpperCase() == _normalizedToNetwork.toUpperCase() ? null : coinToNetwork;
376 final to = CryptoCurrency.safeParseCurrencyFromString(coinTo, tag: toTag);
377
378 final inputAddress = responseJSON['depositAddress'] as String;
@@ -417,6 +419,13 @@ class ExolixExchangeProvider extends ExchangeProvider {
419 }
420 }
421
422 + String _normalizeNetworkType(String network) {
423 + return switch (network.toUpperCase()) {
424 + 'ARBITRUM' => 'ARB',
425 + _ => network,
426 + };
427 + }
428 +
429 String _normalizeCurrency(CryptoCurrency currency) {
430 switch (currency) {
431 case CryptoCurrency.nano:
lib/exchange/provider/letsexchange_exchange_provider.dart
+10 -1
@@ -434,7 +434,8 @@ class LetsExchangeExchangeProvider extends ExchangeProvider {
434 return currency.tag!;
435 }
436 }
437 - return currency.title;
437 +
438 + return _normalizeTitleToNetwork(currency.title);
439 }
440
441 String _normalizeNetworkType(String network) {
@@ -442,10 +443,18 @@ class LetsExchangeExchangeProvider extends ExchangeProvider {
443 'ERC20' => 'ETH',
444 'TRC20' => 'TRX',
445 'BEP20' => 'BSC',
446 + 'ARBITRUM' => 'ARB',
447 _ => network,
448 };
449 }
450
451 + String _normalizeTitleToNetwork(String title) {
452 + return switch (title.toUpperCase()) {
453 + 'ARB' => 'ARBITRUM',
454 + _ => title,
455 + };
456 + }
457 +
458 String _normalizeBchAddress(String address) =>
459 address.startsWith('bitcoincash:') ? address.substring(12) : address;
460 }
lib/exchange/provider/stealth_ex_exchange_provider.dart
+12 -2
@@ -346,13 +346,15 @@ class StealthExExchangeProvider extends ExchangeProvider {
346 // Parsing 'from' currency with network tag
347 final fromCurrency = deposit['symbol'] as String;
348 final fromNetwork = deposit['network'] as String?;
349 - final fromTag = fromNetwork == 'mainnet' ? null : fromNetwork;
349 + final _normalizedFromNetwork = _normalizeNetworkType(fromNetwork ?? '');
350 + final fromTag = _normalizedFromNetwork == 'mainnet' ? null : fromNetwork;
351 final from = CryptoCurrency.safeParseCurrencyFromString(fromCurrency, tag: fromTag);
352
353 // Parsing 'to' currency with network tag
354 final toCurrency = withdrawal['symbol'] as String;
355 final toNetwork = withdrawal['network'] as String?;
355 - final toTag = toNetwork == 'mainnet' ? null : toNetwork;
356 + final _normalizedToNetwork = _normalizeNetworkType(toNetwork ?? '');
357 + final toTag = _normalizedToNetwork == 'mainnet' ? null : toNetwork;
358 final to = CryptoCurrency.safeParseCurrencyFromString(toCurrency, tag: toTag);
359
360 final payoutAddress = withdrawal['address'] as String;
@@ -440,7 +442,15 @@ class StealthExExchangeProvider extends ExchangeProvider {
442 return currency.title.toLowerCase();
443 }
444
445 + String _normalizeNetworkType(String network) {
446 + return switch (network.toUpperCase()) {
447 + 'ARBITRUM' => 'mainnet',
448 + _ => network,
449 + };
450 + }
451 +
452 String _getNetwork(CryptoCurrency currency) {
453 + if (currency == CryptoCurrency.arb) return 'arbitrum';
454 if (currency.tag == null) return 'mainnet';
455
456 if (currency == CryptoCurrency.maticpoly) return 'mainnet';
lib/exchange/provider/trocador_exchange_provider.dart
+1
@@ -523,6 +523,7 @@ class TrocadorExchangeProvider extends ExchangeProvider {
523 'TRC20' => 'TRX',
524 'BEP20' => 'BSC',
525 'LIGHTNING' => 'LN',
526 + 'MATIC' => 'POL',
527 _ => network,
528 };
529 }