diff --git a/src/pages/birthday-setup/birthday-setup.ts b/src/pages/birthday-setup/birthday-setup.ts index 4ed80cd..089db5e 100644 --- a/src/pages/birthday-setup/birthday-setup.ts +++ b/src/pages/birthday-setup/birthday-setup.ts @@ -110,36 +110,21 @@ document.addEventListener('DOMContentLoaded', async () => { // Connexion aux relais await services.connectAllRelays(); - - // Vérifier que les relais sont connectés - const currentBlockHeight = services.getCurrentBlockHeight(); - if (currentBlockHeight !== -1) { - console.log('✅ Relays connected successfully, chain_tip:', currentBlockHeight); - } else { - throw new Error('Relays connected but chain_tip not set'); - } - - // Les relais sont déjà prêts après connectAllRelays - // Vérifier que le handshake a été reçu - if (currentBlockHeight > 0) { - console.log('✅ Communication handshake completed, chain_tip:', currentBlockHeight); - } else { - throw new Error('Handshake not received or chain_tip not set'); - } - - // Attendre que la hauteur de bloc soit définie avant de mettre à jour la date anniversaire - updateStatus('⏳ Attente de la synchronisation avec le réseau...', 'loading'); - + // Attendre que la hauteur de bloc soit définie via le handshake + updateStatus('⏳ Attente de la synchronisation avec le réseau...', 'loading'); + updateProgress(40); + + // Attendre que le handshake arrive et que chain_tip soit défini await new Promise((resolve, reject) => { const timeout = setTimeout(() => { - reject(new Error('Timeout waiting for block height')); + reject(new Error('Timeout waiting for block height from handshake')); }, 15000); // 15 secondes de timeout const checkBlockHeight = () => { const blockHeight = services.getCurrentBlockHeight(); - if (blockHeight !== -1) { - console.log(`✅ Block height set: ${blockHeight}`); + if (blockHeight !== -1 && blockHeight > 0) { + console.log(`✅ Block height set from handshake: ${blockHeight}`); clearTimeout(timeout); resolve(); } else { @@ -150,14 +135,34 @@ document.addEventListener('DOMContentLoaded', async () => { checkBlockHeight(); }); - // Mettre à jour la date anniversaire du wallet - await services.updateDeviceBlockHeight(); + // Vérifier que les relais sont connectés et que le handshake a été reçu + const currentBlockHeight = services.getCurrentBlockHeight(); + if (currentBlockHeight !== -1 && currentBlockHeight > 0) { + console.log('✅ Relays connected successfully, chain_tip:', currentBlockHeight); + console.log('✅ Communication handshake completed, chain_tip:', currentBlockHeight); + } else { + throw new Error('Handshake not received or chain_tip not set'); + } + // Mettre à jour la date anniversaire du wallet + updateStatus('🎂 Mise à jour de la date anniversaire...', 'loading'); + updateProgress(60); + console.log('🔄 Calling updateDeviceBlockHeight()...'); + await services.updateDeviceBlockHeight(); + console.log('✅ updateDeviceBlockHeight() completed successfully'); + // Vérifier que le birthday a bien été mis à jour en récupérant le wallet depuis la base + updateStatus('🔍 Vérification de la mise à jour...', 'loading'); + updateProgress(70); + console.log('🔄 Verifying birthday update...'); const updatedWallet = await services.getDeviceFromDatabase(); if (updatedWallet?.sp_wallet?.birthday && updatedWallet.sp_wallet.birthday > 0) { console.log('✅ Birthday updated successfully:', updatedWallet.sp_wallet.birthday); } else { + console.error('❌ Birthday update verification failed:', { + birthday: updatedWallet?.sp_wallet?.birthday, + hasSpWallet: !!updatedWallet?.sp_wallet + }); throw new Error(`Birthday update verification failed: expected birthday > 0, got ${updatedWallet?.sp_wallet?.birthday}`); } @@ -166,9 +171,12 @@ document.addEventListener('DOMContentLoaded', async () => { updateProgress(100); console.log('🎉 Birthday setup completed successfully - redirecting to block sync'); + console.log('📍 Target URL: /src/pages/block-sync/block-sync.html'); + console.log('⏰ Redirecting in 1 second...'); // Rediriger vers la page de synchronisation des blocs setTimeout(() => { + console.log('🔄 Executing redirect now...'); window.location.href = '/src/pages/block-sync/block-sync.html'; }, 1000); diff --git a/src/services/service.ts b/src/services/service.ts index 3b24a45..6fa6d6a 100755 --- a/src/services/service.ts +++ b/src/services/service.ts @@ -2345,6 +2345,8 @@ export default class Services { } else { throw new Error(`Final save verification failed: expected last_scan ${this.currentBlockHeight}, got ${finalDevice?.sp_wallet?.last_scan}`); } + console.log('✅ updateDeviceBlockHeight completed successfully for new device'); + return; } catch (e) { throw new Error(`Failed to save updated device: ${e}`); }