diff --git a/suite-common/trading/src/middlewares/tradingMiddleware.ts b/suite-common/trading/src/middlewares/tradingMiddleware.ts index e9f4ba6fc1f..051d7ab507e 100644 --- a/suite-common/trading/src/middlewares/tradingMiddleware.ts +++ b/suite-common/trading/src/middlewares/tradingMiddleware.ts @@ -6,9 +6,6 @@ import { INVITY_API_RELOAD_DATA_AFTER_MS } from '../constants'; import { invityAPI } from '../invityAPI'; import { TradingRootState, selectState } from '../selectors/tradingSelectors'; import { buyThunks } from '../thunks/buyThunks'; -import { getTradeTypeByRoute } from '../utils'; - -const LOCATION_CHANGE = '@router/location-change'; /** * In the Sell and Swap section an account can be changed by a user in the select @@ -25,7 +22,6 @@ export const getAccountAccordingToRoute = (state: TradingRootState) => { export const tradingMiddleware = createMiddleware(async (action, { dispatch, next, getState }) => { const state = selectState(getState()); const { isLoading, lastLoadedTimestamp } = state.wallet.trading; - const isRouteChange = action.type === LOCATION_CHANGE; if (action.type === tradingActions.LOAD_DATA) { const account = getAccountAccordingToRoute(state); @@ -48,11 +44,6 @@ export const tradingMiddleware = createMiddleware(async (action, { dispatch, nex invityAPI.setInvityServersEnvironment(invityServerEnvironment); } - const tradeType = getTradeTypeByRoute(state.router.route?.name); - if (tradeType) { - dispatch(tradingActions.tradingActions.setTradingActiveSection(tradeType)); - } - invityAPI.createInvityAPIKey(account.descriptor); if (isDifferentAccount || !platforms || !coins) { @@ -71,35 +62,5 @@ export const tradingMiddleware = createMiddleware(async (action, { dispatch, nex } } - next(action); - - // get the new state after the action has been processed - const newState = selectState(getState()); - - // TODO: native route change control? - if (isRouteChange) { - const routeName = newState.router.route?.name; - const isBuy = routeName === 'wallet-trading-buy'; - const isSell = routeName === 'wallet-trading-sell'; - const isExchange = routeName === 'wallet-trading-exchange'; - - if (isBuy) { - dispatch(tradingActions.tradingActions.setTradingActiveSection('buy')); - } - - const wasBuy = state.router.route?.name === 'wallet-trading-buy'; - const wasSell = state.router.route?.name === 'wallet-trading-sell'; - const isBuyToSell = wasBuy && isSell; - const isSellToBuy = wasSell && isBuy; - - const cleanupPrefilledFromCryptoId = - !!newState.wallet.trading.prefilledFromCryptoId && - ((!isSell && !isExchange && !isBuy) || isBuyToSell || isSellToBuy); - - if (cleanupPrefilledFromCryptoId) { - dispatch(tradingActions.tradingActions.setTradingFromPrefilledCryptoId(undefined)); - } - } - - return action; + return next(action); });