From 05dddd956792a48e12dc19b8b127d8e18e275db6 Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Fri, 21 Mar 2025 10:47:18 +0100 Subject: [PATCH] new member name service ok --- src/pages/account/account.ts | 65 ++++++++++++++++++++++++------------ src/services/service.ts | 65 ++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 21 deletions(-) diff --git a/src/pages/account/account.ts b/src/pages/account/account.ts index 1ba3a89..ea9f582 100755 --- a/src/pages/account/account.ts +++ b/src/pages/account/account.ts @@ -141,7 +141,7 @@ class AccountElement extends HTMLElement { @@ -805,14 +805,10 @@ private handleAvatarUpload(event: Event): void { } -private showProcess(): void { - //console.log("showProcess called"); +private async showProcess(): Promise { currentMode = 'process'; this.hideAllContent(); - const headerTitle = this.shadowRoot?.getElementById('header-title'); - if (headerTitle) headerTitle.textContent = 'Process'; - const processContent = this.shadowRoot?.getElementById('process-content'); if (processContent) { processContent.style.display = 'block'; @@ -827,32 +823,59 @@ private showProcess(): void { Notifications - + + + Loading processes... + + `; - - - this.updateProcessTableContent(mockProcessRows); + + try { + const service = await Services.getInstance(); + const myProcesses = await service.getMyProcesses(); + this.updateProcessTableContent(myProcesses); + } catch (error) { + console.error('Error loading processes:', error); + const tbody = processContent.querySelector('tbody'); + if (tbody) { + tbody.innerHTML = ` + + + Error loading processes. Please try again later. + + + `; + } + } } } -// Fonction utilitaire pour mettre Γ  jour le contenu du tableau Process -private updateProcessTableContent(rows: any[]): void { +private updateProcessTableContent(processes: any[]): void { const tbody = this.shadowRoot?.querySelector('#process-table tbody'); if (!tbody) return; - tbody.innerHTML = rows.map(row => ` + if (processes.length === 0) { + tbody.innerHTML = ` + + No processes found + + `; + return; + } + + tbody.innerHTML = processes.map(process => ` - ${row.process} - ${row.role} + ${process.name || 'N/A'} + ${process.role || 'N/A'} -
+
- - ${row.notification?.messages?.filter((m: any) => !m.read).length || 0}/${row.notification?.messages?.length || 0} + + ${process.notifications?.unread || 0}/${process.notifications?.total || 0}
@@ -1014,7 +1037,7 @@ private async showPairing(): Promise {
- +
`; @@ -1283,10 +1306,10 @@ private openAvatarPopup(): void { Name: -
+
Address: ${savedAddress} diff --git a/src/services/service.ts b/src/services/service.ts index 11333b2..a8ba4fb 100755 --- a/src/services/service.ts +++ b/src/services/service.ts @@ -399,6 +399,51 @@ export default class Services { } } + public async createProfileProcess(): Promise { + const myProcessId: string = this.getPairingProcessId(); + const roles: Record = { + owner: { + members: [{ process_id: myProcessId }], + validation_rules: [ + { + quorum: 0.01, + fields: ['description', 'relayDomaine', 'serviceDomaine'], + min_sig_member: 0.01, + }, + ], + storages: [STORAGEURL] + }, + blm: { + members: [{}], + validation_rules: [ + { + quorum: 0.0, + fields: ['description', 'ourDomaine', 'serviceDomaine'], + min_sig_member: 0.0, + }, + ], + storages: [STORAGEURL] + }, + }; + const profileTemplate = { + description: 'profile', + }; + const publicData = {} + const relayAddress = this.getAllRelays()[0]['spAddress']; + const feeRate = 1; + try { + return this.sdkClient.create_new_process( + profileTemplate, + roles, + publicData, + relayAddress, + feeRate + ); + } catch (e) { + throw new Error(`Creating process failed:, ${e}`); + } + } + private async lookForNotaryProcess(): Promise { const processes = await this.getMyProcesses(); for (const processId of processes) { @@ -1370,4 +1415,24 @@ export default class Services { return false; } } + + public async updateMemberPublicName(process: Process, newName: string): Promise { + const lastState = this.getLastCommitedState(process); + if (!lastState) { + throw new Error('No committed state found'); + } + + // Create new state with updated memberPublicName + const newState = { + ...lastState, + public_data: { + ...lastState.public_data, + memberPublicName: newName, + pairedAddresses: lastState.public_data.pairedAddresses // PrΓ©server les adresses existantes + } + }; + + // Update the process with new state + return await this.updateProcess(process, newState, null); + } }