Merge branch 'ihm_unify_clean_base' of https://git.4nkweb.com/4nk/ihm_client into ihm_unify_clean_base
This commit is contained in:
commit
36db809589
@ -36,7 +36,7 @@ export async function init() {
|
||||
|
||||
const processes = await getProcesses();
|
||||
for (let process of processes) {
|
||||
const processName = process[1].title;
|
||||
const processName = process['description'];
|
||||
const opt = new Option(processName);
|
||||
opt.value = processName;
|
||||
element.add(opt);
|
||||
@ -364,7 +364,7 @@ async function showSelectedProcess(elem: MouseEvent) {
|
||||
titleDiv.className = 'process-title';
|
||||
titleDiv.innerHTML = `${process[1].title} : ${process[1].description}`;
|
||||
processDiv.appendChild(titleDiv);
|
||||
for (const zone of process[1].zones) {
|
||||
for (const zone of process.zones) {
|
||||
const zoneElement = document.createElement('div');
|
||||
zoneElement.className = 'process-element';
|
||||
const zoneId = process[1].title + '-' + zone.id;
|
||||
@ -408,5 +408,10 @@ async function getProcesses(): Promise<any[]> {
|
||||
const service = await Services.getInstance();
|
||||
const processes = await service.getProcesses();
|
||||
|
||||
return processes;
|
||||
const res = Object.entries(processes).map(([key, value]) => ({
|
||||
key,
|
||||
value
|
||||
}))
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -13,13 +13,13 @@ class Database {
|
||||
indices: [],
|
||||
},
|
||||
AnkProcess: {
|
||||
name: 'process',
|
||||
options: { keyPath: 'id' },
|
||||
name: 'processes',
|
||||
options: {},
|
||||
indices: [],
|
||||
},
|
||||
AnkSharedSecrets: {
|
||||
name: 'shared_secrets',
|
||||
options: { keyPath: 'key' },
|
||||
options: {},
|
||||
indices: [],
|
||||
},
|
||||
AnkUnconfirmedSecrets: {
|
||||
@ -27,11 +27,6 @@ class Database {
|
||||
options: { autoIncrement: true },
|
||||
indices: [],
|
||||
},
|
||||
AnkProcessData: {
|
||||
name: 'process-data',
|
||||
options: { keyPath: 'id' },
|
||||
indices: [],
|
||||
},
|
||||
};
|
||||
|
||||
// Private constructor to prevent direct instantiation from outside
|
||||
@ -191,6 +186,36 @@ class Database {
|
||||
});
|
||||
return result
|
||||
}
|
||||
|
||||
public async dumpStore(storeName: string): Promise<Record<string, any>> {
|
||||
const db = await this.getDb();
|
||||
const tx = db.transaction(storeName, 'readonly');
|
||||
const store = tx.objectStore(storeName);
|
||||
|
||||
try {
|
||||
// Wait for both getAllKeys() and getAll() to resolve
|
||||
const [keys, values] = await Promise.all([
|
||||
new Promise<any[]>((resolve, reject) => {
|
||||
const request = store.getAllKeys();
|
||||
request.onsuccess = () => resolve(request.result);
|
||||
request.onerror = () => reject(request.error);
|
||||
}),
|
||||
new Promise<any[]>((resolve, reject) => {
|
||||
const request = store.getAll();
|
||||
request.onsuccess = () => resolve(request.result);
|
||||
request.onerror = () => reject(request.error);
|
||||
}),
|
||||
]);
|
||||
|
||||
// Combine keys and values into an object
|
||||
const result: Record<string, any> = Object.fromEntries(keys.map((key, index) => [key, values[index]]));
|
||||
return result;
|
||||
|
||||
} catch (error) {
|
||||
console.error("Error fetching data from IndexedDB:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Database;
|
||||
|
@ -3,7 +3,7 @@ import { INotification } from '~/models/notification.model';
|
||||
import { IProcess } from '~/models/process.model';
|
||||
// import Database from './database';
|
||||
import { initWebsocket, sendMessage } from '../websockets';
|
||||
import { ApiReturn, Member } from '../../dist/pkg/sdk_client';
|
||||
import { ApiReturn, Member, Process } from '../../dist/pkg/sdk_client';
|
||||
import ModalService from './modal.service';
|
||||
import { navigate } from '../router';
|
||||
import Database from './database.service';
|
||||
@ -52,7 +52,7 @@ export default class Services {
|
||||
|
||||
public async init(): Promise<void> {
|
||||
this.notifications = this.getNotifications();
|
||||
this.sdkClient = await import('../../dist/pkg/sdk_client');
|
||||
this.sdkClient = await import('../../pkg/sdk_client');
|
||||
this.sdkClient.setup();
|
||||
await this.addWebsocketConnection(wsurl);
|
||||
}
|
||||
@ -298,23 +298,25 @@ export default class Services {
|
||||
for (const entry of entries) {
|
||||
db.addObject({
|
||||
storeName: 'shared_secrets',
|
||||
object: entry,
|
||||
key: null,
|
||||
object: entry.value,
|
||||
key: entry.key,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(async () => {
|
||||
if (apiReturn.updated_process && apiReturn.updated_process.length) {
|
||||
const [commitmentTx, process] = apiReturn.updated_process;
|
||||
if (apiReturn.updated_process) {
|
||||
const updatedProcess = apiReturn.updated_process;
|
||||
|
||||
// Save process to storage
|
||||
const db = await Database.getInstance();
|
||||
db.addObject({
|
||||
storeName: 'process',
|
||||
object: { id: commitmentTx, process },
|
||||
key: null,
|
||||
});
|
||||
try {
|
||||
await this.saveProcess(updatedProcess.commitment_tx, updatedProcess.current_process);
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
// do we need to act?
|
||||
updatedProcess.user_validation_required
|
||||
}
|
||||
|
||||
if (apiReturn.commit_to_send) {
|
||||
@ -444,86 +446,46 @@ export default class Services {
|
||||
}
|
||||
}
|
||||
|
||||
async getProcesses(): Promise<any[]> {
|
||||
const process = [
|
||||
[
|
||||
'1',
|
||||
{
|
||||
title: 'Messaging',
|
||||
description: 'Messagerie chiffrée',
|
||||
html: '<div><input /></div>',
|
||||
css: '',
|
||||
script: '',
|
||||
zones: [
|
||||
{
|
||||
id: '1',
|
||||
title: 'zone 1',
|
||||
description: 'zone 1',
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
title: 'zone 2',
|
||||
description: 'zone 2',
|
||||
},
|
||||
],
|
||||
roles: {
|
||||
owner: {
|
||||
members: ['dfdsfdfdsf', 'dfdfdfdsfsfdfdsf'],
|
||||
validation_rules: [
|
||||
{
|
||||
quorum: 1.0,
|
||||
fields: ['description', 'roles', 'session_privkey', 'session_pubkey', 'key_parity'],
|
||||
min_sig_member: 1.0,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
[
|
||||
'2',
|
||||
{
|
||||
title: 'Database',
|
||||
description: 'Database chiffrée',
|
||||
html: '<div><input value="{{inputValue}}" /></div>',
|
||||
css: '',
|
||||
script: '',
|
||||
zones: [
|
||||
{
|
||||
id: '1',
|
||||
title: 'zone 1',
|
||||
description: 'zone 1',
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
title: 'zone 2',
|
||||
description: 'zone 2',
|
||||
},
|
||||
],
|
||||
roles: {
|
||||
owner: {
|
||||
members: ['dfdsfdfdsf', 'dfdfdfdsfsfdfdsf'],
|
||||
validation_rules: [
|
||||
{
|
||||
quorum: 1.0,
|
||||
fields: ['description', 'roles', 'session_privkey', 'session_pubkey', 'key_parity'],
|
||||
min_sig_member: 1.0,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
];
|
||||
return process;
|
||||
public async saveProcess(commitedIn: string, process: any) {
|
||||
const db = await Database.getInstance();
|
||||
try {
|
||||
await db.addObject({
|
||||
storeName: 'processes',
|
||||
object: process,
|
||||
key: commitedIn,
|
||||
});
|
||||
} catch (e) {
|
||||
throw new Error(`Failed to save process: ${e}`)
|
||||
}
|
||||
}
|
||||
|
||||
private getProcessesCache() {
|
||||
console.log('TODO get processes from indexedDB')
|
||||
public async getProcess(commitedIn: string): Promise<Process> {
|
||||
const db = await Database.getInstance();
|
||||
return await db.getObject('processes', commitedIn);
|
||||
}
|
||||
|
||||
public async getProcesses(): Promise<Record<string, Process>> {
|
||||
const db = await Database.getInstance();
|
||||
|
||||
const processes: Record<string, Process> = await db.dumpStore('processes');
|
||||
return processes;
|
||||
}
|
||||
|
||||
// Restore process in wasm with persistent storage
|
||||
public async restoreProcesses() {
|
||||
console.log('TODO: restore processes from indexedDB');
|
||||
const db = await Database.getInstance();
|
||||
try {
|
||||
const processes: Record<string, Process> = await db.dumpStore('processes');
|
||||
if (processes && Object.keys(processes).length != 0) {
|
||||
console.log(`Restoring ${Object.keys(processes).length} processes`);
|
||||
this.sdkClient.set_process_cache(JSON.stringify(processes));
|
||||
} else {
|
||||
console.log('No processes to restore!');
|
||||
}
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
getNotifications(): INotification[] {
|
||||
|
@ -166,14 +166,15 @@ async function onOkButtonClick() {
|
||||
if (!createPairingProcessReturn.updated_process) {
|
||||
throw new Error('createPairingProcess returned an empty new process'); // This should never happen
|
||||
}
|
||||
const [commitmentOutpoint, process] = createPairingProcessReturn.updated_process;
|
||||
|
||||
const commitmentOutpoint = createPairingProcessReturn.updated_process.commitment_tx;
|
||||
|
||||
// We set the service to the process
|
||||
service.getUpdateProposals(commitmentOutpoint);
|
||||
|
||||
await service.evaluatePendingUpdates();
|
||||
} catch (e) {
|
||||
console.error('onOkButtonClick error:', e);
|
||||
console.error(`onOkButtonClick error: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user