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