Skip to content

Commit

Permalink
clearing wallet height on chain id change
Browse files Browse the repository at this point in the history
  • Loading branch information
grod220 committed Nov 7, 2024
1 parent bc7914a commit cd95d45
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand All @@ -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<string | undefined>();
const [grpcEndpointInput, setGrpcEndpointInput] = useState<string>('');
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions apps/extension/src/state/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface NetworkSlice {
fullSyncHeight?: number;
chainId?: string;
setGRPCEndpoint: (endpoint: string) => Promise<void>;
clearWalletCreationHeight: () => Promise<void>;
setChainId: (chainId: string) => void;
}

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

0 comments on commit cd95d45

Please sign in to comment.