-
-
Notifications
You must be signed in to change notification settings - Fork 359
chore: bump react-hook-form, @hookform/resolvers, yup #18704
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { useEffect, useRef } from 'react'; | ||
| import { useDispatch, useSelector } from 'react-redux'; | ||
|
|
||
| import { BuyTrade } from 'invity-api'; | ||
| import { BuyTrade, CryptoId, FiatCurrencyCode } from 'invity-api'; | ||
|
|
||
| import { useFormatters } from '@suite-common/formatters'; | ||
| import { | ||
|
|
@@ -34,53 +34,58 @@ const useReceiveAccountChangeEffect = ({ setValue }: TradingBuyForm) => { | |
| }, [selectedReceiveAccount, setValue]); | ||
| }; | ||
|
|
||
| const useAmountAndCurrencyFieldsChangeEffect = ({ setValue, watch }: TradingBuyForm) => { | ||
| const useAmountAndCurrencyFieldsChangeEffect = ({ setValue, getValues, watch }: TradingBuyForm) => { | ||
| const dispatch = useDispatch(); | ||
| const prevNetworkId = useRef<string | undefined>(undefined); | ||
| const prevCryptoId = useRef<CryptoId | undefined>(undefined); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using cryptoId I can distinguish tokens of the same network and solve #18677 (review) |
||
| const prevFiatCurrency = useRef<FiatCurrencyCode | undefined>(getValues('fiatCurrency')); | ||
|
|
||
| useEffect(() => { | ||
| const { unsubscribe } = watch(({ focusedValue, asset, amountInCrypto }, { name, type }) => { | ||
| switch (name) { | ||
| case 'fiatValue': | ||
| if (focusedValue === 'fiatValue' && type === 'change') { | ||
| setValue('cryptoValue', undefined, { shouldValidate: true }); | ||
| if (amountInCrypto) { | ||
| setValue('amountInCrypto', false); | ||
| const { unsubscribe } = watch( | ||
| ({ focusedValue, asset, amountInCrypto, fiatCurrency }, { name, type }) => { | ||
| switch (name) { | ||
| case 'fiatValue': | ||
| if (focusedValue === 'fiatValue' && type === 'change') { | ||
| setValue('cryptoValue', undefined, { shouldValidate: true }); | ||
| if (amountInCrypto) { | ||
| setValue('amountInCrypto', false); | ||
| } | ||
| } | ||
| } | ||
| break; | ||
| break; | ||
|
|
||
| case 'cryptoValue': | ||
| if (focusedValue === 'cryptoValue' && type === 'change') { | ||
| setValue('fiatValue', undefined, { shouldValidate: true }); | ||
| if (!amountInCrypto) { | ||
| setValue('amountInCrypto', true); | ||
| } | ||
| } | ||
| break; | ||
|
|
||
| case 'cryptoValue': | ||
| if (focusedValue === 'cryptoValue' && type === 'change') { | ||
| setValue('fiatValue', undefined, { shouldValidate: true }); | ||
| if (!amountInCrypto) { | ||
| setValue('amountInCrypto', true); | ||
| case 'fiatCurrency': | ||
| if (fiatCurrency !== prevFiatCurrency.current) { | ||
| prevFiatCurrency.current = fiatCurrency; | ||
| setValue('fiatValue', undefined, { shouldValidate: true }); | ||
| setValue('cryptoValue', undefined, { shouldValidate: true }); | ||
| } | ||
| break; | ||
|
|
||
| case 'asset': { | ||
| if (asset?.cryptoId !== prevCryptoId.current) { | ||
| prevCryptoId.current = asset?.cryptoId as CryptoId | undefined; | ||
| setValue('cryptoValue', undefined, { shouldValidate: true }); | ||
| dispatch( | ||
| setBuySelectedReceiveAccount({ selectedReceiveAccount: undefined }), | ||
| ); | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only clear the This fixes an infinite render loop, that only manifested in Note: I spend considerably time debugging this, trying to find the real root cause why this started happening after bumping react-hook-form to 7.55. I did not succeed 😞
This issue sounds relevant, but I reproduced the same crash even in 7.55, not just 7.56 |
||
| break; | ||
| } | ||
| break; | ||
|
|
||
| case 'fiatCurrency': | ||
| setValue('fiatValue', undefined, { shouldValidate: true }); | ||
| setValue('cryptoValue', undefined, { shouldValidate: true }); | ||
| break; | ||
|
|
||
| case 'asset': { | ||
| setValue('cryptoValue', undefined, { shouldValidate: true }); | ||
|
|
||
| if (asset?.networkId !== prevNetworkId.current) { | ||
| prevNetworkId.current = asset?.networkId; | ||
| dispatch( | ||
| setBuySelectedReceiveAccount({ selectedReceiveAccount: undefined }), | ||
| ); | ||
| } | ||
| break; | ||
| default: | ||
| // do nothing | ||
| break; | ||
| } | ||
|
|
||
| default: | ||
| // do nothing | ||
| break; | ||
| } | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
| return unsubscribe; | ||
| }, [dispatch, setValue, watch]); | ||
|
|
||
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.
Solve TS error at L76 (
string | undefinednot assignable tostringforpath, signature)The problem arose when bumping
@hookform/resolvers + react-hook-form, and then bumpingyupdid not help.It took me a while to realize that the former two are not at fault, it's
yupthat was insufficiently typed (in both versions I tried!), andreact-hook-formmerely tightened its types to catch that.