Skip to content

Commit

Permalink
Remove overcomplicated type check in translations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan-Mahda committed Nov 5, 2024
1 parent 2f7dc24 commit 7e47281
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import Page from '@popup/popupX/shared/Page';
import { useTranslation } from 'react-i18next';
import i18n from '@popup/shell/i18n/i18n';
import Text from '@popup/popupX/shared/Text';
import Card from '@popup/popupX/shared/Card';
import Button from '@popup/popupX/shared/Button';
Expand Down Expand Up @@ -134,7 +135,7 @@ function Loader() {
}

export default withPasswordProtected(Loader, {
headingKey: 'privateKey.accountPrivateKey',
pageInfoKey: 'privateKey.passwordDescription',
submitKey: 'privateKey.showPrivateKey',
headingText: i18n.t('x:privateKey.accountPrivateKey'),
pageInfoText: i18n.t('x:privateKey.passwordDescription'),
submitText: i18n.t('x:privateKey.showPrivateKey'),
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import Button from '@popup/popupX/shared/Button';
import { useTranslation } from 'react-i18next';
import i18n from '@popup/shell/i18n';
import Page from '@popup/popupX/shared/Page';
import Text from '@popup/popupX/shared/Text';
import Card from '@popup/popupX/shared/Card';
Expand Down Expand Up @@ -50,7 +51,7 @@ function SeedPhrase() {
}

export default withPasswordProtected(SeedPhrase, {
headingKey: 'seedPhrase.seedPhrase',
pageInfoKey: 'seedPhrase.passwordDescription',
submitKey: 'seedPhrase.showSeedPhrase',
headingText: i18n.t('x:seedPhrase.seedPhrase'),
pageInfoText: i18n.t('x:seedPhrase.passwordDescription'),
submitText: i18n.t('x:seedPhrase.showSeedPhrase'),
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import FormPassword from '@popup/popupX/shared/Form/Password';
import Form from '@popup/popupX/shared/Form/Form';
import { sessionPasscodeAtom } from '@popup/store/settings';
import { useForm } from '@popup/shared/Form';
import { TranslationKeyX } from '@popup/shell/i18n/i18n';

type FormValues = {
currentPasscode: string;
};

export type PasswordProtectConfigType = {
headingKey: TranslationKeyX;
pageInfoKey: TranslationKeyX;
submitKey: TranslationKeyX;
headingText: string;
pageInfoText: string;
submitText: string;
};

type PasswordProtectProps = {
Expand All @@ -28,10 +27,8 @@ type PasswordProtectProps = {

export default function PasswordProtect({
setPasswordConfirmed,
config: { headingKey, pageInfoKey, submitKey },
config: { headingText, pageInfoText, submitText },
}: PasswordProtectProps) {
const { t: tUse } = useTranslation('x');
const t = (key: TranslationKeyX) => tUse(key) as unknown as string;
const { t: tPasscode } = useTranslation('x', { keyPrefix: 'sharedX.form.password' });
const passcode = useAtomValue(sessionPasscodeAtom);
const form = useForm<FormValues>();
Expand All @@ -46,9 +43,9 @@ export default function PasswordProtect({

return (
<Page className="confirm-password-x">
<Page.Top heading={t(headingKey)} />
<Page.Top heading={headingText} />
<Page.Main>
<Text.MainRegular>{t(pageInfoKey)}</Text.MainRegular>
<Text.MainRegular>{pageInfoText}</Text.MainRegular>
<Form id="confirm-password-form" onSubmit={handleSubmit} formMethods={form}>
{(f) => {
return (
Expand All @@ -70,7 +67,7 @@ export default function PasswordProtect({
<Button.Main
form="confirm-password-form"
type="submit"
label={t(submitKey)}
label={submitText}
disabled={form.formState.isSubmitting}
/>
</Page.Footer>
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions packages/browser-wallet/src/popup/shell/i18n/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import countries from 'i18n-iso-countries';
import { ObjectPath } from '@popup/popupX/shared/utils/typescriptHelpers';

import en from './locales/en';
import da from './locales/da';

countries.registerLocale(require('i18n-iso-countries/langs/en.json'));
countries.registerLocale(require('i18n-iso-countries/langs/da.json'));

export type TranslationKeyX = ObjectPath<typeof en.x>;
export const defaultNS: keyof typeof en = 'shared';
const ns: Array<keyof typeof en> = Object.keys(en) as Array<keyof typeof en>;

Expand Down

0 comments on commit 7e47281

Please sign in to comment.