mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
add validation to ensure only supported currencies (#2758)
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user