@@ -49,10 +49,19 @@ export const SwapProcessingScene: React.FC<Props> = (props: Props) => {
4949 swapRequest . fromTokenId
5050 )
5151 const toDenomination = useDisplayDenom (
52- swapRequest . toWallet . currencyConfig ,
52+ // Wallet-to-wallet swaps always have a destination wallet here; fall back to
53+ // the source config only so this hook stays unconditional.
54+ ( swapRequest . toWallet ?? swapRequest . fromWallet ) . currencyConfig ,
5355 swapRequest . toTokenId
5456 )
5557
58+ // This scene only processes wallet-to-wallet swap requests, which always
59+ // carry a destination wallet (swap-to-address has its own flow).
60+ const toWallet = swapRequest . toWallet
61+ if ( toWallet == null ) {
62+ throw new Error ( 'Swap request is missing a destination wallet' )
63+ }
64+
5665 const doWork = async ( isCancelled : ( ) => boolean ) : Promise < void > => {
5766 const quotes = await account . fetchSwapQuotes (
5867 swapRequest ,
@@ -70,7 +79,7 @@ export const SwapProcessingScene: React.FC<Props> = (props: Props) => {
7079 const fromWallet = swapRequest . fromWallet
7180 const fromAddresses = await fromWallet . getAddresses ( { tokenId : null } )
7281 const fromAddress = fromAddresses [ 0 ] ?. publicAddress
73- const targetPluginId = swapRequest . toWallet . currencyInfo . pluginId
82+ const targetPluginId = toWallet . currencyInfo . pluginId
7483
7584 let matchingWalletId : string | undefined
7685 for ( const walletId of Object . keys ( account . currencyWallets ) ) {
@@ -89,8 +98,8 @@ export const SwapProcessingScene: React.FC<Props> = (props: Props) => {
8998 }
9099 }
91100
92- let finalToWalletId : string = swapRequest . toWallet . id
93- let finalToWallet = swapRequest . toWallet
101+ let finalToWalletId : string
102+ let finalToWallet : typeof toWallet
94103 let isWalletCreated = false
95104 if ( matchingWalletId == null ) {
96105 // If not found, split from the source chain wallet to the destination
@@ -165,7 +174,7 @@ export const SwapProcessingScene: React.FC<Props> = (props: Props) => {
165174 params : {
166175 fromWalletId : swapRequest . fromWallet . id ,
167176 fromTokenId : swapRequest . fromTokenId ,
168- toWalletId : swapRequest . toWallet . id ,
177+ toWalletId : toWallet . id ,
169178 toTokenId : swapRequest . toTokenId
170179 }
171180 } )
@@ -189,7 +198,7 @@ export const SwapProcessingScene: React.FC<Props> = (props: Props) => {
189198 params : {
190199 fromWalletId : swapRequest . fromWallet . id ,
191200 fromTokenId : swapRequest . fromTokenId ,
192- toWalletId : swapRequest . toWallet . id ,
201+ toWalletId : toWallet . id ,
193202 toTokenId : swapRequest . toTokenId ,
194203 errorDisplayInfo
195204 }
@@ -313,7 +322,9 @@ function processSwapQuoteError({
313322 swapRequest . fromTokenId
314323 )
315324 const toCurrencyCode = getCurrencyCode (
316- swapRequest . toWallet ,
325+ // Wallet-to-wallet swaps always have a destination wallet here; the
326+ // fallback only keeps the type honest for swap-to-address requests.
327+ swapRequest . toWallet ?? swapRequest . fromWallet ,
317328 swapRequest . toTokenId
318329 )
319330
@@ -362,10 +373,11 @@ function trackSwapError(error: unknown, swapRequest: EdgeSwapRequest): void {
362373 swapRequest . fromTokenId
363374 ) ,
364375 swapToCurrency : getCurrencyCode (
365- swapRequest . toWallet ,
376+ swapRequest . toWallet ?? swapRequest . fromWallet ,
366377 swapRequest . toTokenId
367378 ) ,
368- swapToWalletKind : swapRequest . toWallet . currencyInfo . pluginId ,
379+ swapToWalletKind : ( swapRequest . toWallet ?? swapRequest . fromWallet )
380+ . currencyInfo . pluginId ,
369381 swapDirectionType : swapRequest . quoteFor
370382 } )
371383 // Unsearchable context data:
0 commit comments