From 8f7819be8205728dcc443bc1249ae895b29621d0 Mon Sep 17 00:00:00 2001 From: David Adegoke <64401859+Blazebrain@users.noreply.github.com> Date: Fri, 13 Mar 2026 01:32:37 +0100 Subject: [PATCH] fix: Swap external send QR using trade currency instead of selected wallet (#3068) --- lib/utils/token_utilities.dart | 9 +++++++ .../exchange/exchange_trade_view_model.dart | 25 +++++++++++-------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/utils/token_utilities.dart b/lib/utils/token_utilities.dart index d38816fe7..32ef710fd 100644 --- a/lib/utils/token_utilities.dart +++ b/lib/utils/token_utilities.dart @@ -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(); diff --git a/lib/view_model/exchange/exchange_trade_view_model.dart b/lib/view_model/exchange/exchange_trade_view_model.dart index 04180e7d7..e85d493b2 100644 --- a/lib/view_model/exchange/exchange_trade_view_model.dart +++ b/lib/view_model/exchange/exchange_trade_view_model.dart @@ -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; }