add validation to ensure only supported currencies (#2758)
Serhii committed
Dec 25, 2025 at 10:37 UTC
9aa7ac2b61fa5fcde0e840364fa5cdaab3d5a643
1 file changed
+27
-22
lib/exchange/provider/chainflip_exchange_provider.dart
+27
-22
@@ -19,22 +19,19 @@ class ChainflipExchangeProvider extends ExchangeProvider {
19
ChainflipExchangeProvider({required this.tradesStore})
20
: super(pairList: supportedPairs(_notSupported));
21
22
- static final List<CryptoCurrency> _notSupported = [
23
- ...(CryptoCurrency.all
24
- .where((element) => ![
25
- CryptoCurrency.btc,
26
- CryptoCurrency.eth,
27
- CryptoCurrency.usdc,
28
- CryptoCurrency.usdterc20,
29
- CryptoCurrency.flip,
30
- CryptoCurrency.sol,
31
- CryptoCurrency.usdcsol,
32
- // TODO: Add CryptoCurrency.etharb
33
- // TODO: Add CryptoCurrency.usdcarb
34
- // TODO: Add CryptoCurrency.dot
35
- ].contains(element))
36
- .toList())
37
- ];
22
+ static final List<CryptoCurrency> _notSupported = [];
23
+ static final List<CryptoCurrency> _supported = [
24
+ CryptoCurrency.btc,
25
+ CryptoCurrency.eth,
26
+ CryptoCurrency.usdc,
27
+ CryptoCurrency.usdterc20,
28
+ CryptoCurrency.flip,
29
+ CryptoCurrency.sol,
30
+ CryptoCurrency.usdcsol,
31
+ CryptoCurrency.arbEth,
32
+ // TODO: Add CryptoCurrency.usdcarb
33
+ // TODO: Add CryptoCurrency.dot
34
+ ];
35
36
static const _baseURL = 'chainflip-broker.io';
37
static const _assetsPath = '/assets';
@@ -72,6 +69,11 @@ class ChainflipExchangeProvider extends ExchangeProvider {
69
required bool isFixedRateMode}) async {
70
71
try {
72
+
73
+ if(!_supported.contains(from) || !_supported.contains(to)) {
74
+ throw Exception('No rates found for $from to $to');
75
+ }
76
+
77
final assetId = _normalizeCurrency(from);
78
79
final assetsResponse = await _getAssets();
@@ -103,6 +105,9 @@ class ChainflipExchangeProvider extends ExchangeProvider {
105
try {
106
if (amount == 0) return 0.0;
107
108
+ if(!_supported.contains(from) || !_supported.contains(to)) return 0.0;
109
+
110
+
111
final quoteParams = {
112
'apiKey': _affiliateKey,
113
'sourceAsset': _normalizeCurrency(from),
@@ -320,13 +325,13 @@ class ChainflipExchangeProvider extends ExchangeProvider {
325
}
326
327
String _normalizeCurrency(CryptoCurrency currency) {
323
- final network = switch (currency.tag) {
324
- 'ETH' => 'eth',
325
- 'SOL' => 'sol',
326
- _ => currency.title.toLowerCase()
327
- };
328
+ final tag = currency.tag?.toLowerCase();
329
+ final title = currency.title.toLowerCase();
330
+
331
+ // Naive assets without network tag
332
+ if (tag == null) return '$title.$title';
333
329
- return '${currency.title.toLowerCase()}.$network';
334
+ return '$title.$tag';
335
}
336
337
CryptoCurrency? _toCurrency(String name) {