From b134fe1817e7988eaac9439713098e95553f22d7 Mon Sep 17 00:00:00 2001 From: Tyler Date: Fri, 20 Dec 2024 16:21:13 -0500 Subject: [PATCH] sync-local-address --- src/abacus-ts/socketSelectors.ts | 6 +++--- src/hooks/useAccounts.tsx | 6 +++++- src/state/wallet.ts | 7 +++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/abacus-ts/socketSelectors.ts b/src/abacus-ts/socketSelectors.ts index 36e72193a..36219420f 100644 --- a/src/abacus-ts/socketSelectors.ts +++ b/src/abacus-ts/socketSelectors.ts @@ -3,7 +3,7 @@ import { ENVIRONMENT_CONFIG_MAP } from '@/constants/networks'; import { EndpointsConfig } from '@/hooks/useEndpointsConfig'; import { type RootState } from '@/state/_store'; -import { getUserSubaccountNumber, getUserWalletAddress } from '@/state/accountSelectors'; +import { getUserSubaccountNumber } from '@/state/accountSelectors'; import { getSelectedNetwork } from '@/state/appSelectors'; import { createAppSelector } from '@/state/appTypes'; @@ -19,8 +19,8 @@ export const selectIndexerUrl = createAppSelector([getSelectedNetwork], (network }); export const selectParentSubaccountInfo = createAppSelector( - [getUserWalletAddress, getUserSubaccountNumber], - (wallet, subaccount) => ({ wallet, subaccount }) + [(state) => state.wallet.localWallet?.address, getUserSubaccountNumber], + (wallet, subaccount) => ({ wallet, subaccount: 0 }) // TODO DO NOT HARD CODE THIS ); export const selectIndexerReady = createAppSelector( diff --git a/src/hooks/useAccounts.tsx b/src/hooks/useAccounts.tsx index 2e2a571f5..6a121923c 100644 --- a/src/hooks/useAccounts.tsx +++ b/src/hooks/useAccounts.tsx @@ -18,7 +18,7 @@ import { setOnboardingGuard, setOnboardingState } from '@/state/account'; import { getGeo, getHasSubaccount } from '@/state/accountSelectors'; import { getSelectedDydxChainId } from '@/state/appSelectors'; import { useAppDispatch, useAppSelector } from '@/state/appTypes'; -import { clearSavedEncryptedSignature } from '@/state/wallet'; +import { clearSavedEncryptedSignature, setLocalWallet } from '@/state/wallet'; import { getSourceAccount } from '@/state/walletSelectors'; import abacusStateManager from '@/lib/abacus'; @@ -135,6 +135,10 @@ const useAccountsContext = () => { [localDydxWallet] ); + useEffect(() => { + dispatch(setLocalWallet({ address: dydxAddress })); + }, [dispatch, dydxAddress]); + const nobleAddress = useMemo(() => { return localNobleWallet?.address; }, [localNobleWallet]); diff --git a/src/state/wallet.ts b/src/state/wallet.ts index 562886f39..2edb93e0c 100644 --- a/src/state/wallet.ts +++ b/src/state/wallet.ts @@ -13,6 +13,9 @@ export type SourceAccount = { // NOTE: This app slice is persisted via redux-persist. Changes to this type may require migrations. export interface WalletState { sourceAccount: SourceAccount; + localWallet?: { + address?: string; + }; } const initialState: WalletState = { @@ -58,6 +61,9 @@ export const walletSlice = createSlice({ clearSavedEncryptedSignature: (state) => { state.sourceAccount.encryptedSignature = undefined; }, + setLocalWallet: (state, { payload }: PayloadAction<{ address?: string }>) => { + state.localWallet = payload; + }, clearSourceAccount: (state) => { state.sourceAccount = { address: undefined, @@ -75,4 +81,5 @@ export const { setSavedEncryptedSignature, clearSavedEncryptedSignature, clearSourceAccount, + setLocalWallet, } = walletSlice.actions;