Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/i18n/locales/ar/onboarding.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"confirmWritten": "لقد كتبتها",
"createFailed": "فشل في إنشاء المحفظة",
"defaultWalletName": "المحفظة الرئيسية",
"walletSuffix": "محفظة",
"enterWallet": "دخول المحفظة",
"form": {
"agreementPrefix": "لقد قرأت ووافقت على",
Expand Down Expand Up @@ -197,4 +198,4 @@
"similarExists": "يوجد لون مشابه",
"auto": "تلقائي"
}
}
}
3 changes: 2 additions & 1 deletion src/i18n/locales/en/onboarding.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"confirmWritten": "I have written it down",
"createFailed": "Failed to create wallet",
"defaultWalletName": "Main Wallet",
"walletSuffix": "Wallet",
"enterWallet": "Enter Wallet",
"themeTitle": "Choose Card Theme",
"themeSubtitle": "Select a theme color for your wallet card",
Expand Down Expand Up @@ -197,4 +198,4 @@
"similarExists": "Similar color exists",
"auto": "Auto"
}
}
}
3 changes: 2 additions & 1 deletion src/i18n/locales/zh-CN/onboarding.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"wordIncorrect": "单词不正确",
"complete": "完成创建",
"defaultWalletName": "主钱包",
"walletSuffix": "钱包",
"createFailed": "创建钱包失败",
"themeTitle": "选择卡片主题",
"themeSubtitle": "为您的钱包卡片选择一个主题色",
Expand Down Expand Up @@ -197,4 +198,4 @@
"similarExists": "已有相似颜色",
"auto": "自动"
}
}
}
3 changes: 2 additions & 1 deletion src/i18n/locales/zh-TW/onboarding.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"confirmWritten": "我已抄寫完成",
"createFailed": "建立錢包失敗",
"defaultWalletName": "主錢包",
"walletSuffix": "錢包",
"enterWallet": "進入錢包",
"form": {
"agreementPrefix": "我已閱讀並同意",
Expand Down Expand Up @@ -197,4 +198,4 @@
"similarExists": "已有相似顏色",
"auto": "自動"
}
}
}
45 changes: 45 additions & 0 deletions src/lib/wallet-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Wallet Utilities
*
* Helper functions for wallet management
*/

import { wordlists } from 'bip39';

/** Locale to BIP39 wordlist mapping */
const LOCALE_WORDLIST_MAP: Record<string, string[] | undefined> = {
'zh-CN': wordlists.chinese_simplified,
'zh-TW': wordlists.chinese_traditional,
'ja': wordlists.japanese,
'ko': wordlists.korean,
};

/**
* Locales that don't use spaces between words
* (Chinese, Japanese, Korean - CJK languages)
*/
const NO_SPACE_LOCALES = ['zh-CN', 'zh-TW', 'ja', 'ko'];

/**
* Generate a random wallet name using BIP39 wordlist
* @param locale Current locale (e.g. 'zh-CN', 'en')
* @param suffix Localized suffix (e.g. '钱包', 'Wallet')
* @returns Generated wallet name (e.g. '爱钱包', 'Garden Wallet')
*/
export function generateWalletName(locale: string, suffix: string): string {
// Get wordlist for locale, fallback to English
const wordlist = LOCALE_WORDLIST_MAP[locale] ?? wordlists.english!;

// Pick a random word
const randomWord = wordlist[Math.floor(Math.random() * wordlist.length)];

// Capitalize first letter for non-CJK languages
const formattedWord = NO_SPACE_LOCALES.includes(locale)
? randomWord
: randomWord.charAt(0).toUpperCase() + randomWord.slice(1);

// CJK languages don't use spaces
const useSpace = !NO_SPACE_LOCALES.includes(locale);

return useSpace ? `${formattedWord} ${suffix}` : `${formattedWord}${suffix}`;
}
4 changes: 2 additions & 2 deletions src/pages/my-card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export function MyCardPage() {
}, [handleUsernameSave]);

// Snapdom share hook
const { isProcessing: isDownloading, download: handleDownload, share: handleShare, canShare } = useSnapdomShare(
const { isProcessing: isDownloading, download: handleDownload, share: handleShare } = useSnapdomShare(
cardRef,
{
filename: `my-card-${Date.now()}`,
Expand Down Expand Up @@ -197,7 +197,7 @@ export function MyCardPage() {
className="group mb-6 flex items-center gap-2 text-xl font-semibold"
>
<span>{displayName}</span>
<Pencil className="size-4 text-muted-foreground opacity-0 group-hover:opacity-100" />
<Pencil className="size-4 text-muted-foreground opacity-50 group-hover:opacity-100" />
</button>
)}

Expand Down
8 changes: 5 additions & 3 deletions src/pages/wallet/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import {
IconCircleKey as KeyRound,
IconCircleCheck as CheckCircle,
} from '@tabler/icons-react';
import { useChainConfigs, walletActions } from '@/stores';
import { useChainConfigs, walletActions, useLanguage } from '@/stores';
import { generateMnemonic } from '@/lib/crypto';
import { generateWalletName } from '@/lib/wallet-utils';
import { deriveWalletChainAddresses } from '@/services/chain-adapter';
import { deriveThemeHue } from '@/hooks/useWalletTheme';
import type { ChainConfig } from '@/services/chain-config';
Expand All @@ -31,6 +32,7 @@ export function WalletCreatePage() {
const { goBack, navigate } = useNavigation();
const { t } = useTranslation('onboarding');
const chainConfigs = useChainConfigs();
const currentLanguage = useLanguage();
const [step, setStep] = useState<Step>('pattern');
const [patternKey, setPatternKey] = useState('');
const [mnemonic] = useState<string[]>(() => {
Expand Down Expand Up @@ -122,7 +124,7 @@ export function WalletCreatePage() {

const wallet = await walletActions.createWallet(
{
name: t('create.defaultWalletName'),
name: generateWalletName(currentLanguage, t('create.walletSuffix')),
keyType: 'mnemonic',
address: primaryChain.address,
chain: primaryChain.chain,
Expand All @@ -138,7 +140,7 @@ export function WalletCreatePage() {
setCreatedWalletId(wallet.id);
setStep('theme');
} catch (error) {

} finally {
setIsCreating(false);
}
Expand Down