fix: Swap external send QR using trade currency instead of selected wallet (#3068)

This commit is contained in:
David Adegoke
2026-03-13 01:32:37 +01:00
committed by GitHub
parent 89e07fbba6
commit 8f7819be82
2 changed files with 23 additions and 11 deletions
+9
View File
@@ -231,6 +231,15 @@ class TokenUtilities {
return null;
}
static Erc20Token? findErc20TokenForSwap(CryptoCurrency currency) {
if (currency is Erc20Token) return currency;
for (final token in loadDefaultEvmTokensForSwap()) {
if (_matchesCurrency(token, currency)) return token;
}
return null;
}
static bool isNativeToken(CryptoCurrency currency) {
final title = currency.title.toLowerCase();
final tag = currency.tag?.toLowerCase();
@@ -478,7 +478,11 @@ abstract class ExchangeTradeViewModelBase with Store {
return null;
}
switch (wallet.type) {
// Using trade currency here so the external-send QR encodes the correct scheme
final uriWalletType =
cryptoCurrencyOrTokenToWalletType(fromCurrency) ?? wallet.type;
switch (uriWalletType) {
case WalletType.bitcoin:
return BitcoinURI(address: inputAddress, amount: amount);
case WalletType.bitcoinCash:
@@ -524,17 +528,16 @@ abstract class ExchangeTradeViewModelBase with Store {
contractAddress: null,
);
} else {
if (isEVMCompatibleChain(wallet.type)) {
final erc20Token = TokenUtilities.findErc20Token(currency, wallet);
final erc20Token = TokenUtilities.findErc20Token(currency, wallet) ??
TokenUtilities.findErc20TokenForSwap(currency);
if (erc20Token != null) {
return ERC681URI(
chainId: chainId,
address: address,
amount: amount,
contractAddress: erc20Token.contractAddress,
);
}
if (erc20Token != null) {
return ERC681URI(
chainId: chainId,
address: address,
amount: amount,
contractAddress: erc20Token.contractAddress,
);
}
return null;
}