import { Show, createSignal, createEffect, onCleanup } from 'solid-js'; import type { Component } from 'solid-js'; import { Card } from '@/components/shared/Card'; import { copyToClipboard } from '@/utils/clipboard'; import { showError, showSuccess } from '@/utils/toast'; import { useTokenRevealState, dismissTokenReveal } from '@/stores/tokenReveal'; const formatSourceLabel = (value?: string) => { if (!value) return ''; return value .split(/[-_\s]+/) .filter(Boolean) .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)) .join(' '); }; export const TokenRevealDialog: Component = () => { const state = useTokenRevealState(); const [copied, setCopied] = createSignal(false); const handleDismiss = () => { dismissTokenReveal(); setCopied(false); }; const handleCopy = async (token: string) => { const success = await copyToClipboard(token); if (success) { setCopied(true); showSuccess('Token copied to clipboard'); setTimeout(() => setCopied(false), 2000); } else { showError('Failed to copy token'); } }; createEffect(() => { const current = state(); setCopied(false); if (!current) { return; } const onKeyDown = (event: KeyboardEvent) => { if (event.key === 'Escape') { handleDismiss(); } }; window.addEventListener('keydown', onKeyDown); onCleanup(() => window.removeEventListener('keydown', onKeyDown)); }); return ( {(tokenInfo) => { const info = tokenInfo(); const sourceLabel = formatSourceLabel(info.source); const recordName = info.record?.name?.trim() || 'Untitled token'; const hint = info.note || 'Copy this token now; Pulse will not display it again after you close this dialog.'; const tokenHint = info.record?.prefix && info.record?.suffix ? `${info.record.prefix}…${info.record.suffix}` : info.record?.prefix ? `${info.record.prefix}…` : info.record?.suffix ? `…${info.record.suffix}` : null; return (
); }} ); }; export default TokenRevealDialog;