import { useState } from 'react'; import { Lock, LockOpen, ShieldCheck } from 'lucide-react'; import { toneFill } from '@/components/Data/tone'; import { formatCountdown } from './format'; import { useLockCountdown } from './useLockCountdown'; import { useLockActions, useWalletConfig } from './useWalletData'; import { UnlockDialog } from './dialogs/UnlockDialog'; // The lock indicator. Locked is the resting state and reads as reassurance, not as an error — a watch-only // wallet with no key material in memory is the whole point of the design, so it is never styled as a // warning and never blocks the screen behind it. // // The countdown ticks locally (useLockCountdown) and flips to locked at zero without waiting for the poll. type LockBadgeProps = { walletId: number | null; walletName: string; /** Compact drops the action button — for the panel header, where there is no room. */ compact?: boolean; }; export const LockBadge = ({ walletId, walletName, compact = false }: LockBadgeProps) => { const { hasSeed, unlocked, secondsRemaining, isLoading } = useLockCountdown(walletId); const { config } = useWalletConfig(); const { lock } = useLockActions(walletId); const [unlockOpen, setUnlockOpen] = useState(false); // A wallet with no seed — a remote node, a custodial account — has nothing to lock. Showing it a // padlock would imply a protection it does not have. if (walletId == null || hasSeed === false) { if (isLoading || hasSeed == null) return null; return ( no seed held ); } if (hasSeed == null) return null; return ( <>
{unlocked ? : } {unlocked ? formatCountdown(secondsRemaining) : 'locked'} {!compact && (unlocked ? ( ) : ( ))}
{unlockOpen && ( )} ); }; /** * The inline "you need to unlock for this" prompt, used by the signing surfaces only. Renders its children * disabled-in-place rather than replacing the screen, so you can still read the form you are about to * submit while the wallet is locked. */ type UnlockPromptProps = { walletId: number; walletName: string; className?: string }; export const UnlockPrompt = ({ walletId, walletName, className = '' }: UnlockPromptProps) => { const { config } = useWalletConfig(); const [open, setOpen] = useState(false); return ( <>
This wallet is locked. Signing needs the passphrase — everything else on this screen already works.
{open && ( )} ); };