fix: Resolve WebSocket parsing and WASM serialization errors
**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
This commit is contained in:
parent
33935f4b18
commit
050351d52e
@ -16,7 +16,7 @@
|
||||
</div>
|
||||
|
||||
<button id="mainPairingButton" class="primary-btn">Authenticate with Browser</button>
|
||||
|
||||
|
||||
<div class="account-actions">
|
||||
<button id="deleteAccountButton" class="danger-btn">🗑️ Delete Account</button>
|
||||
</div>
|
||||
|
||||
@ -120,7 +120,7 @@ export async function initHomePage(): Promise<void> {
|
||||
|
||||
// Set up main pairing interface
|
||||
setupMainPairing();
|
||||
|
||||
|
||||
// Set up account actions
|
||||
setupAccountActions();
|
||||
|
||||
@ -604,9 +604,9 @@ async function handleMainPairing(): Promise<void> {
|
||||
// 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<void> {
|
||||
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<void> {
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if (mainStatus) {
|
||||
mainStatus.innerHTML = '<div class="spinner"></div><span>Deleting account and all data...</span>';
|
||||
}
|
||||
|
||||
|
||||
// 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<void> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Clear service worker caches
|
||||
if ('caches' in window) {
|
||||
const cacheNames = await caches.keys();
|
||||
@ -681,19 +681,19 @@ async function handleDeleteAccount(): Promise<void> {
|
||||
cacheNames.map(cacheName => caches.delete(cacheName))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (mainStatus) {
|
||||
mainStatus.innerHTML = '<span style="color: var(--success-color)">✅ Account and all data deleted successfully</span>';
|
||||
}
|
||||
|
||||
|
||||
// Reload the page to start fresh
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 2000);
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.error('Account deletion failed:', error);
|
||||
|
||||
|
||||
if (mainStatus) {
|
||||
mainStatus.innerHTML = '<span style="color: var(--error-color)">❌ Failed to delete account</span>';
|
||||
}
|
||||
|
||||
@ -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<string, RoleDefinition>[] = [];
|
||||
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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user