fix: wait for handshake before checking chain_tip and add logs for debugging
**Motivations :** - La vérification de chain_tip se fait trop tôt, avant que le handshake arrive - Le code ne continue pas après updateDeviceBlockHeight(), besoin de logs pour comprendre pourquoi - Ajouter des logs détaillés pour tracer le flux d'exécution **Modifications :** - Déplacer la vérification de chain_tip après l'attente du handshake dans birthday-setup.ts - Améliorer la condition de vérification pour attendre chain_tip > 0 - Ajouter des logs détaillés à chaque étape dans birthday-setup.ts - Ajouter un return explicite à la fin de updateDeviceBlockHeight() pour garantir qu'elle se termine correctement - Ajouter des logs avant et après updateDeviceBlockHeight() pour tracer l'exécution **Pages affectées :** - src/pages/birthday-setup/birthday-setup.ts (attente du handshake avant vérification) - src/services/service.ts (return explicite et logs)
This commit is contained in:
parent
a52baf07e0
commit
cd368cf667
@ -111,35 +111,20 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
// Connexion aux relais
|
// Connexion aux relais
|
||||||
await services.connectAllRelays();
|
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
|
// 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<void>((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
const timeout = setTimeout(() => {
|
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
|
}, 15000); // 15 secondes de timeout
|
||||||
|
|
||||||
const checkBlockHeight = () => {
|
const checkBlockHeight = () => {
|
||||||
const blockHeight = services.getCurrentBlockHeight();
|
const blockHeight = services.getCurrentBlockHeight();
|
||||||
if (blockHeight !== -1) {
|
if (blockHeight !== -1 && blockHeight > 0) {
|
||||||
console.log(`✅ Block height set: ${blockHeight}`);
|
console.log(`✅ Block height set from handshake: ${blockHeight}`);
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
@ -150,14 +135,34 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
checkBlockHeight();
|
checkBlockHeight();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 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
|
// Mettre à jour la date anniversaire du wallet
|
||||||
|
updateStatus('🎂 Mise à jour de la date anniversaire...', 'loading');
|
||||||
|
updateProgress(60);
|
||||||
|
console.log('🔄 Calling updateDeviceBlockHeight()...');
|
||||||
await services.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
|
// 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();
|
const updatedWallet = await services.getDeviceFromDatabase();
|
||||||
if (updatedWallet?.sp_wallet?.birthday && updatedWallet.sp_wallet.birthday > 0) {
|
if (updatedWallet?.sp_wallet?.birthday && updatedWallet.sp_wallet.birthday > 0) {
|
||||||
console.log('✅ Birthday updated successfully:', updatedWallet.sp_wallet.birthday);
|
console.log('✅ Birthday updated successfully:', updatedWallet.sp_wallet.birthday);
|
||||||
} else {
|
} 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}`);
|
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);
|
updateProgress(100);
|
||||||
|
|
||||||
console.log('🎉 Birthday setup completed successfully - redirecting to block sync');
|
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
|
// Rediriger vers la page de synchronisation des blocs
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
console.log('🔄 Executing redirect now...');
|
||||||
window.location.href = '/src/pages/block-sync/block-sync.html';
|
window.location.href = '/src/pages/block-sync/block-sync.html';
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
|
|||||||
@ -2345,6 +2345,8 @@ export default class Services {
|
|||||||
} else {
|
} else {
|
||||||
throw new Error(`Final save verification failed: expected last_scan ${this.currentBlockHeight}, got ${finalDevice?.sp_wallet?.last_scan}`);
|
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) {
|
} catch (e) {
|
||||||
throw new Error(`Failed to save updated device: ${e}`);
|
throw new Error(`Failed to save updated device: ${e}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user