feat(co-sign): add debug logs for auto-join flow in CoSignJoin

Add console.log statements to trace the auto-join logic:
- Log loaded shares with sessionId
- Log auto-select share matching check
- Log auto-join conditions and share match status
- Log validateInviteCode results including joinToken
- Log handleJoinSession parameters

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-31 03:33:10 -08:00
parent cd63643ba4
commit da189ca3d4
1 changed files with 59 additions and 0 deletions

View File

@ -51,6 +51,11 @@ export default function CoSignJoin() {
const result = await window.electronAPI.storage.listShares(); const result = await window.electronAPI.storage.listShares();
// 兼容不同返回格式 // 兼容不同返回格式
const shareList = Array.isArray(result) ? result : ((result as any)?.data || []); const shareList = Array.isArray(result) ? result : ((result as any)?.data || []);
console.log('[CoSignJoin] Loaded shares:', shareList.map((s: Share) => ({
id: s.id,
sessionId: s.sessionId,
walletName: s.walletName,
})));
setShares(shareList); setShares(shareList);
} catch (err) { } catch (err) {
console.error('Failed to load shares:', err); console.error('Failed to load shares:', err);
@ -71,17 +76,36 @@ export default function CoSignJoin() {
if (sessionInfo && shares.length > 0 && !selectedShareId) { if (sessionInfo && shares.length > 0 && !selectedShareId) {
// 尝试找到匹配的 share基于 keygen session ID // 尝试找到匹配的 share基于 keygen session ID
const matchingShare = shares.find(s => s.sessionId === sessionInfo.keygenSessionId); const matchingShare = shares.find(s => s.sessionId === sessionInfo.keygenSessionId);
console.log('[CoSignJoin] Auto-select share check:', {
keygenSessionId: sessionInfo.keygenSessionId,
sharesSessionIds: shares.map(s => s.sessionId),
matchingShare: matchingShare ? { id: matchingShare.id, sessionId: matchingShare.sessionId } : null,
});
if (matchingShare) { if (matchingShare) {
console.log('[CoSignJoin] Auto-selecting matching share:', matchingShare.id);
setSelectedShareId(matchingShare.id); setSelectedShareId(matchingShare.id);
} else if (shares.length === 1) { } else if (shares.length === 1) {
// 如果只有一个 share自动选择 // 如果只有一个 share自动选择
console.log('[CoSignJoin] Auto-selecting only share:', shares[0].id);
setSelectedShareId(shares[0].id); setSelectedShareId(shares[0].id);
} else {
console.log('[CoSignJoin] No matching share found, user must select manually');
} }
} }
}, [sessionInfo, shares, selectedShareId]); }, [sessionInfo, shares, selectedShareId]);
// 自动加入 // 自动加入
useEffect(() => { useEffect(() => {
console.log('[CoSignJoin] Auto-join check:', {
step,
hasSessionInfo: !!sessionInfo,
hasJoinToken: !!joinToken,
selectedShareId,
autoJoinAttempted,
isLoading,
sharesCount: shares.length,
});
if ( if (
step === 'select_share' && step === 'select_share' &&
sessionInfo && sessionInfo &&
@ -92,14 +116,24 @@ export default function CoSignJoin() {
) { ) {
// 找到匹配的 share 且未尝试过自动加入,则自动加入 // 找到匹配的 share 且未尝试过自动加入,则自动加入
const matchingShare = shares.find(s => s.sessionId === sessionInfo.keygenSessionId); const matchingShare = shares.find(s => s.sessionId === sessionInfo.keygenSessionId);
console.log('[CoSignJoin] Auto-join conditions met, checking share match:', {
keygenSessionId: sessionInfo.keygenSessionId,
matchingShareId: matchingShare?.id,
selectedShareId,
isMatch: matchingShare && matchingShare.id === selectedShareId,
});
if (matchingShare && matchingShare.id === selectedShareId) { if (matchingShare && matchingShare.id === selectedShareId) {
console.log('[CoSignJoin] Auto-joining session...');
setAutoJoinAttempted(true); setAutoJoinAttempted(true);
handleJoinSession(); handleJoinSession();
} else {
console.log('[CoSignJoin] Share mismatch, not auto-joining');
} }
} }
}, [step, sessionInfo, joinToken, selectedShareId, autoJoinAttempted, isLoading, shares]); }, [step, sessionInfo, joinToken, selectedShareId, autoJoinAttempted, isLoading, shares]);
const handleValidateCode = async (codeToValidate: string) => { const handleValidateCode = async (codeToValidate: string) => {
console.log('[CoSignJoin] handleValidateCode called:', codeToValidate);
if (!codeToValidate.trim()) { if (!codeToValidate.trim()) {
setError('请输入邀请码'); setError('请输入邀请码');
return; return;
@ -110,16 +144,26 @@ export default function CoSignJoin() {
try { try {
const result: ValidateResult = await window.electronAPI.cosign.validateInviteCode(codeToValidate); const result: ValidateResult = await window.electronAPI.cosign.validateInviteCode(codeToValidate);
console.log('[CoSignJoin] validateInviteCode result:', {
success: result.success,
sessionInfo: result.sessionInfo,
hasJoinToken: !!result.joinToken,
joinTokenPreview: result.joinToken?.substring(0, 20) + '...',
error: result.error,
});
if (result.success && result.sessionInfo) { if (result.success && result.sessionInfo) {
setSessionInfo(result.sessionInfo); setSessionInfo(result.sessionInfo);
if (result.joinToken) { if (result.joinToken) {
setJoinToken(result.joinToken); setJoinToken(result.joinToken);
} else {
console.warn('[CoSignJoin] WARNING: No joinToken in response!');
} }
setStep('select_share'); setStep('select_share');
} else { } else {
setError(result.error || '无效的邀请码'); setError(result.error || '无效的邀请码');
} }
} catch (err) { } catch (err) {
console.error('[CoSignJoin] validateInviteCode error:', err);
setError('验证邀请码失败,请检查网络连接'); setError('验证邀请码失败,请检查网络连接');
} finally { } finally {
setIsLoading(false); setIsLoading(false);
@ -127,6 +171,12 @@ export default function CoSignJoin() {
}; };
const handleJoinSession = async () => { const handleJoinSession = async () => {
console.log('[CoSignJoin] handleJoinSession called:', {
hasSessionInfo: !!sessionInfo,
hasJoinToken: !!joinToken,
selectedShareId,
});
if (!sessionInfo) { if (!sessionInfo) {
setError('会话信息不完整'); setError('会话信息不完整');
return; return;
@ -146,6 +196,14 @@ export default function CoSignJoin() {
setIsLoading(true); setIsLoading(true);
setError(null); setError(null);
console.log('[CoSignJoin] Calling cosign.joinSession with:', {
sessionId: sessionInfo.sessionId,
shareId: selectedShareId,
walletName: sessionInfo.walletName,
messageHash: sessionInfo.messageHash,
threshold: sessionInfo.threshold,
});
try { try {
const result = await window.electronAPI.cosign.joinSession({ const result = await window.electronAPI.cosign.joinSession({
sessionId: sessionInfo.sessionId, sessionId: sessionInfo.sessionId,
@ -156,6 +214,7 @@ export default function CoSignJoin() {
messageHash: sessionInfo.messageHash, messageHash: sessionInfo.messageHash,
threshold: sessionInfo.threshold, threshold: sessionInfo.threshold,
}); });
console.log('[CoSignJoin] joinSession result:', result);
if (result.success) { if (result.success) {
navigate(`/cosign/session/${sessionInfo.sessionId}`); navigate(`/cosign/session/${sessionInfo.sessionId}`);