Skip to content

feat: snap birthday block form on install #67

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

Merged
merged 5 commits into from
Feb 19, 2025

Conversation

irubido
Copy link
Collaborator

@irubido irubido commented Feb 13, 2025

Closes #63

Adds snaps Interactive UI Form input as option to set birthday block from which web wallet starts sync.

Dapp redirects to account-summary once wallet was created.

Screenshot from 2025-02-18 16-08-06

I also tried with new OnInstallHandler and storing form data to state, but it does not happen first thing onInstall and does not stop the all other rpcs called.

Screenshot from 2025-02-13 17-52-28

@irubido irubido requested a review from Lykhoyda February 13, 2025 16:52
@irubido irubido changed the title feat: snap birthday feat: snap birthday block form on install Feb 13, 2025
@irubido irubido marked this pull request as ready for review February 14, 2025 15:32
Comment on lines 1 to 3
import { Form, Box, Heading, Input, Button, Text } from "@metamask/snaps-sdk/jsx";

type BirthdayBlockForm = {customBirthdayBlock: number | null}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please reformat files with prettier

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Lint is currently broken across the snap and web-wallet, will address fixing linter to @chainsafe/eslint-config in separate issue

Copy link
Contributor

Choose a reason for hiding this comment

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

@irubido prettier should also be configured with your IDE, to reference the .prettierrc file. I wouldn't rely on @chainsafe/eslint-config as it's pretty outdated. But we can indeed force to to follow prettier styles with eslint

</Text>
<Input min={0} step={1} type='number' name="customBirthdayBlock" placeholder='optional syncing block height' />
</Box>
<Button type='submit' name="next">Next</Button>
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be "submit" button text

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Submit kind of implies that something should be submitted, and it is optional. Maybe, Continue to wallet would be better?

Copy link
Contributor

Choose a reason for hiding this comment

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

"Continue to wallet" sounds good

<Form name="birthday-block-form">
<Box>
<Heading>Optional syncing block height</Heading>
<Text>
Copy link
Contributor

Choose a reason for hiding this comment

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

It would also be nice to give a user a hint about the current block height as a reference point.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Guess I would need "endowment:network-access" and some API providing current block of the chain. Or did I miss some method in wasm returning latest block without initialized wallet?

Copy link
Contributor

Choose a reason for hiding this comment

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

you can pass it from front-end when calling setBirthdayBlock()

@@ -19,7 +20,7 @@ function App() {
}, [location.pathname]);

useInterval(() => {
triggerRescan();
if(installedSnap) triggerRescan();
Copy link
Contributor

Choose a reason for hiding this comment

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

You can put this logic directly inside triggerRescan method as we have an access to the state

@@ -83,10 +83,11 @@ export function useWebZjsActions(): WebzjsActions {

const addNewAccountFromUfvk = useCallback(
async (ufvk: string, birthdayHeight: number) => {
if(state.webWallet === null) {dispatch({ type: 'set-error', payload: new Error('Wallet not initialized') }); return;}
Copy link
Contributor

Choose a reason for hiding this comment

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

reformat with prettier please

}, [installedSnap, navigate]);
if (installedSnap) {
const homeReload = async () => {
const accountData = await getAccountData();
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 we get Account data only on the Receive page?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I replaced unifiedAddress instead installedSnap as a flag that allows /dashboard/account-summary.

Maybe checking wallet summary is better for this case

@irubido
Copy link
Collaborator Author

irubido commented Feb 18, 2025

Screenshot from 2025-02-18 16-08-06

@irubido irubido requested a review from Lykhoyda February 18, 2025 15:13
@Lykhoyda Lykhoyda merged commit 1bf5720 into main Feb 19, 2025
5 checks passed
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.

web-wallet and snap - Add block height option
2 participants