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

Clear cache fix & added sync states #883

Merged
merged 2 commits into from
Apr 5, 2024
Merged

Clear cache fix & added sync states #883

merged 2 commits into from
Apr 5, 2024

Conversation

grod220
Copy link
Collaborator

@grod220 grod220 commented Apr 4, 2024

Closes #824

Does two main things:

  • On cache clearing, waits for db to clear before transitioning back to index. Sometimes takes a bit, so added a loading state for the button.
  • Added genesis and normal loading states for block sync bar. Gives users an indication something is happening. At the moment, it simply doesn't render when its in the loading state.
vid_compressed.mp4

@@ -11,7 +11,7 @@ declare const MINIFRONT_URL: string;

export const localDefaults: LocalStorageState = {
wallets: [],
fullSyncHeight: 0,
fullSyncHeight: undefined,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is sort of a bug somewhat relating to: #882.

0 sync height indicates that we've synced the genesis block. So undefined should be used as the proper default indicating no sync has been done. Lots of changes in components flow from this one change.

Comment on lines +20 to +23
await chrome.runtime.sendMessage(ServicesMessage.ClearCache);
useStore.setState(state => {
state.network.fullSyncHeight = undefined;
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Two things happening here:

  • Awaiting cache clearing to finish
  • resetting zustand sync height

Only after this do we navigate. Sometimes this can be slower, so added a loading state.

<motion.div
className='flex w-full flex-col gap-1'
initial={{ opacity: 0 }}
animate={{ opacity: 1, transition: { duration: 0.3, ease: 'easeOut', delay: 0.75 } }}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Set a short delay. If not, flickers the screen.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I understand what flickers, but setting a hard-coded time delay to avoid flicker feels a little hacky to me, since whether it works depends on the speed of the user's computer. Is there not a deterministic way to prevent flicker?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here's without it. Essentially, we need a sort of UI debouncer to prevent it. I found a slight animation delay is sufficient, but perhaps there is a better way 🤔

Screen.Recording.2024-04-05.at.5.53.03.AM.mov

@@ -56,7 +90,7 @@ const SyncingState = ({ fullSyncHeight, latestKnownBlockHeight }: SyncingStatePr
return (
<motion.div
className='flex w-full flex-col items-center gap-1'
initial={{ opacity: 1 }}
initial={{ opacity: 0 }}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

bug fix

@grod220 grod220 force-pushed the block-sync-states branch from 417e642 to 95e8214 Compare April 4, 2024 13:45
Copy link
Contributor

@jessepinho jessepinho left a comment

Choose a reason for hiding this comment

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

Couple small Qs, but feel free to merge after addressing those. This is a big UX win!

@@ -12,7 +12,9 @@ export const LargeBlockSyncStatus = ({
error,
}: BlockSyncProps) => {
if (error) return <BlockSyncErrorState error={error} />;
if (!latestKnownBlockHeight || !fullSyncHeight) return <div />;
if (!latestKnownBlockHeight || !fullSyncHeight) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be checking for !== undefined? Since 0n now means that the first block has synced?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Aha! This edge case is the gift that keeps on giving.

<motion.div
className='flex w-full flex-col gap-1'
initial={{ opacity: 0 }}
animate={{ opacity: 1, transition: { duration: 0.3, ease: 'easeOut', delay: 0.75 } }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I understand what flickers, but setting a hard-coded time delay to avoid flicker feels a little hacky to me, since whether it works depends on the speed of the user's computer. Is there not a deterministic way to prevent flicker?

@grod220 grod220 merged commit 406bd16 into main Apr 5, 2024
6 checks passed
@grod220 grod220 deleted the block-sync-states branch April 5, 2024 04:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add block sync states
2 participants