-
Notifications
You must be signed in to change notification settings - Fork 91
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
feat: removal of react hook form #166
Conversation
…on to be looked at
…-form it was trigger to many recalulations
19e96e5
to
00ae41b
Compare
We might want to revise what hooks are made available for the external API? see commit 44b71ec |
0dad7bf
to
b6e6450
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find URLSearchParamsBuilder event though we export it from form barrel file.
packages/widget/src/types/index.ts
Outdated
// TODO: needs to be removed | ||
declare global { | ||
interface Window { | ||
useFormStore?: boolean; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes. I'll get rid of that
// The following a is a "placeholder" "for validation for toAddress | ||
// is will be re-addressed in the next piece of work for Wallet Switching |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please improve this comment? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we can probably live without it - I'll delete it
{ ...valuesToFormValues(formDefaultValues) }, | ||
); | ||
|
||
// TODO: isValidating & isValid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is done?
useEffect(() => { | ||
addFieldValidation('toAddress', async (value: string) => { | ||
try { | ||
if (!value && requiredToAddress) { | ||
return t('error.title.walletEnsAddressInvalid'); | ||
} | ||
}, | ||
onBlur: () => trigger(FormKey.ToAddress), | ||
}, | ||
}); | ||
|
||
if (!value || isAddress(value) || isSVMAddress(value)) { | ||
return true; | ||
} | ||
const address = await getEnsAddress(config, { | ||
chainId: getFieldValues('toChain')[0], | ||
name: normalize(value), | ||
}); | ||
return Boolean(address); | ||
} catch (error) { | ||
return t('error.title.walletEnsAddressInvalid') as string; | ||
} | ||
}); | ||
}, [addFieldValidation, requiredToAddress, getFieldValues, t, config]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add this field onBlur instead of creating validation on every field update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed this and decide for now its actually ok for it to stay here as it only really will update on requiredToAddress and config changing - though we might look to optimise the pattern for validation in future.
When testing this is wasn't actually working. This was main due to a problem in the useValidationActions hook and a missing call to clearErrors when valid.
Now fixed and works as it did previously - the additional clearErrors logic has been put in the formStore logic and the useValidationActions has been rewritten like the useFieldActions hook so that it avoid any potential problems related to connascence of position/meaning. See commit 9ebef7f
@@ -1,10 +1,8 @@ | |||
import { useEffect, useRef, useState } from 'react'; | |||
import { useWatch } from 'react-hook-form'; | |||
import { useFieldValues } from '../stores'; | |||
|
|||
export const useDebouncedWatch = (name: any, delay: number) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove any
and type name
properly here now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually yes and I think the use of the useDebouncedWatch probably doesn't need to be used with FormKey anymore
// Makes widget config options reactive to changes | ||
// Acts similar to values property from useForm, but includes additional logic for chains |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be updated I guess, we no longer have useForm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update
import type { UseBoundStoreWithEqualityFn } from 'zustand/esm/traditional'; | ||
import type { StoreApi } from 'zustand/esm'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ESM is used by default, so we can safely import from zustand
and zustand/traditional
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check those and change them
Maybe later, those are undocumented exports for our experimental NFT flow. |
I've fixed the gitignore file now, this was filtering out the URLSearchParamsBuilder.tsx file and listing it as ignored due to I think this should be ready for review again |
Hey! This is your new endopint: https://6ab298ef.widget-spikeremov.pages.dev |
Jira: LF-5981
This PR looks to remove the react-hook-form library from the Widget
It puts a zustand store in its place to handle the passing of form values across the app.
Main hooks that interact with the form store
other hooks
*The validation here is a placeholder and will likely change when looking at the new changes for the Wallet Switcher (should be the next piece of work)