Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(extension): #207: fix resetting the fullSyncHeight in local storage after cache clearing #217

Merged
merged 5 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(undefined);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: I don't think this will work as doing chrome.storage.set({ "fullSyncHeight": undefined }) is a no-op. Can you confirm with a test? May help reviewing the docs as well: https://developer.chrome.com/docs/extensions/reference/api/storage#type-StorageArea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Truly has some problems, reverted to the Tal's initial solution with allSettled

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;
}),
);

Expand Down