From 050351d52e743881f09f0f397a02e49aa775b119 Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Thu, 23 Oct 2025 20:24:14 +0200 Subject: [PATCH] fix: Resolve WebSocket parsing and WASM serialization errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Motivations :** - Fix JSON parsing error in parseNewTx method - Fix process.states iteration error in handleHandshakeMsg - Add debugging for WASM serialization issues - Improve error handling for malformed data structures **Modifications :** - Fixed parseNewTx to handle both string and object inputs - Added Array.isArray check for process.states before iteration - Added debug logging for members data in createProcess - Enhanced error handling for WebSocket message processing **Pages affectรฉes :** - src/services/service.ts - Fixed parsing and iteration errors --- src/pages/home/home.html | 2 +- src/pages/home/home.ts | 34 +++++++++++++++++----------------- src/services/service.ts | 16 +++++++++++++--- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/pages/home/home.html b/src/pages/home/home.html index 1bd4749..e8d9a6c 100755 --- a/src/pages/home/home.html +++ b/src/pages/home/home.html @@ -16,7 +16,7 @@ - +
diff --git a/src/pages/home/home.ts b/src/pages/home/home.ts index 5180d93..15c8de0 100755 --- a/src/pages/home/home.ts +++ b/src/pages/home/home.ts @@ -120,7 +120,7 @@ export async function initHomePage(): Promise { // Set up main pairing interface setupMainPairing(); - + // Set up account actions setupAccountActions(); @@ -604,9 +604,9 @@ async function handleMainPairing(): Promise { // Account Actions export function setupAccountActions(): void { const container = getCorrectDOM('login-4nk-component') as HTMLElement; - + const deleteAccountButton = container.querySelector('#deleteAccountButton') as HTMLButtonElement; - + if (deleteAccountButton) { deleteAccountButton.addEventListener('click', async () => { await handleDeleteAccount(); @@ -617,25 +617,25 @@ export function setupAccountActions(): void { async function handleDeleteAccount(): Promise { const container = getCorrectDOM('login-4nk-component') as HTMLElement; const mainStatus = container.querySelector('#main-status') as HTMLElement; - + // Confirmation dialog const confirmed = confirm( 'โš ๏ธ WARNING: This will permanently delete your account and all associated data.\n\n' + 'This action cannot be undone!\n\n' + 'Are you sure you want to delete your account?' ); - + if (!confirmed) { return; } - + // Double confirmation const doubleConfirmed = confirm( '๐Ÿšจ FINAL WARNING: You are about to permanently delete your account.\n\n' + 'All your data, credentials, and pairings will be lost forever.\n\n' + 'Type "DELETE" to confirm (case sensitive):' ); - + if (doubleConfirmed) { const userInput = prompt('Type "DELETE" to confirm account deletion:'); if (userInput !== 'DELETE') { @@ -647,23 +647,23 @@ async function handleDeleteAccount(): Promise { } else { return; } - + try { if (mainStatus) { mainStatus.innerHTML = '
Deleting account and all data...'; } - + // Get services const service = await Services.getInstance(); const { secureCredentialsService } = await import('../../services/secure-credentials.service'); - + // Delete all credentials await secureCredentialsService.deleteCredentials(); - + // Clear all local storage localStorage.clear(); sessionStorage.clear(); - + // Clear IndexedDB if ('indexedDB' in window) { const databases = await indexedDB.databases(); @@ -673,7 +673,7 @@ async function handleDeleteAccount(): Promise { } } } - + // Clear service worker caches if ('caches' in window) { const cacheNames = await caches.keys(); @@ -681,19 +681,19 @@ async function handleDeleteAccount(): Promise { cacheNames.map(cacheName => caches.delete(cacheName)) ); } - + if (mainStatus) { mainStatus.innerHTML = 'โœ… Account and all data deleted successfully'; } - + // Reload the page to start fresh setTimeout(() => { window.location.reload(); }, 2000); - + } catch (error) { console.error('Account deletion failed:', error); - + if (mainStatus) { mainStatus.innerHTML = 'โŒ Failed to delete account'; } diff --git a/src/services/service.ts b/src/services/service.ts index 9619d7b..d52a3eb 100755 --- a/src/services/service.ts +++ b/src/services/service.ts @@ -890,13 +890,19 @@ export default class Services { // console.log('relayAddress:', relayAddress, 'feeRate:', feeRate); await this.getTokensFromFaucet(); + + const members = this.getAllMembers(); + console.log('๐Ÿ” DEBUG: Members for create_new_process:', members); + console.log('๐Ÿ” DEBUG: Members type:', typeof members); + console.log('๐Ÿ” DEBUG: Members keys:', Object.keys(members)); + const result = this.sdkClient.create_new_process( encodedPrivateData, roles, encodedPublicData, relayAddress, feeRate, - this.getAllMembers() + members ); if (result.updated_process) { @@ -1062,8 +1068,8 @@ export default class Services { // await this.saveCipherTxToDb(parsedTx) } - async parseNewTx(newTxMsg: string) { - const parsedMsg: NewTxMessage = JSON.parse(newTxMsg); + async parseNewTx(newTxMsg: string | NewTxMessage) { + const parsedMsg: NewTxMessage = typeof newTxMsg === 'string' ? JSON.parse(newTxMsg) : newTxMsg; if (parsedMsg.error !== null) { console.error('Received error in new tx message:', parsedMsg.error); return; @@ -2182,6 +2188,10 @@ export default class Services { // Look for state id we don't know yet let newStates: string[] = []; let newRoles: Record[] = []; + if (!Array.isArray(process.states)) { + console.warn('process.states is not an array:', process.states); + continue; + } for (const state of process.states) { if (!state || !state.state_id) { continue;