Skip to content

Commit

Permalink
Merge branch 'tu/sync-local-address' into tu/bonsai-all
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo committed Dec 20, 2024
2 parents 475a781 + b134fe1 commit aeda6ed
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,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';

Expand All @@ -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

Check failure on line 23 in src/abacus-ts/socketSelectors.ts

View workflow job for this annotation

GitHub Actions / lint

'subaccount' is defined but never used. Allowed unused args must match /^_/u
);

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 aeda6ed

Please sign in to comment.