feat: optimize router to start with security-setup without WebAssembly
**Motivations :** - La page d'accueil doit rediriger automatiquement vers security-setup si aucune clé PBKDF2 n'est trouvée - Éviter d'initialiser WebAssembly au démarrage pour une première visite - Le processus doit avancer automatiquement au fur et à mesure des vérifications **Modifications :** - Modifier checkStorageStateAndNavigate() pour utiliser DeviceReaderService au lieu de Services - Commencer par vérifier la clé PBKDF2 (étape la plus précoce) - Ne pas initialiser Services.getInstance() au démarrage dans init() - Ajouter la route block-sync dans routes - Rediriger vers security-setup par défaut si aucune clé PBKDF2 trouvée **Pages affectées :** - src/router.ts (logique de redirection optimisée, route block-sync ajoutée)
This commit is contained in:
parent
4418f805ef
commit
f3cfeef11b
@ -20,12 +20,14 @@ const routes: { [key: string]: string } = {
|
||||
'security-setup': '/src/pages/security-setup/security-setup.html',
|
||||
'wallet-setup': '/src/pages/wallet-setup/wallet-setup.html',
|
||||
'birthday-setup': '/src/pages/birthday-setup/birthday-setup.html',
|
||||
'block-sync': '/src/pages/block-sync/block-sync.html',
|
||||
};
|
||||
|
||||
export let currentRoute = '';
|
||||
|
||||
/**
|
||||
* Vérifie l'état du storage et détermine quelle page afficher selon l'état actuel
|
||||
* Version légère qui n'initialise pas WebAssembly pour la première visite
|
||||
* Logique de progression :
|
||||
* - Si pairing → account
|
||||
* - Si date anniversaire → pairing
|
||||
@ -37,32 +39,11 @@ export async function checkStorageStateAndNavigate(): Promise<void> {
|
||||
console.log('🔍 Checking storage state to determine next step...');
|
||||
|
||||
try {
|
||||
// Vérifier l'état du pairing
|
||||
const services = await Services.getInstance();
|
||||
const isPaired = services.isPaired();
|
||||
// Utiliser DeviceReaderService pour éviter d'initialiser WebAssembly
|
||||
const { DeviceReaderService } = await import('./services/device-reader.service');
|
||||
const deviceReader = DeviceReaderService.getInstance();
|
||||
|
||||
if (isPaired) {
|
||||
console.log('✅ Device is paired, navigating to account page');
|
||||
await navigate('account');
|
||||
return;
|
||||
}
|
||||
|
||||
// Vérifier si la date anniversaire est configurée (wallet avec birthday > 0)
|
||||
const device = await services.getDeviceFromDatabase();
|
||||
if (device?.sp_wallet && device.sp_wallet.birthday > 0) {
|
||||
console.log('🎂 Birthday is configured, navigating to pairing');
|
||||
await navigate('home'); // Pour l'instant, rediriger vers home pour le pairing
|
||||
return;
|
||||
}
|
||||
|
||||
// Vérifier si le wallet existe (même avec birthday = 0)
|
||||
if (device?.sp_wallet) {
|
||||
console.log('💰 Wallet exists but birthday not set, navigating to birthday-setup');
|
||||
await navigate('birthday-setup');
|
||||
return;
|
||||
}
|
||||
|
||||
// Vérifier si une clé PBKDF2 existe
|
||||
// Vérifier si une clé PBKDF2 existe (vérification la plus légère)
|
||||
const { SecureCredentialsService } = await import('./services/secure-credentials.service');
|
||||
const secureCredentialsService = SecureCredentialsService.getInstance();
|
||||
|
||||
@ -72,26 +53,65 @@ export async function checkStorageStateAndNavigate(): Promise<void> {
|
||||
let hasPBKDF2Key = false;
|
||||
for (const mode of allSecurityModes) {
|
||||
try {
|
||||
const key = await secureCredentialsService.retrievePBKDF2Key(mode);
|
||||
if (key) {
|
||||
hasPBKDF2Key = true;
|
||||
console.log(`🔐 PBKDF2 key found for mode: ${mode}`);
|
||||
break;
|
||||
const hasKey = await secureCredentialsService.hasPBKDF2Key(mode);
|
||||
if (hasKey) {
|
||||
const key = await secureCredentialsService.retrievePBKDF2Key(mode);
|
||||
if (key) {
|
||||
hasPBKDF2Key = true;
|
||||
console.log(`🔐 PBKDF2 key found for mode: ${mode}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// Mode non disponible, continuer
|
||||
console.log(`⚠️ No PBKDF2 key found for mode ${mode}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasPBKDF2Key) {
|
||||
console.log('🔐 PBKDF2 key exists, navigating to wallet-setup');
|
||||
if (!hasPBKDF2Key) {
|
||||
// Aucune clé PBKDF2 trouvée, commencer par la configuration de sécurité
|
||||
console.log('🔐 No PBKDF2 key found, navigating to security-setup');
|
||||
await navigate('security-setup');
|
||||
return;
|
||||
}
|
||||
|
||||
// Vérifier si le wallet existe (même avec birthday = 0)
|
||||
const device = await deviceReader.getDeviceFromDatabase();
|
||||
if (!device?.sp_wallet) {
|
||||
console.log('💰 Wallet does not exist, navigating to wallet-setup');
|
||||
await navigate('wallet-setup');
|
||||
return;
|
||||
}
|
||||
|
||||
// Aucune clé PBKDF2 trouvée, commencer par la configuration de sécurité
|
||||
console.log('🔐 No PBKDF2 key found, navigating to security-setup');
|
||||
await navigate('security-setup');
|
||||
// Vérifier si la date anniversaire est configurée (wallet avec birthday > 0)
|
||||
if (device.sp_wallet.birthday && device.sp_wallet.birthday > 0) {
|
||||
console.log('🎂 Birthday is configured, checking pairing status...');
|
||||
|
||||
// Vérifier l'état du pairing (nécessite Services mais seulement si tout est prêt)
|
||||
try {
|
||||
const services = await Services.getInstance();
|
||||
const isPaired = services.isPaired();
|
||||
|
||||
if (isPaired) {
|
||||
console.log('✅ Device is paired, navigating to account page');
|
||||
await navigate('account');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('🔗 Not paired yet, navigating to pairing');
|
||||
await navigate('home');
|
||||
return;
|
||||
} catch (error) {
|
||||
console.log('⚠️ Could not check pairing status, navigating to home');
|
||||
await navigate('home');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Wallet existe mais birthday pas configuré
|
||||
console.log('💰 Wallet exists but birthday not set, navigating to birthday-setup');
|
||||
await navigate('birthday-setup');
|
||||
return;
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Error checking storage state:', error);
|
||||
@ -130,7 +150,7 @@ async function handleLocation(path: string) {
|
||||
console.log('📍 Route HTML:', routeHtml);
|
||||
|
||||
// Pour les pages de setup, rediriger directement vers la page HTML
|
||||
if (path === 'security-setup' || path === 'wallet-setup' || path === 'birthday-setup') {
|
||||
if (path === 'security-setup' || path === 'wallet-setup' || path === 'birthday-setup' || path === 'block-sync') {
|
||||
console.log('📍 Processing setup route:', path);
|
||||
window.location.href = routeHtml;
|
||||
return;
|
||||
@ -225,10 +245,8 @@ export async function init(): Promise<void> {
|
||||
try {
|
||||
console.log('🚀 Starting application initialization...');
|
||||
|
||||
// Initialiser les services de base
|
||||
console.log('🔧 Initializing basic services...');
|
||||
const services = await Services.getInstance();
|
||||
(window as any).myService = services;
|
||||
// Initialiser uniquement la base de données (sans WebAssembly)
|
||||
console.log('🔧 Initializing database...');
|
||||
const db = await Database.getInstance();
|
||||
|
||||
// Register service worker
|
||||
@ -236,6 +254,7 @@ export async function init(): Promise<void> {
|
||||
await db.registerServiceWorker('/src/service-workers/database.worker.js');
|
||||
|
||||
// Vérifier l'état du storage et naviguer vers la page appropriée
|
||||
// Cette fonction est maintenant légère et ne nécessite pas WebAssembly
|
||||
console.log('🔍 Checking storage state and navigating to appropriate page...');
|
||||
await checkStorageStateAndNavigate();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user