Skip to content

Commit

Permalink
chore(bonsai-core): sync local address to store for use in bonsai (#1395
Browse files Browse the repository at this point in the history
)
  • Loading branch information
tyleroooo authored and tinaszheng committed Jan 7, 2025
1 parent f6c6b53 commit df32a1a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/abacus-ts/socketSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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 { getSelectedNetwork } from '@/state/appSelectors';
import { createAppSelector } from '@/state/appTypes';

Expand All @@ -18,9 +17,10 @@ export const selectIndexerUrl = createAppSelector([getSelectedNetwork], (network
return `${endpointsConfig.indexers[0]!.api}`;
});

// TODO allow configurable parent subaccount number
export const selectParentSubaccountInfo = createAppSelector(
[getUserWalletAddress, getUserSubaccountNumber],
(wallet, subaccount) => ({ wallet, subaccount })
[(state) => state.wallet.localWallet?.address],
(wallet) => ({ wallet, subaccount: 0 })
);

export const selectIndexerReady = createAppSelector(
Expand Down
6 changes: 5 additions & 1 deletion src/hooks/useAccounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -135,6 +135,10 @@ const useAccountsContext = () => {
[localDydxWallet]
);

useEffect(() => {
dispatch(setLocalWallet({ address: dydxAddress }));
}, [dispatch, dydxAddress]);

const nobleAddress = useMemo(() => {
return localNobleWallet?.address;
}, [localNobleWallet]);
Expand Down
7 changes: 7 additions & 0 deletions src/state/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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,
Expand All @@ -75,4 +81,5 @@ export const {
setSavedEncryptedSignature,
clearSavedEncryptedSignature,
clearSourceAccount,
setLocalWallet,
} = walletSlice.actions;

0 comments on commit df32a1a

Please sign in to comment.