@@ -49,10 +49,22 @@ export const SwapProcessingScene: React.FC<Props> = (props: Props) => {
4949 swapRequest . fromTokenId
5050 )
5151 const toDenomination = useDisplayDenom (
52- swapRequest . toWallet . currencyConfig ,
53- swapRequest . toTokenId
52+ // Wallet-to-wallet swaps always have a destination wallet here; fall back to
53+ // the source config only so this hook stays unconditional. Pair that
54+ // fallback with a null tokenId so the lookup never asks the source config
55+ // for a token it does not have (the result is unused once the guard below
56+ // throws on a missing destination wallet).
57+ ( swapRequest . toWallet ?? swapRequest . fromWallet ) . currencyConfig ,
58+ swapRequest . toWallet != null ? swapRequest . toTokenId : null
5459 )
5560
61+ // This scene only processes wallet-to-wallet swap requests, which always
62+ // carry a destination wallet (swap-to-address has its own flow).
63+ const toWallet = swapRequest . toWallet
64+ if ( toWallet == null ) {
65+ throw new Error ( 'Swap request is missing a destination wallet' )
66+ }
67+
5668 const doWork = async ( isCancelled : ( ) => boolean ) : Promise < void > => {
5769 const quotes = await account . fetchSwapQuotes (
5870 swapRequest ,
@@ -70,7 +82,7 @@ export const SwapProcessingScene: React.FC<Props> = (props: Props) => {
7082 const fromWallet = swapRequest . fromWallet
7183 const fromAddresses = await fromWallet . getAddresses ( { tokenId : null } )
7284 const fromAddress = fromAddresses [ 0 ] ?. publicAddress
73- const targetPluginId = swapRequest . toWallet . currencyInfo . pluginId
85+ const targetPluginId = toWallet . currencyInfo . pluginId
7486
7587 let matchingWalletId : string | undefined
7688 for ( const walletId of Object . keys ( account . currencyWallets ) ) {
@@ -89,8 +101,8 @@ export const SwapProcessingScene: React.FC<Props> = (props: Props) => {
89101 }
90102 }
91103
92- let finalToWalletId : string = swapRequest . toWallet . id
93- let finalToWallet = swapRequest . toWallet
104+ let finalToWalletId : string
105+ let finalToWallet : typeof toWallet
94106 let isWalletCreated = false
95107 if ( matchingWalletId == null ) {
96108 // If not found, split from the source chain wallet to the destination
@@ -165,7 +177,7 @@ export const SwapProcessingScene: React.FC<Props> = (props: Props) => {
165177 params : {
166178 fromWalletId : swapRequest . fromWallet . id ,
167179 fromTokenId : swapRequest . fromTokenId ,
168- toWalletId : swapRequest . toWallet . id ,
180+ toWalletId : toWallet . id ,
169181 toTokenId : swapRequest . toTokenId
170182 }
171183 } )
@@ -189,7 +201,7 @@ export const SwapProcessingScene: React.FC<Props> = (props: Props) => {
189201 params : {
190202 fromWalletId : swapRequest . fromWallet . id ,
191203 fromTokenId : swapRequest . fromTokenId ,
192- toWalletId : swapRequest . toWallet . id ,
204+ toWalletId : toWallet . id ,
193205 toTokenId : swapRequest . toTokenId ,
194206 errorDisplayInfo
195207 }
@@ -313,7 +325,9 @@ function processSwapQuoteError({
313325 swapRequest . fromTokenId
314326 )
315327 const toCurrencyCode = getCurrencyCode (
316- swapRequest . toWallet ,
328+ // Wallet-to-wallet swaps always have a destination wallet here; the
329+ // fallback only keeps the type honest for swap-to-address requests.
330+ swapRequest . toWallet ?? swapRequest . fromWallet ,
317331 swapRequest . toTokenId
318332 )
319333
@@ -362,10 +376,11 @@ function trackSwapError(error: unknown, swapRequest: EdgeSwapRequest): void {
362376 swapRequest . fromTokenId
363377 ) ,
364378 swapToCurrency : getCurrencyCode (
365- swapRequest . toWallet ,
379+ swapRequest . toWallet ?? swapRequest . fromWallet ,
366380 swapRequest . toTokenId
367381 ) ,
368- swapToWalletKind : swapRequest . toWallet . currencyInfo . pluginId ,
382+ swapToWalletKind : ( swapRequest . toWallet ?? swapRequest . fromWallet )
383+ . currencyInfo . pluginId ,
369384 swapDirectionType : swapRequest . quoteFor
370385 } )
371386 // Unsearchable context data:
0 commit comments