From cd95d453969286ea891a370c8795515fff6ee4dd Mon Sep 17 00:00:00 2001 From: Gabe Rodriguez Date: Thu, 7 Nov 2024 11:07:36 -0800 Subject: [PATCH] clearing wallet height on chain id change --- .../grpc-endpoint-form/use-grpc-endpoint-form.ts | 7 ++++--- apps/extension/src/state/network.ts | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/extension/src/shared/components/grpc-endpoint-form/use-grpc-endpoint-form.ts b/apps/extension/src/shared/components/grpc-endpoint-form/use-grpc-endpoint-form.ts index d961cf16..fbb7f85d 100644 --- a/apps/extension/src/shared/components/grpc-endpoint-form/use-grpc-endpoint-form.ts +++ b/apps/extension/src/shared/components/grpc-endpoint-form/use-grpc-endpoint-form.ts @@ -14,6 +14,7 @@ const useSaveGrpcEndpointSelector = (state: AllSlices) => ({ grpcEndpoint: state.network.grpcEndpoint, chainId: state.network.chainId, setGrpcEndpoint: state.network.setGRPCEndpoint, + clearWalletCreationHeight: state.network.clearWalletCreationHeight, setChainId: state.network.setChainId, }); @@ -31,9 +32,8 @@ export const useGrpcEndpointForm = (isOnboarding: boolean) => { const grpcEndpointsQuery = useRpcs(); // Get the rpc set in storage (if present) - const { grpcEndpoint, chainId, setGrpcEndpoint, setChainId } = useStoreShallow( - useSaveGrpcEndpointSelector, - ); + const { grpcEndpoint, chainId, setGrpcEndpoint, setChainId, clearWalletCreationHeight } = + useStoreShallow(useSaveGrpcEndpointSelector); const [originalChainId, setOriginalChainId] = useState(); const [grpcEndpointInput, setGrpcEndpointInput] = useState(''); @@ -138,6 +138,7 @@ export const useGrpcEndpointForm = (isOnboarding: boolean) => { setConfirmChangedChainIdPromise(undefined); } + await clearWalletCreationHeight(); // changing chain id means the wallet birthday is no longer valid await setGrpcEndpoint(grpcEndpointInput); void chrome.runtime.sendMessage(ServicesMessage.ClearCache); } else { diff --git a/apps/extension/src/state/network.ts b/apps/extension/src/state/network.ts index db6ebee9..ecce8c49 100644 --- a/apps/extension/src/state/network.ts +++ b/apps/extension/src/state/network.ts @@ -7,6 +7,7 @@ export interface NetworkSlice { fullSyncHeight?: number; chainId?: string; setGRPCEndpoint: (endpoint: string) => Promise; + clearWalletCreationHeight: () => Promise; setChainId: (chainId: string) => void; } @@ -24,6 +25,9 @@ export const createNetworkSlice = await local.set('grpcEndpoint', endpoint); }, + clearWalletCreationHeight: async () => { + await local.remove('walletCreationBlockHeight'); + }, setChainId: (chainId: string) => { set(state => { state.network.chainId = chainId;