**Motivations :** - L'erreur 'Current block height not set' se produit car updateDeviceBlockHeight est appelé avant que le handshake soit complètement traité - Il faut attendre que this.currentBlockHeight soit défini avant de mettre à jour la date anniversaire **Modifications :** - Ajout de la méthode publique getCurrentBlockHeight() dans Services - Modification de birthday-setup.ts pour attendre que la hauteur de bloc soit définie - Ajout d'une boucle d'attente avec timeout pour s'assurer que le handshake est traité **Pages affectées :** - src/services/service.ts (getCurrentBlockHeight) - src/pages/birthday-setup/birthday-setup.ts (attente de la hauteur de bloc)
145 lines
4.8 KiB
HTML
145 lines
4.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Test Birthday Setup</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
}
|
|
.log {
|
|
background: #f5f5f5;
|
|
border: 1px solid #ddd;
|
|
padding: 10px;
|
|
margin: 10px 0;
|
|
border-radius: 4px;
|
|
font-family: monospace;
|
|
white-space: pre-wrap;
|
|
max-height: 400px;
|
|
overflow-y: auto;
|
|
}
|
|
button {
|
|
background: #007bff;
|
|
color: white;
|
|
border: none;
|
|
padding: 10px 20px;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
margin: 5px;
|
|
}
|
|
button:hover {
|
|
background: #0056b3;
|
|
}
|
|
button:disabled {
|
|
background: #ccc;
|
|
cursor: not-allowed;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>Test Birthday Setup - Debug Device Not Found</h1>
|
|
|
|
<div>
|
|
<button onclick="testWalletCreation()">1. Créer Wallet</button>
|
|
<button onclick="testDeviceRetrieval()">2. Récupérer Device</button>
|
|
<button onclick="testBirthdaySetup()">3. Test Birthday Setup</button>
|
|
<button onclick="clearLogs()">Effacer Logs</button>
|
|
</div>
|
|
|
|
<div id="logs" class="log"></div>
|
|
|
|
<script type="module">
|
|
import Services from './src/services/service.js';
|
|
import { DATABASE_CONFIG } from './src/services/database-config.js';
|
|
|
|
const logs = document.getElementById('logs');
|
|
|
|
function log(message) {
|
|
const timestamp = new Date().toLocaleTimeString();
|
|
logs.textContent += `[${timestamp}] ${message}\n`;
|
|
logs.scrollTop = logs.scrollHeight;
|
|
console.log(message);
|
|
}
|
|
|
|
function clearLogs() {
|
|
logs.textContent = '';
|
|
}
|
|
|
|
window.clearLogs = clearLogs;
|
|
|
|
async function testWalletCreation() {
|
|
log('🔄 Test: Création du wallet...');
|
|
try {
|
|
// Simuler la création du wallet comme dans wallet-setup.ts
|
|
const services = await Services.getInstance();
|
|
log('✅ Services initialisés');
|
|
|
|
// Créer un device avec le SDK
|
|
const device = services.sdkClient.create_device(0);
|
|
log('✅ Device créé avec le SDK');
|
|
|
|
// Sauvegarder le device
|
|
await services.saveDeviceInDatabase(device);
|
|
log('✅ Device sauvegardé dans la base de données');
|
|
|
|
log('🎉 Test de création du wallet réussi!');
|
|
} catch (error) {
|
|
log(`❌ Erreur lors de la création du wallet: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
async function testDeviceRetrieval() {
|
|
log('🔄 Test: Récupération du device...');
|
|
try {
|
|
const services = await Services.getInstance();
|
|
log('✅ Services initialisés');
|
|
|
|
const device = await services.getDeviceFromDatabase();
|
|
if (device) {
|
|
log('✅ Device récupéré avec succès');
|
|
log(`🔍 Device details: ${JSON.stringify({
|
|
hasSpWallet: !!device.sp_wallet,
|
|
birthday: device.sp_wallet?.birthday,
|
|
address: device.sp_wallet?.address
|
|
}, null, 2)}`);
|
|
} else {
|
|
log('❌ Aucun device trouvé dans la base de données');
|
|
}
|
|
} catch (error) {
|
|
log(`❌ Erreur lors de la récupération du device: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
async function testBirthdaySetup() {
|
|
log('🔄 Test: Birthday Setup complet...');
|
|
try {
|
|
const services = await Services.getInstance();
|
|
log('✅ Services initialisés');
|
|
|
|
// Connexion aux relais
|
|
await services.connectAllRelays();
|
|
log('✅ Relays connectés');
|
|
|
|
// Mettre à jour la date anniversaire
|
|
await services.updateDeviceBlockHeight();
|
|
log('✅ Birthday updated successfully');
|
|
|
|
log('🎉 Test de birthday setup réussi!');
|
|
} catch (error) {
|
|
log(`❌ Erreur lors du birthday setup: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
window.testWalletCreation = testWalletCreation;
|
|
window.testDeviceRetrieval = testDeviceRetrieval;
|
|
window.testBirthdaySetup = testBirthdaySetup;
|
|
|
|
log('🚀 Test page chargée. Cliquez sur les boutons pour tester.');
|
|
</script>
|
|
</body>
|
|
</html>
|