new member name service ok

This commit is contained in:
NicolasCantu 2025-03-21 10:47:18 +01:00
parent d54ce71f02
commit 05dddd9567
2 changed files with 109 additions and 21 deletions

View File

@ -141,7 +141,7 @@ class AccountElement extends HTMLElement {
<!-- User Info Section -->
<div class="popup-info">
<p><strong>Name:</strong> <span class="editable" id="popup-name"></span></p>
<p><strong>Last Name:</strong> <span class="editable" id="popup-lastname"></span></p>
<!--<p><strong>Last Name:</strong> <span class="editable" id="popup-lastname"></span></p>-->
<p><strong>Address:</strong> 🏠 🌍 🗽🎊😩-🎊😑🎄😩</p>
</div>
@ -805,14 +805,10 @@ private handleAvatarUpload(event: Event): void {
}
private showProcess(): void {
//console.log("showProcess called");
private async showProcess(): Promise<void> {
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 {
<th>Notifications</th>
</tr>
</thead>
<tbody></tbody>
<tbody>
<tr>
<td colspan="3">Loading processes...</td>
</tr>
</tbody>
</table>
</div>
`;
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 = `
<tr>
<td colspan="3" class="error-message">
Error loading processes. Please try again later.
</td>
</tr>
`;
}
}
}
}
// 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 = `
<tr>
<td colspan="3">No processes found</td>
</tr>
`;
return;
}
tbody.innerHTML = processes.map(process => `
<tr>
<td>${row.process}</td>
<td>${row.role}</td>
<td>${process.name || 'N/A'}</td>
<td>${process.role || 'N/A'}</td>
<td>
<div class="notification-container" onclick="window.showProcessNotifications('${row.process}')">
<div class="notification-container" onclick="window.showProcessNotifications('${process.id}')">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" width="16" height="16">
<path d="M224 0c-17.7 0-32 14.3-32 32V51.2C119 66 64 130.6 64 208v18.8c0 47-17.3 92.4-48.5 127.6l-7.4 8.3c-8.4 9.4-10.4 22.9-5.3 34.4S19.4 416 32 416H416c12.6 0 24-7.4 29.2-18.9s3.1-25-5.3-34.4l-7.4-8.3C401.3 319.2 384 273.9 384 226.8V208c0-77.4-55-142-128-156.8V32c0-17.7-14.3-32-32-32zm45.3 493.3c12-12 18.7-28.3 18.7-45.3H160c0 17 6.7 33.3 18.7 45.3s28.3 18.7 45.3 18.7s33.3-6.7 45.3-18.7z"/>
</svg>
<span class="notification-count" data-process="${row.process}">
${row.notification?.messages?.filter((m: any) => !m.read).length || 0}/${row.notification?.messages?.length || 0}
<span class="notification-count" data-process="${process.id}">
${process.notifications?.unread || 0}/${process.notifications?.total || 0}
</span>
</div>
</td>
@ -1014,7 +1037,7 @@ private async showPairing(): Promise<void> {
<tbody></tbody>
</table>
<div class="button-container">
<button class="add-row-button button-style" onclick="window.addRowPairing()">Add a line</button>
<button class="add-row-button button-style" onclick="window.addRowPairing()">Add a device</button>
</div>
</div>
`;
@ -1283,10 +1306,10 @@ private openAvatarPopup(): void {
<strong>Name:</strong>
<input type="text" id="userName" value="${savedName}" class="editable">
</div>
<div class="info-row">
<!--<div class="info-row">
<strong>Last Name:</strong>
<input type="text" id="userLastName" value="${savedLastName}" class="editable">
</div>
</div>-->
<div class="info-row">
<strong>Address:</strong>
<span>${savedAddress}</span>

View File

@ -399,6 +399,51 @@ export default class Services {
}
}
public async createProfileProcess(): Promise<ApiReturn> {
const myProcessId: string = this.getPairingProcessId();
const roles: Record<string, RoleDefinition> = {
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<string | null> {
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<ApiReturn> {
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);
}
}