diff --git a/packages/product-components/package.json b/packages/product-components/package.json index b3479c361abf..67d0ea919154 100644 --- a/packages/product-components/package.json +++ b/packages/product-components/package.json @@ -29,7 +29,7 @@ "@trezor/utils": "workspace:*", "framer-motion": "^12.9.1", "react": "18.2.0", - "react-hook-form": "^7.54.2", + "react-hook-form": "^7.56.1", "react-intl": "^7.1.11", "react-svg": "16.3.0", "styled-components": "^6.1.17", diff --git a/packages/suite/package.json b/packages/suite/package.json index 848d449236ad..ccabfd2ef1a7 100644 --- a/packages/suite/package.json +++ b/packages/suite/package.json @@ -21,7 +21,7 @@ "@everstake/wallet-sdk": "1.0.14", "@floating-ui/react": "^0.27.8", "@formatjs/intl": "3.1.6", - "@hookform/resolvers": "^4.1.3", + "@hookform/resolvers": "^5.0.1", "@mobily/ts-belt": "^3.13.1", "@reduxjs/toolkit": "2.6.0", "@sentry/core": "8.55.0", @@ -102,7 +102,7 @@ "react-dom": "18.2.0", "react-focus-lock": "^2.13.6", "react-helmet-async": "^2.0.5", - "react-hook-form": "^7.54.2", + "react-hook-form": "^7.56.1", "react-intl": "^7.1.11", "react-qr-reader": "^2.2.1", "react-redux": "9.2.0", diff --git a/packages/suite/src/hooks/wallet/sign-verify/useSignVerifyForm.ts b/packages/suite/src/hooks/wallet/sign-verify/useSignVerifyForm.ts index 2b7a330661c8..ab673247bb2f 100644 --- a/packages/suite/src/hooks/wallet/sign-verify/useSignVerifyForm.ts +++ b/packages/suite/src/hooks/wallet/sign-verify/useSignVerifyForm.ts @@ -17,7 +17,17 @@ type SignVerifyContext = { symbol: NetworkSymbol; }; -const signVerifySchema = yup.object({ +// yup doesn't type properly conditionally required fields → need to declare type rather than infer it +export type SignVerifyFields = { + message: string; + address: string; + hex: boolean; + path?: string; + signature?: string; + isElectrum?: boolean; +}; + +const signVerifySchema: yup.ObjectSchema = yup.object({ message: yup .string() .max(MAX_LENGTH_MESSAGE, 'TR_TOO_LONG') @@ -48,8 +58,6 @@ const signVerifySchema = yup.object({ isElectrum: yup.boolean(), }); -export type SignVerifyFields = yup.InferType; - const DEFAULT_VALUES: SignVerifyFields = { message: '', address: '', diff --git a/suite-common/validators/package.json b/suite-common/validators/package.json index 4253a2381993..ba544bcca089 100644 --- a/suite-common/validators/package.json +++ b/suite-common/validators/package.json @@ -16,6 +16,6 @@ "@suite-common/wallet-config": "workspace:*", "@suite-common/wallet-utils": "workspace:*", "@trezor/utils": "workspace:*", - "yup": "^1.4.0" + "yup": "^1.6.1" } } diff --git a/suite-common/wallet-core/package.json b/suite-common/wallet-core/package.json index 81f7c4aa37b9..f968a7625737 100644 --- a/suite-common/wallet-core/package.json +++ b/suite-common/wallet-core/package.json @@ -34,7 +34,7 @@ "@trezor/type-utils": "workspace:*", "@trezor/utils": "workspace:*", "date-fns": "^4.1.0", - "react-hook-form": "^7.54.2", + "react-hook-form": "^7.56.1", "web3-utils": "^4.3.1" } } diff --git a/suite-common/wallet-utils/package.json b/suite-common/wallet-utils/package.json index ab9d7c82a8b0..452e501db297 100644 --- a/suite-common/wallet-utils/package.json +++ b/suite-common/wallet-utils/package.json @@ -29,7 +29,7 @@ "@trezor/utils": "workspace:*", "date-fns": "^4.1.0", "react": "18.2.0", - "react-hook-form": "^7.54.2", + "react-hook-form": "^7.56.1", "web3-utils": "^4.3.1" } } diff --git a/suite-native/accounts/package.json b/suite-native/accounts/package.json index 022463892cb9..2cc133eceba6 100644 --- a/suite-native/accounts/package.json +++ b/suite-native/accounts/package.json @@ -38,7 +38,7 @@ "@trezor/styles": "workspace:*", "jotai": "1.9.1", "react": "18.2.0", - "react-hook-form": "^7.54.2", + "react-hook-form": "^7.56.1", "react-native": "0.76.9", "react-native-reanimated": "^3.16.7", "react-redux": "9.2.0" diff --git a/suite-native/forms/package.json b/suite-native/forms/package.json index 7cdaf00ac8c2..3c48eba96aad 100644 --- a/suite-native/forms/package.json +++ b/suite-native/forms/package.json @@ -10,13 +10,13 @@ "type-check": "yarn g:tsc --build" }, "dependencies": { - "@hookform/resolvers": "^4.1.3", + "@hookform/resolvers": "^5.0.1", "@mobily/ts-belt": "^3.13.1", "@suite-native/atoms": "workspace:*", "@suite-native/icons": "workspace:*", "react": "18.2.0", - "react-hook-form": "^7.54.2", + "react-hook-form": "^7.56.1", "react-native": "0.76.9", - "yup": "^1.4.0" + "yup": "^1.6.1" } } diff --git a/suite-native/module-accounts-import/package.json b/suite-native/module-accounts-import/package.json index 8c54fa828970..19671af5c4cf 100644 --- a/suite-native/module-accounts-import/package.json +++ b/suite-native/module-accounts-import/package.json @@ -46,7 +46,7 @@ "@trezor/utils": "workspace:*", "@trezor/utxo-lib": "workspace:*", "react": "18.2.0", - "react-hook-form": "^7.54.2", + "react-hook-form": "^7.56.1", "react-native": "0.76.9", "react-native-reanimated": "^3.16.7", "react-redux": "9.2.0" diff --git a/suite-native/module-send/package.json b/suite-native/module-send/package.json index 453378a4de98..8f7c18a3d73b 100644 --- a/suite-native/module-send/package.json +++ b/suite-native/module-send/package.json @@ -48,7 +48,7 @@ "expo-linear-gradient": "^14.0.1", "jotai": "1.9.1", "react": "18.2.0", - "react-hook-form": "^7.54.2", + "react-hook-form": "^7.56.1", "react-native": "0.76.9", "react-native-reanimated": "^3.16.7", "react-native-svg": "^15.9.0", diff --git a/suite-native/module-trading/src/hooks/useTradingBuyForm.ts b/suite-native/module-trading/src/hooks/useTradingBuyForm.ts index 1fdf723ac60e..0b0883620e2f 100644 --- a/suite-native/module-trading/src/hooks/useTradingBuyForm.ts +++ b/suite-native/module-trading/src/hooks/useTradingBuyForm.ts @@ -1,7 +1,7 @@ import { useEffect, useRef } from 'react'; import { useDispatch, useSelector } from 'react-redux'; -import { BuyTrade } from 'invity-api'; +import { BuyTrade, 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, watch, getValues }: TradingBuyForm) => { const dispatch = useDispatch(); const prevNetworkId = useRef(undefined); + const prevFiatCurrency = useRef(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?.networkId !== prevNetworkId.current) { + prevNetworkId.current = asset?.networkId; + setValue('cryptoValue', undefined, { shouldValidate: true }); + dispatch( + setBuySelectedReceiveAccount({ selectedReceiveAccount: undefined }), + ); + } + 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]); diff --git a/yarn.lock b/yarn.lock index dab673f46916..01b78d882c30 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3930,14 +3930,14 @@ __metadata: languageName: node linkType: hard -"@hookform/resolvers@npm:^4.1.3": - version: 4.1.3 - resolution: "@hookform/resolvers@npm:4.1.3" +"@hookform/resolvers@npm:^5.0.1": + version: 5.0.1 + resolution: "@hookform/resolvers@npm:5.0.1" dependencies: "@standard-schema/utils": "npm:^0.3.0" peerDependencies: - react-hook-form: ^7.0.0 - checksum: 10/7cd4a872509c79053fd3a377bc2831348453b60f1af41564442b574d4f36b6303f751e715d01c2d9291b484581ae0152045e779aefafdd66802055e24eff7762 + react-hook-form: ^7.55.0 + checksum: 10/a54904e90ea7c600ed59f6c5b9dd1d8039dcf99b32f285602fcb14e915ea1a7568133debceb7801cec5f8f3f06d9cf5d285fe8d1fb5e3c844f3f9b47dc7e91d6 languageName: node linkType: hard @@ -9546,7 +9546,7 @@ __metadata: "@suite-common/wallet-config": "workspace:*" "@suite-common/wallet-utils": "workspace:*" "@trezor/utils": "workspace:*" - yup: "npm:^1.4.0" + yup: "npm:^1.6.1" languageName: unknown linkType: soft @@ -9594,7 +9594,7 @@ __metadata: "@trezor/type-utils": "workspace:*" "@trezor/utils": "workspace:*" date-fns: "npm:^4.1.0" - react-hook-form: "npm:^7.54.2" + react-hook-form: "npm:^7.56.1" web3-utils: "npm:^4.3.1" languageName: unknown linkType: soft @@ -9637,7 +9637,7 @@ __metadata: "@trezor/utils": "workspace:*" date-fns: "npm:^4.1.0" react: "npm:18.2.0" - react-hook-form: "npm:^7.54.2" + react-hook-form: "npm:^7.56.1" web3-utils: "npm:^4.3.1" languageName: unknown linkType: soft @@ -9691,7 +9691,7 @@ __metadata: "@trezor/styles": "workspace:*" jotai: "npm:1.9.1" react: "npm:18.2.0" - react-hook-form: "npm:^7.54.2" + react-hook-form: "npm:^7.56.1" react-native: "npm:0.76.9" react-native-reanimated: "npm:^3.16.7" react-redux: "npm:9.2.0" @@ -10202,14 +10202,14 @@ __metadata: version: 0.0.0-use.local resolution: "@suite-native/forms@workspace:suite-native/forms" dependencies: - "@hookform/resolvers": "npm:^4.1.3" + "@hookform/resolvers": "npm:^5.0.1" "@mobily/ts-belt": "npm:^3.13.1" "@suite-native/atoms": "workspace:*" "@suite-native/icons": "workspace:*" react: "npm:18.2.0" - react-hook-form: "npm:^7.54.2" + react-hook-form: "npm:^7.56.1" react-native: "npm:0.76.9" - yup: "npm:^1.4.0" + yup: "npm:^1.6.1" languageName: unknown linkType: soft @@ -10375,7 +10375,7 @@ __metadata: "@trezor/utils": "workspace:*" "@trezor/utxo-lib": "workspace:*" react: "npm:18.2.0" - react-hook-form: "npm:^7.54.2" + react-hook-form: "npm:^7.56.1" react-native: "npm:0.76.9" react-native-reanimated: "npm:^3.16.7" react-redux: "npm:9.2.0" @@ -10724,7 +10724,7 @@ __metadata: expo-linear-gradient: "npm:^14.0.1" jotai: "npm:1.9.1" react: "npm:18.2.0" - react-hook-form: "npm:^7.54.2" + react-hook-form: "npm:^7.56.1" react-native: "npm:0.76.9" react-native-reanimated: "npm:^3.16.7" react-native-svg: "npm:^15.9.0" @@ -12063,7 +12063,7 @@ __metadata: "@types/react": "npm:18.2.55" framer-motion: "npm:^12.9.1" react: "npm:18.2.0" - react-hook-form: "npm:^7.54.2" + react-hook-form: "npm:^7.56.1" react-intl: "npm:^7.1.11" react-svg: "npm:16.3.0" storybook: "npm:^8.6.12" @@ -12450,7 +12450,7 @@ __metadata: "@floating-ui/react": "npm:^0.27.8" "@formatjs/cli": "npm:6.6.4" "@formatjs/intl": "npm:3.1.6" - "@hookform/resolvers": "npm:^4.1.3" + "@hookform/resolvers": "npm:^5.0.1" "@mobily/ts-belt": "npm:^3.13.1" "@reduxjs/toolkit": "npm:2.6.0" "@sentry/core": "npm:8.55.0" @@ -12549,7 +12549,7 @@ __metadata: react-dom: "npm:18.2.0" react-focus-lock: "npm:^2.13.6" react-helmet-async: "npm:^2.0.5" - react-hook-form: "npm:^7.54.2" + react-hook-form: "npm:^7.56.1" react-intl: "npm:^7.1.11" react-qr-reader: "npm:^2.2.1" react-redux: "npm:9.2.0" @@ -35080,12 +35080,12 @@ __metadata: languageName: node linkType: hard -"react-hook-form@npm:^7.54.2": - version: 7.54.2 - resolution: "react-hook-form@npm:7.54.2" +"react-hook-form@npm:^7.56.1": + version: 7.56.1 + resolution: "react-hook-form@npm:7.56.1" peerDependencies: react: ^16.8.0 || ^17 || ^18 || ^19 - checksum: 10/b156d15b6246c76d0275e5722d9056014693e014d0e3dec06e44bf2672ee549aaba4366de5144d18c4cab29e631f3b2b84269d4fd5727ca17aad9b970fde6960 + checksum: 10/42f9b5a78c9cc0c0f4eaff0eedbe9f019c1c2c8bbacdc9d3fdead7a1b652b4a34f5f6a2d0c7923c5edaf54a5a4c246d4ac6650c80cb91bc9ff4247100e725169 languageName: node linkType: hard @@ -43012,15 +43012,15 @@ __metadata: languageName: node linkType: hard -"yup@npm:^1.4.0": - version: 1.4.0 - resolution: "yup@npm:1.4.0" +"yup@npm:^1.6.1": + version: 1.6.1 + resolution: "yup@npm:1.6.1" dependencies: property-expr: "npm:^2.0.5" tiny-case: "npm:^1.0.3" toposort: "npm:^2.0.2" type-fest: "npm:^2.19.0" - checksum: 10/3d1277e5e1fff4d8130e525c7361f54874ca848ebd427a0aa66606952e3370b9947d84a1ea0b943f389649e886d26b1349930889727489460d6f2f86c2a26e77 + checksum: 10/19dba13403160a8739a9e57c8b816254842f3a9e01672846a980d8230cee8763783c089ded88662b30158d1479cf6bce0b51dce7f19ae7d0477be0c981024bc0 languageName: node linkType: hard