mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
minor fix [skip ci]
This commit is contained in:
@@ -271,15 +271,17 @@ class NearIntentsExchangeProvider extends ExchangeProvider {
|
||||
throw Exception('Failed to parse to currency from assetId: $toAssetId');
|
||||
}
|
||||
|
||||
final from = CryptoCurrency.safeParseCurrencyFromString(fromCurrency.$1, tag: fromCurrency.$2);
|
||||
final to = CryptoCurrency.safeParseCurrencyFromString(toCurrency.$1, tag: toCurrency.$2);
|
||||
final from = CryptoCurrency.safeParseCurrencyFromString(fromCurrency.$1,
|
||||
tag: fromCurrency.$2);
|
||||
final to = CryptoCurrency.safeParseCurrencyFromString(toCurrency.$1,
|
||||
tag: toCurrency.$2);
|
||||
|
||||
|
||||
final trade = Trade(
|
||||
id: depositAddress,
|
||||
// Using deposit address as trade ID
|
||||
from: request.fromCurrency,
|
||||
to: request.fromCurrency,
|
||||
to: request.toCurrency,
|
||||
provider: description,
|
||||
providerName: title,
|
||||
state: TradeState.created,
|
||||
|
||||
@@ -214,11 +214,11 @@ abstract class ExchangeTradeViewModelBase with Store {
|
||||
final canSendError = checkIfCanSend(trade, wallet);
|
||||
|
||||
if (canSendError != null) {
|
||||
_logCanSendError(trade, wallet, canSendError);
|
||||
sendViewModel.state = FailureState(canSendError);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
final selected = trade.from;
|
||||
if (selected == null) {
|
||||
printV('No selectable currency for trade ${trade.id}');
|
||||
@@ -354,62 +354,55 @@ abstract class ExchangeTradeViewModelBase with Store {
|
||||
}
|
||||
|
||||
String? checkIfCanSend(Trade? trade, WalletBase wallet) {
|
||||
try {
|
||||
if (trade == null) return 'Trade is null';
|
||||
|
||||
if (trade == null) throw Exception('Trade is null');
|
||||
final tradeFrom = trade.from;
|
||||
if (tradeFrom == null) return 'Trade from currency is null';
|
||||
|
||||
final tradeFrom = trade.from;
|
||||
if (tradeFrom == null) throw Exception('Trade from currency is null');
|
||||
bool _sameCurrency(CryptoCurrency a, CryptoCurrency b) => a.titleAndTagEqual(b);
|
||||
|
||||
bool _sameCurrency(CryptoCurrency a, CryptoCurrency b) => a.titleAndTagEqual(b);
|
||||
|
||||
bool _isTokenBelongingToWallet(CryptoCurrency cur) {
|
||||
final chainTag = cur.tag ?? cur.title;
|
||||
return wallet.currency == cur &&
|
||||
tradeFrom.tag?.toUpperCase() == chainTag.toUpperCase();
|
||||
}
|
||||
|
||||
final canSend = _sameCurrency(tradeFrom, wallet.currency) ||
|
||||
(_sameCurrency(tradeFrom, CryptoCurrency.btcln) &&
|
||||
wallet.currency == CryptoCurrency.btc) ||
|
||||
trade.provider == ExchangeProviderDescription.xmrto ||
|
||||
_isTokenBelongingToWallet(CryptoCurrency.eth) ||
|
||||
_isTokenBelongingToWallet(CryptoCurrency.maticpoly) ||
|
||||
_isTokenBelongingToWallet(CryptoCurrency.baseEth) ||
|
||||
_isTokenBelongingToWallet(CryptoCurrency.arbEth) ||
|
||||
_isTokenBelongingToWallet(CryptoCurrency.trx) ||
|
||||
_isTokenBelongingToWallet(CryptoCurrency.sol) ||
|
||||
_isTokenBelongingToWallet(CryptoCurrency.bnb);
|
||||
|
||||
if (!canSend) {
|
||||
throw Exception(
|
||||
'Wallet currency ${wallet.currency.title} does not match trade from currency ${tradeFrom.title} or is not a supported token for this wallet.',
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (e, s) {
|
||||
final trade = tradesStore.trade;
|
||||
|
||||
ExchangeProviderLogger.logError(
|
||||
provider: trade?.provider,
|
||||
function: '_checkIfCanSend',
|
||||
error: e,
|
||||
stackTrace: s,
|
||||
requestData: {
|
||||
'tradeId': trade?.id,
|
||||
'tradeFrom': trade?.from?.title,
|
||||
'tradeFromTag': trade?.from?.tag,
|
||||
'tradeTo': trade?.to?.title,
|
||||
'tradeToTag': trade?.to?.tag,
|
||||
'walletName': wallet.name,
|
||||
'walletCurrency': wallet.currency.title,
|
||||
'walletCurrencyTag': wallet.currency.tag,
|
||||
},
|
||||
);
|
||||
|
||||
return e.toString();
|
||||
bool _isTokenBelongingToWallet(CryptoCurrency cur) {
|
||||
final chainTag = cur.tag ?? cur.title;
|
||||
return wallet.currency == cur &&
|
||||
(tradeFrom.tag?.toUpperCase() == chainTag.toUpperCase() ||
|
||||
tradeFrom.title.toUpperCase() == chainTag.toUpperCase());
|
||||
}
|
||||
|
||||
final canSend = _sameCurrency(tradeFrom, wallet.currency) ||
|
||||
(_sameCurrency(tradeFrom, CryptoCurrency.btcln) &&
|
||||
wallet.currency == CryptoCurrency.btc) ||
|
||||
trade.provider == ExchangeProviderDescription.xmrto ||
|
||||
_isTokenBelongingToWallet(CryptoCurrency.eth) ||
|
||||
_isTokenBelongingToWallet(CryptoCurrency.maticpoly) ||
|
||||
_isTokenBelongingToWallet(CryptoCurrency.baseEth) ||
|
||||
_isTokenBelongingToWallet(CryptoCurrency.arbEth) ||
|
||||
_isTokenBelongingToWallet(CryptoCurrency.trx) ||
|
||||
_isTokenBelongingToWallet(CryptoCurrency.sol) ||
|
||||
_isTokenBelongingToWallet(CryptoCurrency.bnb);
|
||||
|
||||
if (!canSend) {
|
||||
return 'Wallet currency ${wallet.currency.title} does not match trade from currency ${tradeFrom.title} or is not a supported token for this wallet.';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
void _logCanSendError(Trade? trade, WalletBase wallet, String error) {
|
||||
ExchangeProviderLogger.logError(
|
||||
provider: trade?.provider,
|
||||
function: '_checkIfCanSend',
|
||||
error: error,
|
||||
requestData: {
|
||||
'tradeId': trade?.id,
|
||||
'tradeFrom': trade?.from?.title,
|
||||
'tradeFromTag': trade?.from?.tag,
|
||||
'tradeTo': trade?.to?.title,
|
||||
'tradeToTag': trade?.to?.tag,
|
||||
'walletName': wallet.name,
|
||||
'walletCurrency': wallet.currency.title,
|
||||
'walletCurrencyTag': wallet.currency.tag,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
static bool _checkIfSwapsXYZCanSendFromExternal(Trade trade, WalletBase wallet) {
|
||||
|
||||
Reference in New Issue
Block a user