add validation to ensure only supported currencies (#2758)

This commit is contained in:
Serhii
2025-12-25 09:37:38 +01:00
committed by GitHub
parent f5754ed2d3
commit 9aa7ac2b61
@@ -19,22 +19,19 @@ class ChainflipExchangeProvider extends ExchangeProvider {
ChainflipExchangeProvider({required this.tradesStore})
: super(pairList: supportedPairs(_notSupported));
static final List<CryptoCurrency> _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<CryptoCurrency> _notSupported = [];
static final List<CryptoCurrency> _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) {