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 1 commit
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(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Does a height synced of 0 mean that the genesis state has been synced? I actually think the data structure is more like:

fullSyncHeight = undefined --> no syncing has been completed
fullSyncHeight = 0 --> genesis state synced
fullSyncHeight = <number> --> that block number has been synced

Can you validate this? May help checking the logic of the loading bar to see what text shows under which condition.

Copy link
Contributor Author

@VanishMax VanishMax Oct 17, 2024

Choose a reason for hiding this comment

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

Both 0 and undefined mean loading, number means syncing, and latestKnownBlockHeight - fullSyncHeight <= 10 means synced

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated zeros to undefined

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