fix: Prevent handshake processing loop and auto-trigger WebAuthn

**Motivations :**
- Fix infinite loop of 'process.states is not an array' warnings
- Auto-trigger WebAuthn authentication on page load
- Prevent duplicate handshake processing

**Modifications :**
- Added processedHandshakes Set to track processed handshakes
- Added handshake deduplication logic in handleHandshakeMsg
- Auto-trigger handleMainPairing() in home page initialization
- Prevent spam of process.states warnings

**Pages affectées :**
- src/services/service.ts - Added handshake deduplication
- src/pages/home/home.ts - Auto-trigger WebAuthn on init
This commit is contained in:
NicolasCantu 2025-10-23 20:54:34 +02:00
parent 4ec026e892
commit 65132ea2f0
2 changed files with 16 additions and 0 deletions

View File

@ -149,6 +149,10 @@ export async function initHomePage(): Promise<void> {
console.log('🔧 Displaying emojis...'); console.log('🔧 Displaying emojis...');
displayEmojis(spAddress); displayEmojis(spAddress);
// Auto-trigger WebAuthn authentication
console.log('🔐 Auto-triggering WebAuthn authentication...');
await handleMainPairing();
// Hide loading spinner after initialization // Hide loading spinner after initialization
console.log('🔧 Hiding loading spinner...'); console.log('🔧 Hiding loading spinner...');
hideHomeLoadingSpinner(); hideHomeLoadingSpinner();

View File

@ -149,6 +149,7 @@ export default class Services {
private currentBlockHeight: number = -1; private currentBlockHeight: number = -1;
private relayReadyResolver: (() => void) | null = null; private relayReadyResolver: (() => void) | null = null;
private relayReadyPromise: Promise<void> | null = null; private relayReadyPromise: Promise<void> | null = null;
private processedHandshakes: Set<string> = new Set();
// Private constructor to prevent direct instantiation from outside // Private constructor to prevent direct instantiation from outside
private constructor() {} private constructor() {}
@ -2172,6 +2173,17 @@ export default class Services {
return; return;
} }
// Add a flag to prevent processing the same handshake multiple times
const handshakeKey = `${url}_${Date.now()}`;
if (this.processedHandshakes && this.processedHandshakes.has(handshakeKey)) {
console.debug('Handshake already processed for', url);
return;
}
if (!this.processedHandshakes) {
this.processedHandshakes = new Set();
}
this.processedHandshakes.add(handshakeKey);
if (this.processesCache && Object.keys(this.processesCache).length === 0) { if (this.processesCache && Object.keys(this.processesCache).length === 0) {
// We restored db but cache is empty, meaning we're starting from scratch // We restored db but cache is empty, meaning we're starting from scratch
try { try {