diff --git a/jest.config.ts b/jest.config.ts index 150dd7a03..ccb36c9d4 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -15,7 +15,7 @@ const config = { '.+\\.tsx$': 'ts-jest' }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], - setupFiles: ['dotenv/config', '@serh11p/jest-webextension-mock'], + setupFiles: ['dotenv/config', '@temple-wallet/jest-webextension-mock'], setupFilesAfterEnv: ['./jest.setup.js'] }; diff --git a/package.json b/package.json index 100147cfa..9766341e6 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,6 @@ "@redux-devtools/remote": "^0.8.0", "@reduxjs/toolkit": "^1.8.5", "@rnw-community/shared": "^0.48.0", - "@serh11p/jest-webextension-mock": "4.0.0", "@svgr/webpack": "6.4.0", "@taquito/ledger-signer": "17.0.0", "@taquito/local-forging": "17.0.0", @@ -58,6 +57,7 @@ "@taquito/tzip16": "17.0.0", "@taquito/utils": "17.0.0", "@temple-wallet/dapp": "5.0.2", + "@temple-wallet/jest-webextension-mock": "^4.1.0", "@temple-wallet/wallet-address-validator": "^0.4.3", "@tezos-domains/core": "1.26.0", "@tezos-domains/taquito-client": "1.26.0", diff --git a/public/_locales/uk/messages.json b/public/_locales/uk/messages.json index c34bdbfb9..bc5505ab9 100644 --- a/public/_locales/uk/messages.json +++ b/public/_locales/uk/messages.json @@ -116,6 +116,9 @@ "lock": { "message": "Заблокувати" }, + "lockUpSettingsDescription": { + "message": "Розширення буде заблоковане після 5 хвилин відсутності активності." + }, "importedAccount": { "message": "Імпортовані" }, diff --git a/src/app/templates/DelegateForm.tsx b/src/app/templates/DelegateForm.tsx index a7a0b7ade..0c22806a5 100644 --- a/src/app/templates/DelegateForm.tsx +++ b/src/app/templates/DelegateForm.tsx @@ -41,7 +41,7 @@ import { useTezosAddressByDomainName } from 'lib/temple/front/tzdns'; import { hasManager, isAddressValid, isKTAddress, mutezToTz, tzToMutez } from 'lib/temple/helpers'; import { TempleAccountType } from 'lib/temple/types'; import { useSafeState } from 'lib/ui/hooks'; -import { delay } from 'lib/utils'; +import { delay, fifoResolve } from 'lib/utils'; import { Link, useLocation } from 'lib/woozie'; import { useUserTestingGroupNameSelector } from '../store/ab-testing/selectors'; @@ -200,6 +200,11 @@ const DelegateForm: FC = () => { return undefined; }, [balanceNum, baseFee]); + const fifoValidateDelegate = useMemo( + () => fifoResolve((value: any) => validateDelegate(value, domainsClient, validateAddress)), + [domainsClient] + ); + const handleFeeFieldChange = useCallback( ([v]) => (maxAddFee && v > maxAddFee ? maxAddFee : v), [maxAddFee] @@ -312,9 +317,7 @@ const DelegateForm: FC = () => { name="to" as={} control={control} - rules={{ - validate: (value: any) => validateDelegate(value, domainsClient, validateAddress) - }} + rules={{ validate: fifoValidateDelegate }} onChange={([v]) => v} onFocus={() => toFieldRef.current?.focus()} textarea diff --git a/src/lib/i18n/core.ts b/src/lib/i18n/core.ts index d967c9d90..01d10015c 100644 --- a/src/lib/i18n/core.ts +++ b/src/lib/i18n/core.ts @@ -29,34 +29,32 @@ let fetchedLocaleMessages: FetchedLocaleMessages = { let cldrLocale = cldrjsLocales.en; export async function init() { - const refetched: FetchedLocaleMessages = { - target: null, - fallback: null - }; - const saved = getSavedLocale(); + const deflt = getDefaultLocale(); + const native = getNativeLocale(); - if (saved) { - const deflt = getDefaultLocale(); - const [newTargetLocale, newFallbackLocale] = await Promise.all([ - !areLocalesEqual(saved, deflt) ? fetchLocaleMessages(saved) : null, - fetchLocaleMessages(deflt) - ]); - - refetched.target = newTargetLocale; - refetched.fallback = newFallbackLocale; - } + const [target, fallback] = await Promise.all([ + !saved || areLocalesEqual(saved, native) ? null : fetchLocaleMessages(saved), + areLocalesEqual(deflt, native) || (saved && areLocalesEqual(deflt, saved)) ? null : fetchLocaleMessages(deflt) + ]); - fetchedLocaleMessages = refetched; + fetchedLocaleMessages = { target, fallback }; cldrLocale = (cldrjsLocales as Record)[getCurrentLocale()] || cldrjsLocales.en; } export function getMessage(messageName: string, substitutions?: Substitutions) { - const val = fetchedLocaleMessages.target?.[messageName] ?? fetchedLocaleMessages.fallback?.[messageName]; + const { target, fallback } = fetchedLocaleMessages; + const targetVal = target?.[messageName]; + + if (targetVal) return applySubstitutions(targetVal, substitutions); + + const nativeVal = browser.i18n.getMessage(messageName, substitutions); + + if (nativeVal && !target) return nativeVal; - if (val) return applySubstitutions(val, substitutions); + const fallbackVal = fallback?.[messageName]; - return browser.i18n.getMessage(messageName, substitutions); + return fallbackVal ? applySubstitutions(fallbackVal, substitutions) : ''; } export function getDateFnsLocale() { diff --git a/src/lib/temple/front/validate-delegate.ts b/src/lib/temple/front/validate-delegate.ts index 68261dace..14f5d58e4 100644 --- a/src/lib/temple/front/validate-delegate.ts +++ b/src/lib/temple/front/validate-delegate.ts @@ -1,10 +1,8 @@ import { TaquitoTezosDomainsClient } from '@tezos-domains/taquito-client'; -import memoize from 'micro-memoize'; import { t } from 'lib/i18n'; import { isDomainNameValid } from 'lib/temple/front'; import { isAddressValid } from 'lib/temple/helpers'; -import { fifoResolve } from 'lib/utils'; function validateAnyAddress(value: string) { switch (false) { @@ -19,11 +17,6 @@ function validateAnyAddress(value: string) { } } -const fifoResolveNameToAddress = memoize( - (domainsClient: TaquitoTezosDomainsClient): ((name: string) => Promise) => - fifoResolve(domainsClient.resolver.resolveNameToAddress) -); - export const validateDelegate = async ( value: string | null | undefined, domainsClient: TaquitoTezosDomainsClient, @@ -34,7 +27,7 @@ export const validateDelegate = async ( if (!domainsClient.isSupported) return validateAddress(value); if (isDomainNameValid(value, domainsClient)) { - const resolved = await fifoResolveNameToAddress(domainsClient)(value); + const resolved = await domainsClient.resolver.resolveNameToAddress(value); if (!resolved) { return validateAddress(value) || t('domainDoesntResolveToAddress', value); } diff --git a/yarn.lock b/yarn.lock index a47129a38..6557dac43 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2310,11 +2310,6 @@ resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.2.0.tgz#8be36a1f66f3265389e90b5f9c9962146758f728" integrity sha512-sXo/qW2/pAcmT43VoRKOJbDOfV3cYpq3szSVfIThQXNt+E4DfKj361vaAt3c88U5tPUxzEswam7GW48PJqtKAg== -"@serh11p/jest-webextension-mock@4.0.0": - version "4.0.0" - resolved "https://registry.yarnpkg.com/@serh11p/jest-webextension-mock/-/jest-webextension-mock-4.0.0.tgz#c3b2a00e8c758e156a4a922718b35183e9023af9" - integrity sha512-SQDFFOJGwQpaPopzYkFgzdDdi8tL8US/XM2UjBu4rmLLztTI/wOSecwXj/i3lhOUwOs3bHO2Zz9eRu2rPy5p9A== - "@sinclair/typebox@^0.24.1": version "0.24.44" resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.24.44.tgz#0a0aa3bf4a155a678418527342a3ee84bd8caa5c" @@ -2796,6 +2791,11 @@ dependencies: nanoid "^3.1.25" +"@temple-wallet/jest-webextension-mock@^4.1.0": + version "4.1.0" + resolved "https://registry.yarnpkg.com/@temple-wallet/jest-webextension-mock/-/jest-webextension-mock-4.1.0.tgz#6834acd98297eb1c76b85a2585a0584ff5578e8f" + integrity sha512-1D/3WpaJS9rk5SENnFB1RZ3oeYkrfDvCV4qyIYjAD6uWe6RHVzcGxQ8UPtSQ/MRrcqjT95q2VwDNxek+9z6+yw== + "@temple-wallet/wallet-address-validator@^0.4.3": version "0.4.3" resolved "https://registry.yarnpkg.com/@temple-wallet/wallet-address-validator/-/wallet-address-validator-0.4.3.tgz#4bb7905a824e290872b7a7fc449df2e8c332e9e1"