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

handle wallet birthday height for non-mainnet chain ids #216

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion apps/extension/src/routes/page/onboarding/set-grpc-endpoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@ import { FadeTransition } from '@repo/ui/components/ui/fade-transition';
import { usePageNav } from '../../../utils/navigate';
import { PagePath } from '../paths';
import { GrpcEndpointForm } from '../../../shared/components/grpc-endpoint-form';
import { localExtStorage } from '../../../storage/local';
import { AppParameters } from '@penumbra-zone/protobuf/penumbra/core/app/v1/app_pb';

export const SetGrpcEndpoint = () => {
const navigate = usePageNav();

const onSuccess = (): void => {
// For beta testing: set the wallet block height to zero for non-mainnet chain IDs.
// This logic only runs after the user selects their rpc endpoint.
const onSuccess = async (): Promise<void> => {
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: unfortunately, I still think this is running after services has initialized. Sadly it looks like the useGrpcEndpointForm is incredibly complicated. It's an example of where useEffect() adds complexity... See:

Copy link
Contributor Author

@TalDerei TalDerei Oct 22, 2024

Choose a reason for hiding this comment

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

tricky, maybe migrate the logic directly into onSubmit?

Copy link
Contributor Author

@TalDerei TalDerei Oct 22, 2024

Choose a reason for hiding this comment

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

like why can't we reorder the operations inside the onSubmit async function?

        await setGrpcEndpoint(grpcEndpointInput);

        const storedParams = await localExtStorage.get('params');
        if (storedParams) {
          const parsedParams = JSON.parse(storedParams) as AppParameters;
          if (!parsedParams.chainId.includes('penumbra-1')) {
            await localExtStorage.set('walletCreationBlockHeight', 0);
          }
        }
        
        // block service init
        
        void chrome.runtime.sendMessage(ServicesMessage.ClearCache);
              
         ...

       await onSuccess();

to ensure a proper sequencing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there must be a way to explicitly block on wallet service init until this code block completes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or we can block wallet service init directly inside onboardGrpcEndpoint?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

settled on fcd8e41 for simplicity and readability.

await new Promise(resolve => setTimeout(resolve, 1000));

const storedParams = await localExtStorage.get('params');
if (storedParams) {
const parsedParams = JSON.parse(storedParams) as AppParameters;
TalDerei marked this conversation as resolved.
Show resolved Hide resolved
if (!parsedParams.chainId.includes('penumbra-1')) {
await localExtStorage.set('walletCreationBlockHeight', 0);
}
}
TalDerei marked this conversation as resolved.
Show resolved Hide resolved

// Navigate to the next page after logic completes
navigate(PagePath.SET_DEFAULT_FRONTEND);
};

Expand Down
12 changes: 0 additions & 12 deletions apps/extension/src/routes/page/onboarding/success.tsx
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: This actually too late. The wallet birthday at this point has already been passed to the block processor. It will only pick up this change after the service worker resets.

Copy link
Contributor Author

@TalDerei TalDerei Oct 21, 2024

Choose a reason for hiding this comment

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

this is a great catch. I was under the impression that block syncing started after the last onboarding step, but it actually begins after selecting the rpc endpoint. I revised the logic and migrated it into the grpc page.

Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,10 @@ import { Button } from '@repo/ui/components/ui/button';
import { SplashPage } from '@repo/ui/components/ui/splash-page';
import { useStore } from '../../../state';
import { getDefaultFrontend } from '../../../state/default-frontend';
import { localExtStorage } from '../../../storage/local';

export const OnboardingSuccess = () => {
const defaultFrontendUrl = useStore(getDefaultFrontend);

// Conditional: for beta-testing purposes, set the wallet block height to zero for non-mainnet chain id's.
void (async () => {
const storedParams = await localExtStorage.get('params');
if (storedParams) {
const parsedParams = JSON.parse(storedParams) as string;
if (parsedParams && !parsedParams.includes('penumbra-1')) {
await localExtStorage.set('walletCreationBlockHeight', 0);
}
}
})();

return (
<SplashPage title='Account created'>
<div className='grid gap-2 text-base font-bold'>
Expand Down