diff --git a/src/pages/block-sync/block-sync.ts b/src/pages/block-sync/block-sync.ts index 917ca91..3cf932f 100644 --- a/src/pages/block-sync/block-sync.ts +++ b/src/pages/block-sync/block-sync.ts @@ -73,6 +73,50 @@ document.addEventListener("DOMContentLoaded", async () => { throw new Error('Wallet found but missing required data (sp_wallet or birthday)'); } + // Étape 2: Initialisation des services + updateStatus('🔄 Initialisation des services...', 'loading'); + updateProgress(20); + + const { default: Services } = await import('../../services/service'); + if (!Services) { + throw new Error('Services class not found in default export'); + } + + console.log('🔄 Waiting for services to be ready...'); + let attempts = 0; + const maxAttempts = 30; + const delayMs = 2000; + + let services; + while (attempts < maxAttempts) { + try { + console.log(`🔄 Attempting to get services (attempt ${attempts + 1}/${maxAttempts})...`); + services = await Services.getInstance(); + console.log('✅ Services initialized successfully'); + break; + } catch (error) { + const errorMessage = error instanceof Error ? error.message : String(error); + console.log(`⏳ Services not ready yet (attempt ${attempts + 1}/${maxAttempts}):`, errorMessage); + + // Si c'est une erreur de mémoire, arrêter immédiatement + if (errorMessage.includes('Out of memory') || errorMessage.includes('insufficient memory')) { + console.error('🚫 Memory error detected - stopping retry attempts'); + updateStatus('❌ Erreur: Mémoire insuffisante. Veuillez actualiser la page.', 'error'); + throw new Error('WebAssembly initialization failed due to insufficient memory. Please refresh the page.'); + } + + attempts++; + if (attempts >= maxAttempts) { + throw new Error(`Services failed to initialize after ${maxAttempts} attempts.`); + } + await new Promise(resolve => setTimeout(resolve, delayMs)); + } + } + + if (!services) { + throw new Error('Services not initialized'); + } + // Vérifier que le birthday est configuré (> 0) if (!wallet.sp_wallet.birthday || wallet.sp_wallet.birthday === 0) { console.log('⚠️ Birthday not configured (birthday = 0), redirecting to birthday-setup...'); diff --git a/src/services/iframe-pairing.service.ts b/src/services/iframe-pairing.service.ts index 0e00515..fa761f5 100644 --- a/src/services/iframe-pairing.service.ts +++ b/src/services/iframe-pairing.service.ts @@ -1,7 +1,6 @@ import { MessageType } from '../models/process.model'; import Services from './service'; import { - // generateWordsDisplay, // Unused import discoverAndJoinPairingProcessWithWords, prepareAndSendPairingTx, } from '../utils/sp-address.utils'; diff --git a/src/services/pairing.service.ts b/src/services/pairing.service.ts index 479dac3..0ac8576 100644 --- a/src/services/pairing.service.ts +++ b/src/services/pairing.service.ts @@ -2,12 +2,10 @@ * PairingService - Service spécialisé pour le pairing * Gère la logique métier du pairing sans couplage direct */ -// import { Device } from '../../pkg/sdk_client'; import { DeviceRepository } from '../repositories/device.repository'; import { ProcessRepository } from '../repositories/process.repository'; import { eventBus } from './event-bus'; import { secureLogger } from './secure-logger'; -// import { secureKeyManager } from './secure-key-manager'; import { SecureCredentialsService } from './secure-credentials.service'; import { CredentialData } from './credentials/types';