import { wordlist } from "@scure/bip39/wordlists/english.js"; import { useState } from "react"; import RevealPasswordToggle from "src/components/password/RevealPasswordToggle"; import { Card, CardContent, CardHeader, CardTitle, } from "src/components/ui/card"; import { InputWithAdornment } from "src/components/ui/custom/input-with-adornment"; type MnemonicInputsProps = { mnemonic?: string; setMnemonic?(mnemonic: string): void; readOnly?: boolean; asCard?: boolean; }; export default function MnemonicInputs({ mnemonic, setMnemonic, readOnly, children, asCard = true, }: React.PropsWithChildren) { const words = mnemonic?.split(" ") || []; while (words.length < 12) { words.push(""); } while (words.length > 12) { words.pop(); } const [revealedIndex, setRevealedIndex] = useState( undefined ); const content = ( <>
{words.map((word, i) => { const isRevealed = revealedIndex === i; const inputId = `mnemonic-word-${i}`; return (
{i + 1}.
setRevealedIndex(i)} onBlur={() => setRevealedIndex(undefined)} className="w-32 sm:w-44 border-[#E4E4E7] text-muted-foreground" list={readOnly ? undefined : "wordlist"} value={isRevealed ? word : word.length ? "•••••" : ""} onChange={(e) => { if (revealedIndex !== i) { return; } words[i] = e.target.value; setMnemonic?.( words .map((word) => word.trim()) .join(" ") .trim() ); }} endAdornment={ { if (passwordView) { document.getElementById(inputId)?.focus(); } }} iconClass="text-muted-foreground" /> } />
); })}
{!readOnly && ( {wordlist.map((word) => ( )} {children} ); if (!asCard) { return content; } return ( <> Recovery Phrase {content} ); }