From dff9eed76eb0cf7843c74885ecda1590dbb5e852 Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Wed, 29 Oct 2025 20:45:08 +0100 Subject: [PATCH] Optimize block scanning and fix pairing page HTML MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **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 --- src/pages/pairing/pairing.ts | 9 ++------- src/services/service.ts | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/pages/pairing/pairing.ts b/src/pages/pairing/pairing.ts index ab0e8c5..4985d71 100644 --- a/src/pages/pairing/pairing.ts +++ b/src/pages/pairing/pairing.ts @@ -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 = ` - - ${loginHtml} - `; + // Injecter seulement le HTML, le CSS est déjà chargé via le dans le + pairingContent.innerHTML = loginHtml; // Créer un conteneur simulant login-4nk-component pour getCorrectDOM const mockContainer = document.createElement('div'); diff --git a/src/services/service.ts b/src/services/service.ts index 719a0c8..2fea83e 100755 --- a/src/services/service.ts +++ b/src/services/service.ts @@ -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 { 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');