Skip to content

Commit

Permalink
chore(extension): add typings for core and cardano packages
Browse files Browse the repository at this point in the history
  • Loading branch information
vetalcore committed May 14, 2024
1 parent 8cf89f4 commit 247d393
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
10 changes: 10 additions & 0 deletions packages/cardano/src/ui/typings/i18next.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'i18next';
import type { Translations } from '@lace/translation';

declare module 'i18next' {
interface CustomTypeOptions {
resources: {
translation: Translations;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -193,7 +194,7 @@ export const AssetActivityItem = ({
<h6 data-testid="transaction-type" className={styles.title}>
{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)}
</h6>
{descriptionContent}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '';
Expand Down Expand Up @@ -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' && {
Expand All @@ -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' && {
Expand Down Expand Up @@ -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' && {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/ui/components/AssetInput/AssetInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,7 +39,7 @@ export interface AssetInputProps {
hasReachedMaxAmount?: boolean;
focused?: boolean;
onBlurErrors?: Set<string>;
getErrorMessage: (message: string) => string;
getErrorMessage: (message: string) => TranslationKey;
setFocusInput?: (input?: string) => void;
setFocus?: (focus: boolean) => void;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<number, string> = {
export const passwordStrengthFeedbackMap: Record<number, TranslationKey> = {
0: 'core.walletNameAndPasswordSetupStep.firstLevelPasswordStrengthFeedback',
1: 'core.walletNameAndPasswordSetupStep.firstLevelPasswordStrengthFeedback',
2: 'core.walletNameAndPasswordSetupStep.secondLevelPasswordStrengthFeedback'
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/ui/typings/i18next.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'i18next';
import type { Translations } from '@lace/translation';

declare module 'i18next' {
interface CustomTypeOptions {
resources: {
translation: Translations;
};
}
}
1 change: 1 addition & 0 deletions packages/translation/src/lib/translations/core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 247d393

Please sign in to comment.