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',
|
'security-setup': '/src/pages/security-setup/security-setup.html',
|
||||||
'wallet-setup': '/src/pages/wallet-setup/wallet-setup.html',
|
'wallet-setup': '/src/pages/wallet-setup/wallet-setup.html',
|
||||||
'birthday-setup': '/src/pages/birthday-setup/birthday-setup.html',
|
'birthday-setup': '/src/pages/birthday-setup/birthday-setup.html',
|
||||||
|
'block-sync': '/src/pages/block-sync/block-sync.html',
|
||||||
};
|
};
|
||||||
|
|
||||||
export let currentRoute = '';
|
export let currentRoute = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vérifie l'état du storage et détermine quelle page afficher selon l'état actuel
|
* 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 :
|
* Logique de progression :
|
||||||
* - Si pairing → account
|
* - Si pairing → account
|
||||||
* - Si date anniversaire → pairing
|
* - Si date anniversaire → pairing
|
||||||
@ -37,32 +39,11 @@ export async function checkStorageStateAndNavigate(): Promise<void> {
|
|||||||
console.log('🔍 Checking storage state to determine next step...');
|
console.log('🔍 Checking storage state to determine next step...');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Vérifier l'état du pairing
|
// Utiliser DeviceReaderService pour éviter d'initialiser WebAssembly
|
||||||
const services = await Services.getInstance();
|
const { DeviceReaderService } = await import('./services/device-reader.service');
|
||||||
const isPaired = services.isPaired();
|
const deviceReader = DeviceReaderService.getInstance();
|
||||||
|
|
||||||
if (isPaired) {
|
// Vérifier si une clé PBKDF2 existe (vérification la plus légère)
|
||||||
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
|
|
||||||
const { SecureCredentialsService } = await import('./services/secure-credentials.service');
|
const { SecureCredentialsService } = await import('./services/secure-credentials.service');
|
||||||
const secureCredentialsService = SecureCredentialsService.getInstance();
|
const secureCredentialsService = SecureCredentialsService.getInstance();
|
||||||
|
|
||||||
@ -72,26 +53,65 @@ export async function checkStorageStateAndNavigate(): Promise<void> {
|
|||||||
let hasPBKDF2Key = false;
|
let hasPBKDF2Key = false;
|
||||||
for (const mode of allSecurityModes) {
|
for (const mode of allSecurityModes) {
|
||||||
try {
|
try {
|
||||||
const key = await secureCredentialsService.retrievePBKDF2Key(mode);
|
const hasKey = await secureCredentialsService.hasPBKDF2Key(mode);
|
||||||
if (key) {
|
if (hasKey) {
|
||||||
hasPBKDF2Key = true;
|
const key = await secureCredentialsService.retrievePBKDF2Key(mode);
|
||||||
console.log(`🔐 PBKDF2 key found for mode: ${mode}`);
|
if (key) {
|
||||||
break;
|
hasPBKDF2Key = true;
|
||||||
|
console.log(`🔐 PBKDF2 key found for mode: ${mode}`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Mode non disponible, continuer
|
// Mode non disponible, continuer
|
||||||
|
console.log(`⚠️ No PBKDF2 key found for mode ${mode}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPBKDF2Key) {
|
if (!hasPBKDF2Key) {
|
||||||
console.log('🔐 PBKDF2 key exists, navigating to wallet-setup');
|
// 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');
|
await navigate('wallet-setup');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aucune clé PBKDF2 trouvée, commencer par la configuration de sécurité
|
// Vérifier si la date anniversaire est configurée (wallet avec birthday > 0)
|
||||||
console.log('🔐 No PBKDF2 key found, navigating to security-setup');
|
if (device.sp_wallet.birthday && device.sp_wallet.birthday > 0) {
|
||||||
await navigate('security-setup');
|
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) {
|
} catch (error) {
|
||||||
console.error('❌ Error checking storage state:', error);
|
console.error('❌ Error checking storage state:', error);
|
||||||
@ -130,7 +150,7 @@ async function handleLocation(path: string) {
|
|||||||
console.log('📍 Route HTML:', routeHtml);
|
console.log('📍 Route HTML:', routeHtml);
|
||||||
|
|
||||||
// Pour les pages de setup, rediriger directement vers la page HTML
|
// 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);
|
console.log('📍 Processing setup route:', path);
|
||||||
window.location.href = routeHtml;
|
window.location.href = routeHtml;
|
||||||
return;
|
return;
|
||||||
@ -225,10 +245,8 @@ export async function init(): Promise<void> {
|
|||||||
try {
|
try {
|
||||||
console.log('🚀 Starting application initialization...');
|
console.log('🚀 Starting application initialization...');
|
||||||
|
|
||||||
// Initialiser les services de base
|
// Initialiser uniquement la base de données (sans WebAssembly)
|
||||||
console.log('🔧 Initializing basic services...');
|
console.log('🔧 Initializing database...');
|
||||||
const services = await Services.getInstance();
|
|
||||||
(window as any).myService = services;
|
|
||||||
const db = await Database.getInstance();
|
const db = await Database.getInstance();
|
||||||
|
|
||||||
// Register service worker
|
// Register service worker
|
||||||
@ -236,6 +254,7 @@ export async function init(): Promise<void> {
|
|||||||
await db.registerServiceWorker('/src/service-workers/database.worker.js');
|
await db.registerServiceWorker('/src/service-workers/database.worker.js');
|
||||||
|
|
||||||
// Vérifier l'état du storage et naviguer vers la page appropriée
|
// 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...');
|
console.log('🔍 Checking storage state and navigating to appropriate page...');
|
||||||
await checkStorageStateAndNavigate();
|
await checkStorageStateAndNavigate();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user