diff --git a/packages/suite/src/actions/wallet/constants/tradingCommonConstants.ts b/packages/suite/src/actions/wallet/constants/tradingCommonConstants.ts index 08a75c5ef2a..81e097dd759 100644 --- a/packages/suite/src/actions/wallet/constants/tradingCommonConstants.ts +++ b/packages/suite/src/actions/wallet/constants/tradingCommonConstants.ts @@ -3,7 +3,7 @@ export const SAVE_TRADE = '@trading-common/save_trade'; export const LOAD_DATA = '@trading-common/load_data'; export const SET_LOADING = '@trading-common/set_loading'; export const SET_MODAL_CRYPTO_CURRENCY = '@trading-common/set_modal_crypto_currency'; -export const SET_MODAL_ACCOUNT = '@trading-common/set_modal_account'; +export const SET_MODAL_ACCOUNT_KEY = '@trading-common/set_modal_account_key'; export const SET_TRADING_ACTIVE_SECTION = '@trading-common/set_trading_active_section'; export const SET_TRADING_FROM_PREFILLED_CRYPTO_ID = '@trading-common/set_trading_from_prefilled_crypto_id'; diff --git a/packages/suite/src/actions/wallet/trading/tradingCommonActions.ts b/packages/suite/src/actions/wallet/trading/tradingCommonActions.ts index 6a777e86c01..85c21657196 100644 --- a/packages/suite/src/actions/wallet/trading/tradingCommonActions.ts +++ b/packages/suite/src/actions/wallet/trading/tradingCommonActions.ts @@ -7,7 +7,7 @@ import { selectSelectedDevice, toggleRememberDevice, } from '@suite-common/wallet-core'; -import { AddressDisplayOptions, Output } from '@suite-common/wallet-types/src'; +import { AccountKey, AddressDisplayOptions, Output } from '@suite-common/wallet-types/src'; import { amountToSmallestUnit, formatAmount, @@ -45,8 +45,8 @@ export type TradingCommonAction = modalCryptoId: CryptoId | undefined; } | { - type: typeof TRADING_COMMON.SET_MODAL_ACCOUNT; - modalAccount: Account | undefined; + type: typeof TRADING_COMMON.SET_MODAL_ACCOUNT_KEY; + modalAccountKey: AccountKey | undefined; } | { type: typeof TRADING_COMMON.SET_TRADING_ACTIVE_SECTION; @@ -63,13 +63,15 @@ type FormState = { }; /** - * Set modalAccount to retrieve the correct account in modals. - * Used in ConfirmAddressModal and TransactionReviewModalContent through selectAccountIncludingChosenInTrading. + * Set modalAccountKey to retrieve the correct account key in modals. + * Used in ConfirmAddressModal and TransactionReviewModalContent through selectAccountKeyIncludingChosenInTrading. * Unset in middleware after modal is closed. */ -export const setTradingModalAccount = (modalAccount: Account | undefined): TradingCommonAction => ({ - type: TRADING_COMMON.SET_MODAL_ACCOUNT, - modalAccount, +export const setTradingModalAccountKey = ( + modalAccountKey: AccountKey | undefined, +): TradingCommonAction => ({ + type: TRADING_COMMON.SET_MODAL_ACCOUNT_KEY, + modalAccountKey, }); export const setActiveSection = (activeSection: TradingType): TradingCommonAction => ({ @@ -92,7 +94,7 @@ export const verifyAddress = path = path ?? accountAddress.path; if (!path || !address) return; - dispatch(setTradingModalAccount(account)); + dispatch(setTradingModalAccountKey(account.key)); const addressDisplayType = selectAddressDisplayType(getState()); diff --git a/packages/suite/src/hooks/wallet/trading/form/useTradingExchangeForm.ts b/packages/suite/src/hooks/wallet/trading/form/useTradingExchangeForm.ts index 092b56fb089..f26126c8114 100644 --- a/packages/suite/src/hooks/wallet/trading/form/useTradingExchangeForm.ts +++ b/packages/suite/src/hooks/wallet/trading/form/useTradingExchangeForm.ts @@ -525,7 +525,7 @@ export const useTradingExchangeForm = ({ }; const sendTransaction = async () => { - dispatch(tradingCommonActions.setTradingModalAccount(account)); + dispatch(tradingCommonActions.setTradingModalAccountKey(account.key)); if (selectedQuote?.isDex) { sendDexTransaction(); diff --git a/packages/suite/src/hooks/wallet/trading/form/useTradingSellForm.ts b/packages/suite/src/hooks/wallet/trading/form/useTradingSellForm.ts index 3f964b6a42a..73bd306dc78 100644 --- a/packages/suite/src/hooks/wallet/trading/form/useTradingSellForm.ts +++ b/packages/suite/src/hooks/wallet/trading/form/useTradingSellForm.ts @@ -481,7 +481,7 @@ export const useTradingSellForm = ({ }; const sendTransaction = async () => { - dispatch(tradingCommonActions.setTradingModalAccount(account)); + dispatch(tradingCommonActions.setTradingModalAccountKey(account.key)); const selectedTrade = trade?.data || selectedQuote; // destinationAddress may be set by useTradingWatchTrade hook to the trade object diff --git a/packages/suite/src/middlewares/wallet/__tests__/tradingMiddleware.test.ts b/packages/suite/src/middlewares/wallet/__tests__/tradingMiddleware.test.ts index c42025a019b..216d2651200 100644 --- a/packages/suite/src/middlewares/wallet/__tests__/tradingMiddleware.test.ts +++ b/packages/suite/src/middlewares/wallet/__tests__/tradingMiddleware.test.ts @@ -229,12 +229,12 @@ describe('tradingMiddleware', () => { expect(setInvityServersEnvironmentMock).toHaveBeenCalledTimes(0); }); - it('Test of cleaning modalAccount property after receive modal is closed', () => { + it('Test of cleaning modalAccountKey property after receive modal is closed', () => { const store = initStore( getInitialState({ trading: { ...initialState, - modalAccount: accounts[0], + modalAccountKey: accounts[0].key, lastLoadedTimestamp: Date.now(), }, }), @@ -260,15 +260,15 @@ describe('tradingMiddleware', () => { type: UI.CLOSE_UI_WINDOW, }); - expect(store.getState().wallet.trading.modalAccount).toEqual(undefined); + expect(store.getState().wallet.trading.modalAccountKey).toEqual(undefined); }); - it('Test of cleaning modalAccount property after send modal is closed', () => { + it('Test of cleaning modalAccountKey property after send modal is closed', () => { const store = initStore( getInitialState({ trading: { ...initialState, - modalAccount: accounts[0], + modalAccountKey: accounts[0].key, lastLoadedTimestamp: Date.now(), }, }), @@ -294,7 +294,7 @@ describe('tradingMiddleware', () => { type: MODAL.CLOSE, }); - expect(store.getState().wallet.trading.modalAccount).toEqual(undefined); + expect(store.getState().wallet.trading.modalAccountKey).toEqual(undefined); }); it('Test of setting activeSection after changing route', () => { diff --git a/packages/suite/src/middlewares/wallet/tradingMiddleware.ts b/packages/suite/src/middlewares/wallet/tradingMiddleware.ts index 84fd3ac5ecd..4eb3485cb04 100644 --- a/packages/suite/src/middlewares/wallet/tradingMiddleware.ts +++ b/packages/suite/src/middlewares/wallet/tradingMiddleware.ts @@ -138,7 +138,7 @@ export const tradingMiddleware = // clear modal account on close button requests // it is necessary to clear the state because it could affect the next modal state if (isTradingRoute && (isReceiveModal || isSendModal)) { - api.dispatch(tradingCommonActions.setTradingModalAccount(undefined)); + api.dispatch(tradingCommonActions.setTradingModalAccountKey(undefined)); } next(action); diff --git a/packages/suite/src/reducers/wallet/__tests__/tradingReducer.test.ts b/packages/suite/src/reducers/wallet/__tests__/tradingReducer.test.ts index 738db977c4e..693b0284969 100644 --- a/packages/suite/src/reducers/wallet/__tests__/tradingReducer.test.ts +++ b/packages/suite/src/reducers/wallet/__tests__/tradingReducer.test.ts @@ -49,22 +49,22 @@ describe('settings reducer', () => { it('TRADING_COMMON.SET_MODAL_ACCOUNT', () => { expect( tradingReducer(undefined, { - type: TRADING_COMMON.SET_MODAL_ACCOUNT, - modalAccount: accounts[0], + type: TRADING_COMMON.SET_MODAL_ACCOUNT_KEY, + modalAccountKey: accounts[0].key, }), ).toEqual({ ...initialState, - modalAccount: accounts[0], + modalAccountKey: accounts[0].key, }); expect( tradingReducer(undefined, { - type: TRADING_COMMON.SET_MODAL_ACCOUNT, - modalAccount: undefined, + type: TRADING_COMMON.SET_MODAL_ACCOUNT_KEY, + modalAccountKey: undefined, }), ).toEqual({ ...initialState, - modalAccount: undefined, + modalAccountKey: undefined, }); }); diff --git a/packages/suite/src/reducers/wallet/selectedAccountReducer.ts b/packages/suite/src/reducers/wallet/selectedAccountReducer.ts index 72cc90176e0..188e4b708f5 100644 --- a/packages/suite/src/reducers/wallet/selectedAccountReducer.ts +++ b/packages/suite/src/reducers/wallet/selectedAccountReducer.ts @@ -1,4 +1,4 @@ -import { accountsActions } from '@suite-common/wallet-core'; +import { AccountsRootState, accountsActions, selectAccountByKey } from '@suite-common/wallet-core'; import type { SelectedAccountStatus } from '@suite-common/wallet-types'; import { State as TradingState } from 'src/reducers/wallet/tradingReducer'; @@ -10,7 +10,7 @@ export type SelectedAccountRootState = { wallet: { selectedAccount: SelectedAccountStatus; }; -}; +} & AccountsRootState; export type SelectedAccountRootStateWithTrading = SelectedAccountRootState & { wallet: { @@ -54,10 +54,10 @@ export const selectIsSelectedAccountLoaded = (state: SelectedAccountRootState) = export const selectAccountIncludingChosenInTrading = ( state: SelectedAccountRootStateWithTrading, ) => { - const { modalAccount } = state.wallet.trading; + const { modalAccountKey } = state.wallet.trading; - if (modalAccount) { - return modalAccount; + if (modalAccountKey) { + return selectAccountByKey(state, modalAccountKey) ?? undefined; } const selectedAccount = selectSelectedAccount(state); diff --git a/packages/suite/src/reducers/wallet/tradingReducer.ts b/packages/suite/src/reducers/wallet/tradingReducer.ts index 74d5c99f21f..5ba7cb0dd74 100644 --- a/packages/suite/src/reducers/wallet/tradingReducer.ts +++ b/packages/suite/src/reducers/wallet/tradingReducer.ts @@ -94,7 +94,7 @@ export interface State { composedTransactionInfo: ComposedTransactionInfo; trades: Trade[]; modalCryptoId: CryptoId | undefined; - modalAccount: Account | undefined; + modalAccountKey: AccountKey | undefined; isLoading: boolean; lastLoadedTimestamp: number; activeSection?: TradingType; @@ -144,7 +144,7 @@ export const initialState: State = { composedTransactionInfo: {}, trades: [], isLoading: false, - modalAccount: undefined, + modalAccountKey: undefined, modalCryptoId: undefined, lastLoadedTimestamp: 0, activeSection: 'buy', @@ -265,8 +265,8 @@ export const tradingReducer = ( draft.isLoading = action.isLoading; draft.lastLoadedTimestamp = action.lastLoadedTimestamp; break; - case TRADING_COMMON.SET_MODAL_ACCOUNT: - draft.modalAccount = action.modalAccount; + case TRADING_COMMON.SET_MODAL_ACCOUNT_KEY: + draft.modalAccountKey = action.modalAccountKey; break; case TRADING_COMMON.SET_MODAL_CRYPTO_CURRENCY: draft.modalCryptoId = action.modalCryptoId;