Skip to content

Commit

Permalink
fix(extension): #207: fix resetting the fullSyncHeight in local stora…
Browse files Browse the repository at this point in the history
…ge after cache clearing
  • Loading branch information
VanishMax committed Oct 17, 2024
1 parent 97fa552 commit d085ff3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import { SettingsScreen } from './settings-screen';
const useCacheClear = () => {
const navigate = usePopupNav();
const [loading, setLoading] = useState(false);
const setFullSyncHeight = useStore(state => state.network.setFullSyncHeight);

const handleCacheClear = () => {
setLoading(true);

void (async function () {
await setFullSyncHeight(0);
await chrome.runtime.sendMessage(ServicesMessage.ClearCache);
useStore.setState(state => {
state.network.fullSyncHeight = undefined;
});
navigate(PopupPath.INDEX);
})();
};
Expand Down
8 changes: 8 additions & 0 deletions apps/extension/src/state/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface NetworkSlice {
chainId?: string;
setGRPCEndpoint: (endpoint: string) => Promise<void>;
setChainId: (chainId: string) => void;
setFullSyncHeight: (value: number) => Promise<void>;
}

export const createNetworkSlice =
Expand All @@ -29,6 +30,13 @@ export const createNetworkSlice =
state.network.chainId = chainId;
});
},
setFullSyncHeight: async value => {
set(state => {
state.network.fullSyncHeight = value;
});

await local.set('fullSyncHeight', value);
},
};
};

Expand Down
2 changes: 2 additions & 0 deletions apps/extension/src/state/persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const customPersistImpl: Persist = f => (set, get, store) => {
const passwordKey = await sessionExtStorage.get('passwordKey');
const wallets = await localExtStorage.get('wallets');
const grpcEndpoint = await localExtStorage.get('grpcEndpoint');
const fullSyncHeight = await localExtStorage.get('fullSyncHeight');
const knownSites = await localExtStorage.get('knownSites');
const frontendUrl = await localExtStorage.get('frontendUrl');
const numeraires = await localExtStorage.get('numeraires');
Expand All @@ -41,6 +42,7 @@ export const customPersistImpl: Persist = f => (set, get, store) => {
state.connectedSites.knownSites = knownSites;
state.defaultFrontend.url = frontendUrl;
state.numeraires.selectedNumeraires = numeraires;
state.network.fullSyncHeight = fullSyncHeight ?? 0;
}),
);

Expand Down

0 comments on commit d085ff3

Please sign in to comment.