Skip to content

Commit

Permalink
fix(trading): stuck account and trade state
Browse files Browse the repository at this point in the history
  • Loading branch information
adderpositive authored and tomasklim committed Feb 4, 2025
1 parent dd82975 commit 59d8906
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/suite/src/actions/wallet/tradingBuyActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
| {
Expand Down Expand Up @@ -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,
});
Expand Down
18 changes: 13 additions & 5 deletions packages/suite/src/middlewares/wallet/tradingMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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';
Expand Down

0 comments on commit 59d8906

Please sign in to comment.