From 9aa7ac2b61fa5fcde0e840364fa5cdaab3d5a643 Mon Sep 17 00:00:00 2001 From: Serhii Date: Thu, 25 Dec 2025 10:37:38 +0200 Subject: [PATCH] add validation to ensure only supported currencies (#2758) --- .../provider/chainflip_exchange_provider.dart | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/lib/exchange/provider/chainflip_exchange_provider.dart b/lib/exchange/provider/chainflip_exchange_provider.dart index 92c2f5245..8fe0485e3 100644 --- a/lib/exchange/provider/chainflip_exchange_provider.dart +++ b/lib/exchange/provider/chainflip_exchange_provider.dart @@ -19,22 +19,19 @@ class ChainflipExchangeProvider extends ExchangeProvider { ChainflipExchangeProvider({required this.tradesStore}) : super(pairList: supportedPairs(_notSupported)); - static final List _notSupported = [ - ...(CryptoCurrency.all - .where((element) => ![ - CryptoCurrency.btc, - CryptoCurrency.eth, - CryptoCurrency.usdc, - CryptoCurrency.usdterc20, - CryptoCurrency.flip, - CryptoCurrency.sol, - CryptoCurrency.usdcsol, - // TODO: Add CryptoCurrency.etharb - // TODO: Add CryptoCurrency.usdcarb - // TODO: Add CryptoCurrency.dot - ].contains(element)) - .toList()) - ]; + static final List _notSupported = []; + static final List _supported = [ + CryptoCurrency.btc, + CryptoCurrency.eth, + CryptoCurrency.usdc, + CryptoCurrency.usdterc20, + CryptoCurrency.flip, + CryptoCurrency.sol, + CryptoCurrency.usdcsol, + CryptoCurrency.arbEth, + // TODO: Add CryptoCurrency.usdcarb + // TODO: Add CryptoCurrency.dot + ]; static const _baseURL = 'chainflip-broker.io'; static const _assetsPath = '/assets'; @@ -72,6 +69,11 @@ class ChainflipExchangeProvider extends ExchangeProvider { required bool isFixedRateMode}) async { try { + + if(!_supported.contains(from) || !_supported.contains(to)) { + throw Exception('No rates found for $from to $to'); + } + final assetId = _normalizeCurrency(from); final assetsResponse = await _getAssets(); @@ -103,6 +105,9 @@ class ChainflipExchangeProvider extends ExchangeProvider { try { if (amount == 0) return 0.0; + if(!_supported.contains(from) || !_supported.contains(to)) return 0.0; + + final quoteParams = { 'apiKey': _affiliateKey, 'sourceAsset': _normalizeCurrency(from), @@ -320,13 +325,13 @@ class ChainflipExchangeProvider extends ExchangeProvider { } String _normalizeCurrency(CryptoCurrency currency) { - final network = switch (currency.tag) { - 'ETH' => 'eth', - 'SOL' => 'sol', - _ => currency.title.toLowerCase() - }; + final tag = currency.tag?.toLowerCase(); + final title = currency.title.toLowerCase(); - return '${currency.title.toLowerCase()}.$network'; + // Naive assets without network tag + if (tag == null) return '$title.$title'; + + return '$title.$tag'; } CryptoCurrency? _toCurrency(String name) {