Optimize block scanning and fix pairing page HTML

**Motivations :**
- Le scan des blocs était refait inutilement dans la page de pairing même si le wallet était déjà synchronisé
- Le HTML de la page de pairing était cassé à cause de la duplication du CSS
- ensureCompleteInitialScan() forçait un scan complet sans vérifier l'état de synchronisation

**Modifications :**
- service.ts : Ajout de vérification de synchronisation dans ensureCompleteInitialScan() pour éviter les scans redondants
- pairing.ts : Suppression de la duplication du CSS et simplification de l'injection de contenu
- Logs améliorés : Ajout de logs pour indiquer si le wallet est déjà synchronisé

**Pages affectées :**
- src/services/service.ts : Optimisation de ensureCompleteInitialScan()
- src/pages/pairing/pairing.ts : Correction de l'affichage HTML
This commit is contained in:
NicolasCantu 2025-10-29 20:45:08 +01:00
parent 1e531ac157
commit dff9eed76e
2 changed files with 15 additions and 10 deletions

View File

@ -7,7 +7,6 @@ import { getCorrectDOM } from '../../utils/html.utils';
import { IframePairingComponent } from '../../components/iframe-pairing/iframe-pairing';
import { checkPBKDF2Key, checkWalletWithRetries } from '../../utils/prerequisites.utils';
import loginHtml from '../home/home.html?raw';
import loginCss from '../../4nk.css?raw';
// Extend WindowEventMap to include custom events
declare global {
@ -93,12 +92,8 @@ document.addEventListener('DOMContentLoaded', async () => {
updateStatus('🔄 Initialisation du pairing...', 'loading');
if (pairingContent) {
pairingContent.innerHTML = `
<style>
${loginCss}
</style>
${loginHtml}
`;
// Injecter seulement le HTML, le CSS est déjà chargé via le <link> dans le <head>
pairingContent.innerHTML = loginHtml;
// Créer un conteneur simulant login-4nk-component pour getCorrectDOM
const mockContainer = document.createElement('div');

View File

@ -2301,6 +2301,7 @@ export default class Services {
/**
* Ensures a complete initial scan is performed before requesting faucet tokens
* This prevents the race condition between scan and faucet transactions
* Only performs scan if wallet is not already synchronized
*/
public async ensureCompleteInitialScan(): Promise<void> {
console.log('🔄 Ensuring complete initial scan...');
@ -2311,9 +2312,18 @@ export default class Services {
throw new Error('Device not found or wallet not initialized');
}
// Force a complete scan from birthday to current block height
const scanFromHeight = Math.max(0, this.currentBlockHeight - 100);
console.log(`🔄 Performing complete scan from block ${scanFromHeight} to ${this.currentBlockHeight}...`);
// Check if wallet is already synchronized
const lastScan = device.sp_wallet.last_scan || 0;
const isSynchronized = lastScan >= this.currentBlockHeight;
if (isSynchronized) {
console.log(`✅ Wallet already synchronized (last_scan: ${lastScan}, current: ${this.currentBlockHeight})`);
return;
}
// Only scan if wallet is not synchronized
console.log(`🔄 Wallet needs synchronization (last_scan: ${lastScan}, current: ${this.currentBlockHeight})`);
console.log(`🔄 Performing scan from block ${lastScan} to ${this.currentBlockHeight}...`);
await this.sdkClient.scan_blocks(this.currentBlockHeight, BLINDBITURL);
console.log('✅ Complete initial scan completed');