refactor service

This commit is contained in:
NicolasCantu 2025-02-26 09:32:00 +01:00
parent b7a2f3a058
commit d950ce0a2b
3 changed files with 3 additions and 33 deletions

View File

@ -164,9 +164,8 @@ async function populateAutocompleteList(select: HTMLSelectElement, query: string
let options_to_show = [];
const service = await Services.getInstance();
const myProcesses = await service.getMyProcesses();
const mineArray = await service.getMyProcesses();
const allProcesses = new Set(Object.keys(await service.getProcesses()));
const mineArray = Array.from(myProcesses);
const allArray = Array.from(allProcesses.difference(myProcesses));
const wrapper = select.parentNode;

View File

@ -146,11 +146,6 @@ export async function init(): Promise<void> {
}
await services.restoreProcessesFromDB();
await services.restoreSecretsFromDB();
setTimeout(async () => {
const myProcesses = await services.getMyProcesses();
const db = await Database.getInstance();
await db.updateMyProcesses(myProcesses);
}, 200);
if (services.isPaired()) {
await navigate('process');

View File

@ -534,16 +534,6 @@ export default class Services {
}
}
public async updateProcessesWorker() {
try {
const myProcesses = await this.getMyProcesses();
const db = await Database.getInstance();
await db.updateMyProcesses(myProcesses);
} catch (e) {
console.error('Failed to update processes worker:', e);
}
}
public async handleApiReturn(apiReturn: ApiReturn) {
console.log(apiReturn);
if (apiReturn.new_tx_to_send && apiReturn.new_tx_to_send.transaction.length != 0) {
@ -601,14 +591,6 @@ export default class Services {
// Save process to db
await this.saveProcessToDb(processId, updatedProcess.current_process);
setTimeout(async () => {
try {
await this.updateProcessesWorker();
} catch (e) {
console.error(e);
}
}, 0)
const isPaired = this.isPaired();
if (updatedProcess.diffs && updatedProcess.diffs.length != 0) {
@ -1135,8 +1117,6 @@ export default class Services {
for (const [processId, process] of Object.entries(newProcesses)) {
const existing = await this.getProcess(processId);
if (existing) {
console.log(`${processId} already in db`);
const event = new CustomEvent('process-updated', {
detail: { processId }
});
@ -1152,7 +1132,6 @@ export default class Services {
await this.saveProcessToDb(processId, process as Process);
}
}
await this.updateProcessesWorker();
}
}, 500)
} catch (e) {
@ -1193,15 +1172,13 @@ export default class Services {
}
}
async getMyProcesses(): Promise<Set<string>> {
public async getMyProcesses(): Promise<string[]> {
try {
const processes = await this.getProcesses();
const userProcessSet = new Set<string>();
for (const [processId, process] of Object.entries(processes)) {
// We use myProcesses attribute to not reevaluate all processes everytime
if (this.myProcesses && this.myProcesses.has(processId)) {
userProcessSet.add(processId);
continue;
}
try {
@ -1209,13 +1186,12 @@ export default class Services {
if (this.rolesContainsUs(roles)) {
this.myProcesses.add(processId);
userProcessSet.add(processId);
}
} catch (e) {
console.error(e);
}
}
return userProcessSet;
return Array.from(this.myProcesses);
} catch (e) {
console.error("Failed to get processes:", e);
}