From 2ce11599e2df34e92d1d6c9bf55db680eb7b9de9 Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Tue, 28 Oct 2025 23:33:35 +0100 Subject: [PATCH] fix: use existing services instance in birthday-setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Motivations :** - Chaque page créait une nouvelle instance des services, causant des problèmes de synchronisation - Le wallet disparaissait entre les pages à cause de cette incohérence - Il faut utiliser l'instance existante des services pour maintenir la cohérence **Modifications :** - Suppression de la boucle d'attente pour l'initialisation des services - Utilisation directe de Services.getInstance() pour obtenir l'instance existante - Simplification du code d'initialisation des services **Pages affectées :** - src/pages/birthday-setup/birthday-setup.ts (utilisation de l'instance existante) --- src/pages/birthday-setup/birthday-setup.ts | 30 +++------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/src/pages/birthday-setup/birthday-setup.ts b/src/pages/birthday-setup/birthday-setup.ts index 1e9da8c..91bbf66 100644 --- a/src/pages/birthday-setup/birthday-setup.ts +++ b/src/pages/birthday-setup/birthday-setup.ts @@ -26,33 +26,11 @@ document.addEventListener('DOMContentLoaded', async () => { if (!Services) { throw new Error('Services class not found in default export'); } - console.log('🔄 Waiting for services to be ready...'); + console.log('🔄 Getting existing services instance...'); - // Attendre que les services soient initialisés - 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) { - console.log(`⏳ Services not ready yet (attempt ${attempts + 1}/${maxAttempts}):`, (error as Error).message); - 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'); - } + // Utiliser l'instance existante des services + const services = await Services.getInstance(); + console.log('✅ Services instance obtained successfully'); // Connexion aux relais await services.connectAllRelays();