import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { QRCodeSVG } from 'qrcode.react'; import styles from './Create.module.css'; interface CreateSessionResult { success: boolean; sessionId?: string; inviteCode?: string; error?: string; } export default function Create() { const navigate = useNavigate(); const [walletName, setWalletName] = useState(''); const [thresholdT, setThresholdT] = useState(3); const [thresholdN, setThresholdN] = useState(5); const [participantName, setParticipantName] = useState(''); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const [result, setResult] = useState(null); const [step, setStep] = useState<'config' | 'creating' | 'created'>('config'); const handleCreateSession = async () => { if (!walletName.trim()) { setError('请输入钱包名称'); return; } if (!participantName.trim()) { setError('请输入您的名称'); return; } if (thresholdT > thresholdN) { setError('签名阈值不能大于参与方总数'); return; } if (thresholdT < 1) { setError('签名阈值至少为 1'); return; } if (thresholdN < 2) { setError('参与方总数至少为 2'); return; } setStep('creating'); setIsLoading(true); setError(null); try { const createResult = await window.electronAPI.grpc.createSession({ walletName: walletName.trim(), thresholdT, thresholdN, initiatorName: participantName.trim(), }); if (createResult.success) { setResult(createResult); setStep('created'); } else { setError(createResult.error || '创建会话失败'); setStep('config'); } } catch (err) { setError('创建会话失败,请检查网络连接'); setStep('config'); } finally { setIsLoading(false); } }; const handleCopyInviteCode = async () => { if (result?.inviteCode) { try { await navigator.clipboard.writeText(result.inviteCode); // 可以添加复制成功的提示 } catch (err) { console.error('Failed to copy:', err); } } }; const handleGoToSession = () => { if (result?.sessionId) { navigate(`/session/${result.sessionId}`); } }; return (

创建共管钱包

3-of-5 混合托管模式 - 设置钱包参数并邀请参与方

{step === 'config' && (
{/* 混合托管说明 */}
ℹ️
混合托管模式说明
  • 5 个密钥份额: 2 个平台备份 + 3 个用户持有
  • 正常签名: 仅需 3 位用户共同签名
  • 密钥恢复: 允许 2 位用户丢失密钥,可使用平台备份轮换
  • 安全保障: 平台备份仅用于紧急恢复,不参与日常签名
setWalletName(e.target.value)} placeholder="为您的共管钱包命名" className={styles.input} disabled={isLoading} />
签名阈值 (T)
{thresholdT}
of
参与方总数 (N)
{thresholdN}

需要 {thresholdT} 个参与方共同签名才能执行交易 (其中 2 个由平台托管用于备份)

setParticipantName(e.target.value)} placeholder="输入您的名称(其他参与者可见)" className={styles.input} disabled={isLoading} />
{error &&
{error}
}
)} {step === 'creating' && (

正在创建会话...

)} {step === 'created' && result && (

会话创建成功

{/* QR Code for mobile scanning */}

使用手机 App 扫码加入

{result.inviteCode}

将此邀请码分享给其他参与方,他们可以使用此码加入会话

)}
); }