mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
Refactor jupiter supported currency checks for swaps (#2886)
This commit is contained in:
@@ -18,13 +18,9 @@ import 'package:cw_core/utils/proxy_wrapper.dart';
|
||||
class JupiterExchangeProvider extends ExchangeProvider {
|
||||
JupiterExchangeProvider();
|
||||
|
||||
// Jupiter only supports Solana tokens
|
||||
static const List<CryptoCurrency> _notSupported = [];
|
||||
|
||||
static final List<CryptoCurrency> _supportedCurrencies = CryptoCurrency.all
|
||||
.where((c) => c.tag == 'SOL' || c == CryptoCurrency.sol)
|
||||
.where((c) => !_notSupported.contains(c))
|
||||
.toList();
|
||||
// Jupiter only supports Solana native SOL and Solana tokens
|
||||
bool _isSolanaCurrency(CryptoCurrency currency) =>
|
||||
currency == CryptoCurrency.sol || currency.tag == 'SOL';
|
||||
|
||||
static const _baseUrl = 'api.jup.ag';
|
||||
static const _orderPath = '/ultra/v1/order';
|
||||
@@ -88,7 +84,7 @@ class JupiterExchangeProvider extends ExchangeProvider {
|
||||
// - errorCode 3: Minimum amount for gasless
|
||||
|
||||
// only return null for supported currencies
|
||||
if (_supportedCurrencies.contains(from) && _supportedCurrencies.contains(to)) {
|
||||
if (_isSolanaCurrency(from) && _isSolanaCurrency(to)) {
|
||||
return Limits(min: null, max: null);
|
||||
} else {
|
||||
throw Exception('not supported');
|
||||
@@ -136,7 +132,7 @@ class JupiterExchangeProvider extends ExchangeProvider {
|
||||
}) async {
|
||||
try {
|
||||
// must support both
|
||||
if (!_supportedCurrencies.contains(from) || !_supportedCurrencies.contains(to)) {
|
||||
if (!_isSolanaCurrency(from) || !_isSolanaCurrency(to)) {
|
||||
return 0.0;
|
||||
}
|
||||
final inputMint = _getTokenMint(from);
|
||||
@@ -227,9 +223,9 @@ class JupiterExchangeProvider extends ExchangeProvider {
|
||||
}) async {
|
||||
try {
|
||||
// must support both
|
||||
if (!_supportedCurrencies.contains(request.fromCurrency) ||
|
||||
!_supportedCurrencies.contains(request.toCurrency)) {
|
||||
throw "not supported currencies";
|
||||
if (!_isSolanaCurrency(request.fromCurrency) ||
|
||||
!_isSolanaCurrency(request.toCurrency)) {
|
||||
throw 'not supported currencies';
|
||||
}
|
||||
|
||||
final inputMint = _getTokenMint(request.fromCurrency);
|
||||
|
||||
Reference in New Issue
Block a user