diff --git a/packages/suite/src/actions/wallet/tradingBuyActions.ts b/packages/suite/src/actions/wallet/tradingBuyActions.ts index a794342ed45..b424bb41ac5 100644 --- a/packages/suite/src/actions/wallet/tradingBuyActions.ts +++ b/packages/suite/src/actions/wallet/tradingBuyActions.ts @@ -29,7 +29,7 @@ export type TradingBuyAction = | { type: typeof TRADING_BUY.SAVE_BUY_INFO; buyInfo: BuyInfo } | { type: typeof TRADING_BUY.DISPOSE } | { type: typeof TRADING_BUY.SET_IS_FROM_REDIRECT; isFromRedirect: boolean } - | { type: typeof TRADING_BUY.SAVE_TRANSACTION_DETAIL_ID; transactionId: string } + | { type: typeof TRADING_BUY.SAVE_TRANSACTION_DETAIL_ID; transactionId: string | undefined } | { type: typeof TRADING_BUY.SAVE_QUOTE_REQUEST; request: BuyTradeQuoteRequest } | { type: typeof TRADING_BUY.VERIFY_ADDRESS; addressVerified: string | undefined } | { @@ -148,7 +148,7 @@ export const saveQuoteRequest = (request: BuyTradeQuoteRequest): TradingBuyActio request, }); -export const saveTransactionDetailId = (transactionId: string): TradingBuyAction => ({ +export const saveTransactionDetailId = (transactionId: string | undefined): TradingBuyAction => ({ type: TRADING_BUY.SAVE_TRANSACTION_DETAIL_ID, transactionId, }); diff --git a/packages/suite/src/middlewares/wallet/tradingMiddleware.ts b/packages/suite/src/middlewares/wallet/tradingMiddleware.ts index 8cca689eb60..94d656cf54b 100644 --- a/packages/suite/src/middlewares/wallet/tradingMiddleware.ts +++ b/packages/suite/src/middlewares/wallet/tradingMiddleware.ts @@ -49,8 +49,7 @@ export const tradingMiddleware = const { sellInfo, tradingAccountKey: tradingSellAccountKey } = state.wallet.trading.sell; const { router, modal } = state; const isRouteChange = action.type === ROUTER.LOCATION_CHANGE; - const isSuiteAccountChanged = - action.type === `${ACCOUNTS_MODULE_PREFIX}/updateSelectedAccount`; + const isAccountUpdated = action.type === `${ACCOUNTS_MODULE_PREFIX}/updateSelectedAccount`; if (action.type === TRADING_COMMON.LOAD_DATA) { const account = getAccountAccordingToRoute(state); @@ -147,9 +146,15 @@ export const tradingMiddleware = } // clear the account key in the Sell and Swap section when the route is not trading - if (isSuiteAccountChanged && (tradingExchangeAccountKey || tradingSellAccountKey)) { - api.dispatch(tradingSellActions.setTradingSellAccountKey(undefined)); - api.dispatch(tradingExchangeActions.setTradingExchangeAccountKey(undefined)); + if ( + isAccountUpdated && + !isTradingRoute && + (tradingExchangeAccountKey || tradingSellAccountKey) + ) { + api.dispatch(tradingSellActions.setTradingSellAccountKey(action.payload.account?.key)); + api.dispatch( + tradingExchangeActions.setTradingExchangeAccountKey(action.payload.account?.key), + ); } next(action); @@ -165,14 +170,17 @@ export const tradingMiddleware = if (isBuy) { api.dispatch(tradingCommonActions.setActiveSection('buy')); + api.dispatch(tradingBuyActions.saveTransactionDetailId(undefined)); } if (isSell) { api.dispatch(tradingCommonActions.setActiveSection('sell')); + api.dispatch(tradingSellActions.saveTransactionId(undefined)); } if (isExchange) { api.dispatch(tradingCommonActions.setActiveSection('exchange')); + api.dispatch(tradingExchangeActions.saveTransactionId(undefined)); } const wasBuy = state.router.route?.name === 'wallet-trading-buy';