Fix block-sync import error and simplify pairing interface

**Motivations :**
- block-sync.ts avait une erreur ReferenceError: Services is not defined
- Le template standardisé créait des problèmes d'affichage
- Besoin de garder l'interface existante qui fonctionnait

**Modifications :**
- src/pages/block-sync/block-sync.ts : Ajout de l'import manquant Services
- src/pages/block-sync/block-sync.html : Retour à l'interface originale qui fonctionnait
- src/pages/pairing/pairing.html : Simplification de l'interface
- src/pages/pairing/pairing.ts : Simplification de la logique d'injection

**Pages affectées :**
- src/pages/block-sync/ : Correction de l'erreur d'import et retour à l'interface originale
- src/pages/pairing/ : Simplification de l'interface pour éviter les problèmes d'affichage
This commit is contained in:
NicolasCantu 2025-10-29 21:43:05 +01:00
parent 2b9b9771e1
commit ad32875179
5 changed files with 161 additions and 286 deletions

View File

@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Synchronisation des blocs - LeCoffre</title> <title>Synchronisation des Blocs - LeCoffre</title>
<link rel="stylesheet" href="../../4nk.css"> <link rel="stylesheet" href="../../4nk.css">
<style> <style>
body { body {
@ -67,129 +67,127 @@
color: #c62828; color: #c62828;
} }
.progress-container { .progress {
margin: 20px 0;
}
.progress-bar {
width: 100%; width: 100%;
height: 8px; height: 8px;
background: #e0e0e0; background: #e0e0e0;
border-radius: 4px; border-radius: 4px;
overflow: hidden; overflow: hidden;
margin: 20px 0;
} }
.progress-fill { .progress-bar {
height: 100%; height: 100%;
background: linear-gradient(90deg, #4caf50, #8bc34a); background: #667eea;
width: 0%; width: 0%;
transition: width 0.3s ease; transition: width 0.3s ease;
} }
.steps-container { .sync-details {
background-color: #f8f9fa;
border-radius: 8px;
padding: 20px;
margin: 20px 0; margin: 20px 0;
text-align: left;
} }
.step-item { .sync-details h3 {
margin-top: 0;
color: #495057;
text-align: center;
margin-bottom: 15px;
}
.sync-item {
display: flex; display: flex;
justify-content: space-between;
align-items: center; align-items: center;
padding: 10px 0; padding: 0.75rem 0;
border-bottom: 1px solid #eee; border-bottom: 1px solid #e9ecef;
} }
.step-item:last-child { .sync-item:last-child {
border-bottom: none; border-bottom: none;
} }
.step-label { .sync-status {
flex: 1; font-weight: bold;
font-weight: 500;
color: #333;
} }
.step-value { .sync-status.pending {
font-weight: 600; color: #ffc107;
color: #666;
} }
.step-status { .sync-status.completed {
margin-left: 10px; color: #28a745;
padding: 4px 8px;
border-radius: 4px;
font-size: 0.8rem;
font-weight: 500;
} }
.step-status.pending { .sync-status.error {
background: #fff3cd; color: #dc3545;
color: #856404;
}
.step-status.completed {
background: #d4edda;
color: #155724;
}
.step-status.error {
background: #f8d7da;
color: #721c24;
} }
.continue-btn { .continue-btn {
width: 100%; width: 100%;
padding: 15px; background: #667eea;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white; color: white;
border: none; border: none;
border-radius: 8px; border-radius: 8px;
font-size: 1.1rem; padding: 15px;
font-size: 16px;
font-weight: 600; font-weight: 600;
cursor: pointer; cursor: pointer;
transition: transform 0.2s ease, box-shadow 0.2s ease;
margin-top: 20px; margin-top: 20px;
transition: background 0.3s ease;
} }
.continue-btn:hover:not(:disabled) { .continue-btn:hover:not(:disabled) {
transform: translateY(-2px); background: #5a6fd8;
box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
} }
.continue-btn:disabled { .continue-btn:disabled {
background: #ccc; background: #ccc;
cursor: not-allowed; cursor: not-allowed;
transform: none;
box-shadow: none;
}
.content-area {
min-height: 200px;
} }
</style> </style>
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<h1>🔄 Synchronisation des blocs</h1> <h1>🔄 Synchronisation des Blocs</h1>
<p class="subtitle">Synchronisation du wallet avec la blockchain</p> <p class="subtitle">Synchronisation avec le réseau Bitcoin pour récupérer l'historique des transactions</p>
<div class="status loading" id="status"> <div class="status loading" id="status">
🔄 Initialisation en cours... 🔄 Initialisation de la synchronisation...
</div> </div>
<div class="progress-container" id="progressContainer" style="display: none;"> <div class="progress">
<div class="progress-bar"> <div class="progress-bar" id="progressBar"></div>
<div class="progress-fill" id="progressFill"></div> </div>
<div class="sync-details">
<h3>📊 Détails de la synchronisation</h3>
<div class="sync-item">
<span>Hauteur de bloc actuelle:</span>
<span id="currentBlock" class="sync-status pending">En attente...</span>
</div>
<div class="sync-item">
<span>Date anniversaire:</span>
<span id="birthday" class="sync-status pending">En attente...</span>
</div>
<div class="sync-item">
<span>Blocs à scanner:</span>
<span id="blocksToScan" class="sync-status pending">En attente...</span>
</div>
<div class="sync-item">
<span>Blocs scannés:</span>
<span id="blocksScanned" class="sync-status pending">0</span>
</div>
<div class="sync-item">
<span>Transactions trouvées:</span>
<span id="transactionsFound" class="sync-status pending">0</span>
</div> </div>
</div> </div>
<div class="steps-container" id="stepsContainer" style="display: none;"> <button id="continueBtn" class="continue-btn" disabled>
<!-- Les étapes seront injectées ici dynamiquement -->
</div>
<div class="content-area" id="contentArea">
<!-- Le contenu spécifique sera injecté ici -->
</div>
<button class="continue-btn" id="continueBtn" style="display: none;">
Aller au pairing Aller au pairing
</button> </button>
</div> </div>

View File

@ -1,21 +1,51 @@
import { checkPBKDF2Key, checkWalletWithRetries } from '../../utils/prerequisites.utils'; import { checkPBKDF2Key, checkWalletWithRetries } from '../../utils/prerequisites.utils';
import { createPageTemplate } from '../../utils/page-template.utils'; import Services from '../../services/service';
document.addEventListener("DOMContentLoaded", async () => { document.addEventListener("DOMContentLoaded", async () => {
console.log("🔄 Block sync page loaded"); console.log("🔄 Block sync page loaded");
// Initialiser le template de page const status = document.getElementById("status") as HTMLElement;
const pageTemplate = createPageTemplate(); const progressBar = document.getElementById("progressBar") as HTMLElement;
const continueBtn = document.getElementById("continueBtn") as HTMLButtonElement;
function updateStatus(message: string, type: 'loading' | 'success' | 'error') {
if (status) {
status.textContent = message;
status.className = `status ${type}`;
}
}
function updateProgress(percentage: number) {
if (progressBar) {
progressBar.style.width = `${percentage}%`;
}
}
function updateSyncItem(elementId: string, value: string, status: 'pending' | 'completed' | 'error' = 'pending') {
const element = document.getElementById(elementId);
if (element) {
element.textContent = value;
element.className = `sync-status ${status}`;
}
}
// Gestion du bouton continuer (définie avant le try pour être toujours disponible)
if (continueBtn) {
continueBtn.addEventListener('click', async () => {
console.log('🔗 Redirecting to pairing page...');
window.location.href = '/src/pages/pairing/pairing.html';
});
}
try { try {
// Vérifier les prérequis // Vérifier les prérequis
console.log('🔍 Verifying prerequisites...'); console.log('🔍 Verifying prerequisites...');
pageTemplate.updateStatus('🔍 Vérification des prérequis...', 'loading'); updateStatus('🔍 Vérification des prérequis...', 'loading');
const pbkdf2KeyResult = await checkPBKDF2Key(); const pbkdf2KeyResult = await checkPBKDF2Key();
if (!pbkdf2KeyResult) { if (!pbkdf2KeyResult) {
console.log('⚠️ PBKDF2 key not found, redirecting to security-setup...'); console.log('⚠️ PBKDF2 key not found, redirecting to security-setup...');
pageTemplate.updateStatus('⚠️ Redirection vers la configuration de sécurité...', 'loading'); updateStatus('⚠️ Redirection vers la configuration de sécurité...', 'loading');
setTimeout(() => { setTimeout(() => {
window.location.href = '/src/pages/security-setup/security-setup.html'; window.location.href = '/src/pages/security-setup/security-setup.html';
}, 1000); }, 1000);
@ -25,7 +55,7 @@ document.addEventListener("DOMContentLoaded", async () => {
const wallet = await checkWalletWithRetries(); const wallet = await checkWalletWithRetries();
if (!wallet) { if (!wallet) {
console.log('⚠️ Wallet not found, redirecting to wallet-setup...'); console.log('⚠️ Wallet not found, redirecting to wallet-setup...');
pageTemplate.updateStatus('⚠️ Redirection vers la configuration du wallet...', 'loading'); updateStatus('⚠️ Redirection vers la configuration du wallet...', 'loading');
setTimeout(() => { setTimeout(() => {
window.location.href = '/src/pages/wallet-setup/wallet-setup.html'; window.location.href = '/src/pages/wallet-setup/wallet-setup.html';
}, 1000); }, 1000);
@ -34,7 +64,7 @@ document.addEventListener("DOMContentLoaded", async () => {
if (!wallet.sp_wallet?.birthday || wallet.sp_wallet.birthday === 0) { if (!wallet.sp_wallet?.birthday || wallet.sp_wallet.birthday === 0) {
console.log('⚠️ Birthday not configured, redirecting to birthday-setup...'); console.log('⚠️ Birthday not configured, redirecting to birthday-setup...');
pageTemplate.updateStatus('⚠️ Redirection vers la configuration de la date anniversaire...', 'loading'); updateStatus('⚠️ Redirection vers la configuration de la date anniversaire...', 'loading');
setTimeout(() => { setTimeout(() => {
window.location.href = '/src/pages/birthday-setup/birthday-setup.html'; window.location.href = '/src/pages/birthday-setup/birthday-setup.html';
}, 1000); }, 1000);
@ -42,18 +72,11 @@ document.addEventListener("DOMContentLoaded", async () => {
} }
console.log('✅ All prerequisites verified for block sync'); console.log('✅ All prerequisites verified for block sync');
pageTemplate.updateStatus('✅ Prerequisites verified', 'success'); updateStatus('✅ Prerequisites verified', 'success');
// Afficher les étapes de synchronisation
pageTemplate.showSteps();
pageTemplate.updateStep('currentBlock', 'En attente...', 'pending');
pageTemplate.updateStep('birthday', wallet.sp_wallet.birthday.toString(), 'completed');
pageTemplate.updateStep('lastScan', 'En attente...', 'pending');
pageTemplate.updateStep('syncStatus', 'En attente...', 'pending');
// Initialiser les services // Initialiser les services
console.log('🔄 Waiting for services to be ready...'); console.log('🔄 Waiting for services to be ready...');
pageTemplate.updateStatus('🔄 Initialisation des services...', 'loading'); updateStatus('🔄 Initialisation des services...', 'loading');
let services: Services; let services: Services;
let attempts = 0; let attempts = 0;
@ -83,7 +106,7 @@ document.addEventListener("DOMContentLoaded", async () => {
const currentBlockHeight = services.getCurrentBlockHeight(); const currentBlockHeight = services.getCurrentBlockHeight();
if (currentBlockHeight === -1) { if (currentBlockHeight === -1) {
console.log('⚠️ Block height not available, connecting to relays...'); console.log('⚠️ Block height not available, connecting to relays...');
pageTemplate.updateStatus('⚠️ Connexion aux relays...', 'loading'); updateStatus('⚠️ Connexion aux relays...', 'loading');
// Attendre que les services se connectent aux relays // Attendre que les services se connectent aux relays
await services.connectAllRelays(); await services.connectAllRelays();
@ -99,19 +122,23 @@ document.addEventListener("DOMContentLoaded", async () => {
console.log(`📊 Sync info: current=${finalBlockHeight}, birthday=${birthday}, lastScan=${lastScan}, toScan=${toScan}`); console.log(`📊 Sync info: current=${finalBlockHeight}, birthday=${birthday}, lastScan=${lastScan}, toScan=${toScan}`);
// Mettre à jour les étapes // Mettre à jour l'interface
pageTemplate.updateStep('currentBlock', finalBlockHeight.toString(), 'completed'); updateSyncItem('currentBlock', finalBlockHeight.toString(), 'completed');
pageTemplate.updateStep('lastScan', lastScan.toString(), 'completed'); updateSyncItem('birthday', birthday.toString(), 'completed');
updateSyncItem('lastScan', lastScan.toString(), 'completed');
if (toScan === 0) { if (toScan === 0) {
console.log('✅ Wallet already synchronized'); console.log('✅ Wallet already synchronized');
pageTemplate.updateStatus('✅ Wallet déjà synchronisé', 'success'); updateStatus('✅ Wallet déjà synchronisé', 'success');
pageTemplate.updateStep('syncStatus', 'Synchronisé', 'completed'); updateSyncItem('blocksToScan', '0', 'completed');
updateSyncItem('blocksScanned', '0', 'completed');
updateSyncItem('transactionsFound', '0', 'completed');
// Afficher le bouton et rediriger automatiquement // Activer le bouton et rediriger automatiquement
pageTemplate.showContinueButton('Aller au pairing', () => { if (continueBtn) {
window.location.href = '/src/pages/pairing/pairing.html'; continueBtn.disabled = false;
}); continueBtn.textContent = 'Aller au pairing';
}
// Auto-redirection après 3 secondes // Auto-redirection après 3 secondes
setTimeout(() => { setTimeout(() => {
@ -122,9 +149,9 @@ document.addEventListener("DOMContentLoaded", async () => {
} }
// Afficher la barre de progression // Afficher la barre de progression
pageTemplate.showProgress(); updateProgress(0);
pageTemplate.updateStatus('🔄 Synchronisation en cours...', 'loading'); updateStatus('🔄 Synchronisation en cours...', 'loading');
pageTemplate.updateStep('syncStatus', 'En cours...', 'pending'); updateSyncItem('blocksToScan', toScan.toString(), 'pending');
// Intercepter les messages de progression du scan // Intercepter les messages de progression du scan
let scanProgressInterval: NodeJS.Timeout | null = null; let scanProgressInterval: NodeJS.Timeout | null = null;
@ -143,12 +170,12 @@ document.addEventListener("DOMContentLoaded", async () => {
const percentage = parseInt(progressMatch[3]); const percentage = parseInt(progressMatch[3]);
// Mettre à jour l'interface avec les détails de progression // Mettre à jour l'interface avec les détails de progression
pageTemplate.updateStatus(`🔍 Synchronisation des blocs: ${currentBlock}/${totalBlocks} (${percentage}%)`, 'loading'); updateStatus(`🔍 Synchronisation des blocs: ${currentBlock}/${totalBlocks} (${percentage}%)`, 'loading');
pageTemplate.updateProgress(60 + (percentage * 0.4)); // 60% à 100% pour la synchronisation updateProgress(percentage);
// Mettre à jour les éléments de synchronisation // Mettre à jour les éléments de synchronisation
pageTemplate.updateStep('blocksScanned', currentBlock.toString(), 'pending'); updateSyncItem('blocksScanned', currentBlock.toString(), 'pending');
pageTemplate.updateStep('blocksToScan', (totalBlocks - currentBlock).toString(), 'pending'); updateSyncItem('blocksToScan', (totalBlocks - currentBlock).toString(), 'pending');
lastProgressMessage = `Bloc ${currentBlock}/${totalBlocks} (${percentage}%)`; lastProgressMessage = `Bloc ${currentBlock}/${totalBlocks} (${percentage}%)`;
} }
@ -165,14 +192,17 @@ document.addEventListener("DOMContentLoaded", async () => {
// Restaurer la fonction console.log originale // Restaurer la fonction console.log originale
console.log = originalConsoleLog; console.log = originalConsoleLog;
pageTemplate.updateStatus('✅ Synchronisation terminée', 'success'); updateStatus('✅ Synchronisation terminée', 'success');
pageTemplate.updateProgress(100); updateProgress(100);
pageTemplate.updateStep('syncStatus', 'Terminé', 'completed'); updateSyncItem('blocksScanned', toScan.toString(), 'completed');
updateSyncItem('blocksToScan', '0', 'completed');
updateSyncItem('transactionsFound', '0', 'completed');
// Afficher le bouton et rediriger automatiquement // Activer le bouton et rediriger automatiquement
pageTemplate.showContinueButton('Aller au pairing', () => { if (continueBtn) {
window.location.href = '/src/pages/pairing/pairing.html'; continueBtn.disabled = false;
}); continueBtn.textContent = 'Aller au pairing';
}
// Auto-redirection après 3 secondes // Auto-redirection après 3 secondes
setTimeout(() => { setTimeout(() => {
@ -184,14 +214,14 @@ document.addEventListener("DOMContentLoaded", async () => {
// Restaurer la fonction console.log originale en cas d'erreur // Restaurer la fonction console.log originale en cas d'erreur
console.log = originalConsoleLog; console.log = originalConsoleLog;
console.error('❌ Error during block scan:', error); console.error('❌ Error during block scan:', error);
pageTemplate.updateStatus(`❌ Erreur lors de la synchronisation: ${(error as Error).message}`, 'error'); updateStatus(`❌ Erreur lors de la synchronisation: ${(error as Error).message}`, 'error');
pageTemplate.updateStep('syncStatus', 'Erreur', 'error'); updateSyncItem('blocksToScan', 'Erreur', 'error');
throw error; throw error;
} }
} catch (error) { } catch (error) {
console.error('❌ Error in block sync page:', error); console.error('❌ Error in block sync page:', error);
pageTemplate.updateStatus(`❌ Erreur: ${(error as Error).message}`, 'error'); updateStatus(`❌ Erreur: ${(error as Error).message}`, 'error');
// Rediriger vers la page appropriée selon l'erreur // Rediriger vers la page appropriée selon l'erreur
const errorMessage = (error as Error).message; const errorMessage = (error as Error).message;

View File

@ -67,156 +67,9 @@
color: #c62828; color: #c62828;
} }
.progress-container {
margin: 20px 0;
}
.progress-bar {
width: 100%;
height: 8px;
background: #e0e0e0;
border-radius: 4px;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #4caf50, #8bc34a);
width: 0%;
transition: width 0.3s ease;
}
.steps-container {
margin: 20px 0;
}
.step-item {
display: flex;
align-items: center;
padding: 10px 0;
border-bottom: 1px solid #eee;
}
.step-item:last-child {
border-bottom: none;
}
.step-label {
flex: 1;
font-weight: 500;
color: #333;
}
.step-value {
font-weight: 600;
color: #666;
}
.step-status {
margin-left: 10px;
padding: 4px 8px;
border-radius: 4px;
font-size: 0.8rem;
font-weight: 500;
}
.step-status.pending {
background: #fff3cd;
color: #856404;
}
.step-status.completed {
background: #d4edda;
color: #155724;
}
.step-status.error {
background: #f8d7da;
color: #721c24;
}
.continue-btn {
width: 100%;
padding: 15px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 8px;
font-size: 1.1rem;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s ease, box-shadow 0.2s ease;
margin-top: 20px;
}
.continue-btn:hover:not(:disabled) {
transform: translateY(-2px);
box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
}
.continue-btn:disabled {
background: #ccc;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
.content-area { .content-area {
min-height: 200px; min-height: 200px;
} }
/* Styles spécifiques au pairing */
.pairing-container {
background: #f8f9fa;
border-radius: 8px;
padding: 20px;
margin: 20px 0;
}
.pairing-card {
background: white;
border-radius: 8px;
padding: 20px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.card-header h2 {
margin: 0 0 10px 0;
color: #333;
font-size: 1.5rem;
}
.card-description {
color: #666;
margin: 0 0 20px 0;
}
.status-indicator {
background: #e3f2fd;
color: #1976d2;
padding: 15px;
border-radius: 8px;
text-align: center;
margin: 20px 0;
}
.account-actions {
margin-top: 20px;
}
.danger-btn {
background: #dc3545;
color: white;
border: none;
padding: 10px 20px;
border-radius: 6px;
cursor: pointer;
font-size: 0.9rem;
}
.danger-btn:hover {
background: #c82333;
}
</style> </style>
</head> </head>
<body> <body>
@ -228,23 +81,9 @@
🔄 Initialisation en cours... 🔄 Initialisation en cours...
</div> </div>
<div class="progress-container" id="progressContainer" style="display: none;">
<div class="progress-bar">
<div class="progress-fill" id="progressFill"></div>
</div>
</div>
<div class="steps-container" id="stepsContainer" style="display: none;">
<!-- Les étapes seront injectées ici dynamiquement -->
</div>
<div class="content-area" id="contentArea"> <div class="content-area" id="contentArea">
<!-- Le contenu de pairing sera injecté ici --> <!-- Le contenu de pairing sera injecté ici -->
</div> </div>
<button class="continue-btn" id="continueBtn" style="display: none;">
Continuer
</button>
</div> </div>
<script type="module" src="./pairing.ts"></script> <script type="module" src="./pairing.ts"></script>

View File

@ -6,21 +6,18 @@ import { displayEmojis, generateCreateBtn, addressToEmoji, prepareAndSendPairing
import { getCorrectDOM } from '../../utils/html.utils'; import { getCorrectDOM } from '../../utils/html.utils';
import { IframePairingComponent } from '../../components/iframe-pairing/iframe-pairing'; import { IframePairingComponent } from '../../components/iframe-pairing/iframe-pairing';
import { checkPBKDF2Key, checkWalletWithRetries } from '../../utils/prerequisites.utils'; import { checkPBKDF2Key, checkWalletWithRetries } from '../../utils/prerequisites.utils';
import { createPageTemplate } from '../../utils/page-template.utils';
import loginHtml from '../home/home.html?raw'; import loginHtml from '../home/home.html?raw';
// Extend WindowEventMap to include custom events // Extend WindowEventMap to include custom events
declare global { declare global {
interface WindowEventMap { interface WindowEventMap {
'pairing-words-generated': CustomEvent; 'pairing-words-generated': CustomEvent;
'pairing-status-update': CustomEvent;
'pairing-success': CustomEvent; 'pairing-success': CustomEvent;
'pairing-error': CustomEvent; 'pairing-error': CustomEvent;
} }
} }
let isInitializing = false; let isInitializing = false;
let pageTemplate: any;
document.addEventListener('DOMContentLoaded', async () => { document.addEventListener('DOMContentLoaded', async () => {
if (isInitializing) { if (isInitializing) {
@ -31,12 +28,19 @@ document.addEventListener('DOMContentLoaded', async () => {
isInitializing = true; isInitializing = true;
console.log('🔐 Pairing page loaded'); console.log('🔐 Pairing page loaded');
// Initialiser le template de page const status = document.getElementById('status') as HTMLElement;
pageTemplate = createPageTemplate(); const contentArea = document.getElementById('contentArea') as HTMLElement;
function updateStatus(message: string, type: 'loading' | 'success' | 'error') {
if (status) {
status.textContent = message;
status.className = `status ${type}`;
}
}
// Vérifier les prérequis en base de données // Vérifier les prérequis en base de données
console.log('🔍 Verifying prerequisites...'); console.log('🔍 Verifying prerequisites...');
pageTemplate.updateStatus('🔍 Vérification des prérequis...', 'loading'); updateStatus('🔍 Vérification des prérequis...', 'loading');
try { try {
console.log('🔧 Getting device reader service...'); console.log('🔧 Getting device reader service...');
@ -46,7 +50,7 @@ document.addEventListener('DOMContentLoaded', async () => {
const pbkdf2KeyResult = await checkPBKDF2Key(); const pbkdf2KeyResult = await checkPBKDF2Key();
if (!pbkdf2KeyResult) { if (!pbkdf2KeyResult) {
console.log('⚠️ PBKDF2 key not found, redirecting to security-setup...'); console.log('⚠️ PBKDF2 key not found, redirecting to security-setup...');
pageTemplate.updateStatus('⚠️ Redirection vers la configuration de sécurité...', 'loading'); updateStatus('⚠️ Redirection vers la configuration de sécurité...', 'loading');
setTimeout(() => { setTimeout(() => {
window.location.href = '/src/pages/security-setup/security-setup.html'; window.location.href = '/src/pages/security-setup/security-setup.html';
}, 1000); }, 1000);
@ -57,7 +61,7 @@ document.addEventListener('DOMContentLoaded', async () => {
const wallet = await checkWalletWithRetries(); const wallet = await checkWalletWithRetries();
if (!wallet) { if (!wallet) {
console.log('⚠️ Wallet still not found after retries, redirecting to wallet-setup...'); console.log('⚠️ Wallet still not found after retries, redirecting to wallet-setup...');
pageTemplate.updateStatus('⚠️ Redirection vers la configuration du wallet...', 'loading'); updateStatus('⚠️ Redirection vers la configuration du wallet...', 'loading');
setTimeout(() => { setTimeout(() => {
window.location.href = '/src/pages/wallet-setup/wallet-setup.html'; window.location.href = '/src/pages/wallet-setup/wallet-setup.html';
}, 1000); }, 1000);
@ -74,7 +78,7 @@ document.addEventListener('DOMContentLoaded', async () => {
// Vérifier que le birthday est configuré (> 0) // Vérifier que le birthday est configuré (> 0)
if (!wallet.sp_wallet.birthday || wallet.sp_wallet.birthday === 0) { if (!wallet.sp_wallet.birthday || wallet.sp_wallet.birthday === 0) {
console.log('⚠️ Birthday not configured, redirecting to birthday-setup...'); console.log('⚠️ Birthday not configured, redirecting to birthday-setup...');
pageTemplate.updateStatus('⚠️ Redirection vers la configuration de la date anniversaire...', 'loading'); updateStatus('⚠️ Redirection vers la configuration de la date anniversaire...', 'loading');
setTimeout(() => { setTimeout(() => {
window.location.href = '/src/pages/birthday-setup/birthday-setup.html'; window.location.href = '/src/pages/birthday-setup/birthday-setup.html';
}, 1000); }, 1000);
@ -84,24 +88,28 @@ document.addEventListener('DOMContentLoaded', async () => {
console.log('✅ All prerequisites verified for pairing page'); console.log('✅ All prerequisites verified for pairing page');
// Charger le contenu de pairing depuis home.html // Charger le contenu de pairing depuis home.html
pageTemplate.updateStatus('🔄 Initialisation du pairing...', 'loading'); updateStatus('🔄 Initialisation du pairing...', 'loading');
// Injecter le contenu de pairing dans la zone de contenu // Injecter le contenu de pairing dans la zone de contenu
pageTemplate.setContent(loginHtml); if (contentArea) {
contentArea.innerHTML = loginHtml;
}
// Importer et initialiser la logique de pairing depuis home.ts // Importer et initialiser la logique de pairing depuis home.ts
const { initHomePage } = await import('../home/home'); const { initHomePage } = await import('../home/home');
await initHomePage(); await initHomePage();
pageTemplate.updateStatus('✅ Prêt pour le pairing', 'success'); updateStatus('✅ Prêt pour le pairing', 'success');
setTimeout(() => { setTimeout(() => {
pageTemplate.hideStatus(); if (status) {
status.style.display = 'none';
}
}, 2000); }, 2000);
console.log('✅ Pairing page initialization completed'); console.log('✅ Pairing page initialization completed');
} catch (error) { } catch (error) {
console.error('❌ Error initializing pairing page:', error); console.error('❌ Error initializing pairing page:', error);
pageTemplate.updateStatus(`❌ Erreur: ${(error as Error).message}`, 'error'); updateStatus(`❌ Erreur: ${(error as Error).message}`, 'error');
// Si l'erreur est liée aux prérequis, rediriger vers la page appropriée // Si l'erreur est liée aux prérequis, rediriger vers la page appropriée
const errorMessage = (error as Error).message; const errorMessage = (error as Error).message;
@ -124,4 +132,4 @@ document.addEventListener('DOMContentLoaded', async () => {
} finally { } finally {
isInitializing = false; isInitializing = false;
} }
}); });

View File

@ -111,7 +111,7 @@ export class PageTemplate {
this.continueBtn.textContent = text; this.continueBtn.textContent = text;
this.continueBtn.style.display = 'block'; this.continueBtn.style.display = 'block';
this.continueBtn.disabled = false; this.continueBtn.disabled = false;
if (onClick) { if (onClick) {
this.continueBtn.onclick = onClick; this.continueBtn.onclick = onClick;
} }