From 247d393d2d101c1372b19b9546745f668d948129 Mon Sep 17 00:00:00 2001 From: vetalcore Date: Tue, 14 May 2024 13:52:30 +0300 Subject: [PATCH] chore(extension): add typings for core and cardano packages --- .../multi-wallet/hardware-wallet/steps/Connect.tsx | 2 +- packages/cardano/src/ui/typings/i18next.d.ts | 10 ++++++++++ .../src/ui/components/Activity/AssetActivityItem.tsx | 3 ++- .../components/ActivityDetail/TransactionDetails.tsx | 7 ++++--- .../core/src/ui/components/AssetInput/AssetInput.tsx | 3 ++- .../WalletSetup/WalletSetupNamePasswordStep/utils.ts | 3 ++- packages/core/src/ui/typings/i18next.d.ts | 10 ++++++++++ packages/translation/src/lib/translations/core/en.json | 1 + 8 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 packages/cardano/src/ui/typings/i18next.d.ts create mode 100644 packages/core/src/ui/typings/i18next.d.ts diff --git a/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/hardware-wallet/steps/Connect.tsx b/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/hardware-wallet/steps/Connect.tsx index da251d7d6..d9cfd847a 100644 --- a/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/hardware-wallet/steps/Connect.tsx +++ b/apps/browser-extension-wallet/src/views/browser-view/features/multi-wallet/hardware-wallet/steps/Connect.tsx @@ -1,7 +1,7 @@ /* eslint-disable unicorn/no-null */ import { Wallet } from '@lace/cardano'; import { WalletSetupConnectHardwareWalletStepRevamp } from '@lace/core'; -import { TranslationKey } from '@lib/translations/types'; +import { TranslationKey } from '@lace/translation'; import { TFunction } from 'i18next'; import React, { useCallback, useEffect, useState, VFC } from 'react'; import { useTranslation } from 'react-i18next'; diff --git a/packages/cardano/src/ui/typings/i18next.d.ts b/packages/cardano/src/ui/typings/i18next.d.ts new file mode 100644 index 000000000..9504b1ac7 --- /dev/null +++ b/packages/cardano/src/ui/typings/i18next.d.ts @@ -0,0 +1,10 @@ +import 'i18next'; +import type { Translations } from '@lace/translation'; + +declare module 'i18next' { + interface CustomTypeOptions { + resources: { + translation: Translations; + }; + } +} diff --git a/packages/core/src/ui/components/Activity/AssetActivityItem.tsx b/packages/core/src/ui/components/Activity/AssetActivityItem.tsx index 46cc344be..8360d417b 100644 --- a/packages/core/src/ui/components/Activity/AssetActivityItem.tsx +++ b/packages/core/src/ui/components/Activity/AssetActivityItem.tsx @@ -15,6 +15,7 @@ import type { ActivityType } from '../ActivityDetail/types'; import styles from './AssetActivityItem.module.scss'; import { ActivityTypeIcon } from '../ActivityDetail/ActivityTypeIcon'; import { useTranslation } from 'react-i18next'; +import { TranslationKey } from '@lace/translation'; export type ActivityAssetInfo = { ticker: string }; export type ActivityAssetProp = { id: string; val: string; info?: ActivityAssetInfo }; @@ -193,7 +194,7 @@ export const AssetActivityItem = ({
{isPendingTx && type !== TransactionActivityType.self && !(type in DelegationActivityType) ? t('core.assetActivityItem.entry.name.sending') - : t(`core.assetActivityItem.entry.name.${type}`)} + : t(`core.assetActivityItem.entry.name.${type}` as unknown as TranslationKey)}
{descriptionContent} diff --git a/packages/core/src/ui/components/ActivityDetail/TransactionDetails.tsx b/packages/core/src/ui/components/ActivityDetail/TransactionDetails.tsx index a327e2676..e3b1460ff 100644 --- a/packages/core/src/ui/components/ActivityDetail/TransactionDetails.tsx +++ b/packages/core/src/ui/components/ActivityDetail/TransactionDetails.tsx @@ -24,6 +24,7 @@ import { } from './types'; import { Collateral, CollateralStatus } from './Collateral'; import { useTranslation } from 'react-i18next'; +import { TranslationKey } from '@lace/translation'; // eslint-disable-next-line @typescript-eslint/no-explicit-any const displayMetadataMsg = (value: any[]): string => value?.find((val: any) => val.hasOwnProperty('msg'))?.msg || ''; @@ -158,7 +159,7 @@ export const TransactionDetails = ({ ...detail, ...('title' in detail && detail.title === 'certificateType' && { - details: [t(`core.assetActivityItem.entry.name.${detail.details[0]}`)] + details: [t(`core.assetActivityItem.entry.name.${detail.details[0]}` as unknown as TranslationKey)] }), ...('title' in detail && detail.title === 'anchorURL' && { @@ -178,7 +179,7 @@ export const TransactionDetails = ({ ...p, ...('title' in p && p.title === 'type' && { - details: [t(`core.activityDetails.governanceActions.${p.details[0]}`)] + details: [t(`core.activityDetails.governanceActions.${p.details[0]}` as unknown as TranslationKey)] }), ...('title' in p && p.title === 'anchorURL' && { @@ -220,7 +221,7 @@ export const TransactionDetails = ({ ...p, ...('title' in p && ['voterType', 'voteTypes'].includes(p.title) && { - details: [t(`core.activityDetails.${p.title}.${p.details[0]}`)] + details: [t(`core.activityDetails.${p.title}.${p.details[0]}` as unknown as TranslationKey)] }), ...('title' in p && p.title === 'anchorURL' && { diff --git a/packages/core/src/ui/components/AssetInput/AssetInput.tsx b/packages/core/src/ui/components/AssetInput/AssetInput.tsx index 5e044840c..774de2f8d 100644 --- a/packages/core/src/ui/components/AssetInput/AssetInput.tsx +++ b/packages/core/src/ui/components/AssetInput/AssetInput.tsx @@ -8,6 +8,7 @@ import styles from './AssetInput.module.scss'; import { validateNumericValue } from '@src/ui/utils/validate-numeric-value'; import { sanitizeNumber } from '@ui/utils/sanitize-number'; import { useTranslation } from 'react-i18next'; +import { TranslationKey } from '@lace/translation'; const isSameNumberFormat = (num1: string, num2: string) => { if (!num1 || !num2) return false; @@ -38,7 +39,7 @@ export interface AssetInputProps { hasReachedMaxAmount?: boolean; focused?: boolean; onBlurErrors?: Set; - getErrorMessage: (message: string) => string; + getErrorMessage: (message: string) => TranslationKey; setFocusInput?: (input?: string) => void; setFocus?: (focus: boolean) => void; } diff --git a/packages/core/src/ui/components/WalletSetup/WalletSetupNamePasswordStep/utils.ts b/packages/core/src/ui/components/WalletSetup/WalletSetupNamePasswordStep/utils.ts index 92322594b..6533cbd1c 100644 --- a/packages/core/src/ui/components/WalletSetup/WalletSetupNamePasswordStep/utils.ts +++ b/packages/core/src/ui/components/WalletSetup/WalletSetupNamePasswordStep/utils.ts @@ -1,11 +1,12 @@ import { complexityLevels } from '@lace/common'; import { ValidationErrorKeys } from './types'; +import { TranslationKey } from '@lace/translation'; // Depending on what is the result of the A/B test, we might want to use these functions/constants in WalletSetupRegisterStep.tsx and WalletSetupPasswordStep.tsx to clean thing up export const MINIMUM_PASSWORD_LEVEL_REQUIRED = 3; export const WALLET_NAME_INPUT_MAX_LENGTH = 30; -export const passwordStrengthFeedbackMap: Record = { +export const passwordStrengthFeedbackMap: Record = { 0: 'core.walletNameAndPasswordSetupStep.firstLevelPasswordStrengthFeedback', 1: 'core.walletNameAndPasswordSetupStep.firstLevelPasswordStrengthFeedback', 2: 'core.walletNameAndPasswordSetupStep.secondLevelPasswordStrengthFeedback' diff --git a/packages/core/src/ui/typings/i18next.d.ts b/packages/core/src/ui/typings/i18next.d.ts new file mode 100644 index 000000000..9504b1ac7 --- /dev/null +++ b/packages/core/src/ui/typings/i18next.d.ts @@ -0,0 +1,10 @@ +import 'i18next'; +import type { Translations } from '@lace/translation'; + +declare module 'i18next' { + interface CustomTypeOptions { + resources: { + translation: Translations; + }; + } +} diff --git a/packages/translation/src/lib/translations/core/en.json b/packages/translation/src/lib/translations/core/en.json index 94fe015cf..a21b85e79 100644 --- a/packages/translation/src/lib/translations/core/en.json +++ b/packages/translation/src/lib/translations/core/en.json @@ -6,6 +6,7 @@ "core.activityDetails.certificateTitles.anchorHash": "Anchor Hash", "core.activityDetails.certificateTitles.anchorURL": "Anchor URL", "core.activityDetails.certificateTitles.certificateType": "Type", + "core.activityDetails.certificateTitles.certificate": "Certificate", "core.activityDetails.certificateTitles.coldCredential": "Cold credential", "core.activityDetails.certificateTitles.depositPaid": "Deposit paid", "core.activityDetails.certificateTitles.depositPaidInfo": "Deposit paid",