refactor service
This commit is contained in:
parent
b7a2f3a058
commit
d950ce0a2b
@ -164,9 +164,8 @@ async function populateAutocompleteList(select: HTMLSelectElement, query: string
|
|||||||
let options_to_show = [];
|
let options_to_show = [];
|
||||||
|
|
||||||
const service = await Services.getInstance();
|
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 allProcesses = new Set(Object.keys(await service.getProcesses()));
|
||||||
const mineArray = Array.from(myProcesses);
|
|
||||||
const allArray = Array.from(allProcesses.difference(myProcesses));
|
const allArray = Array.from(allProcesses.difference(myProcesses));
|
||||||
|
|
||||||
const wrapper = select.parentNode;
|
const wrapper = select.parentNode;
|
||||||
|
@ -146,11 +146,6 @@ export async function init(): Promise<void> {
|
|||||||
}
|
}
|
||||||
await services.restoreProcessesFromDB();
|
await services.restoreProcessesFromDB();
|
||||||
await services.restoreSecretsFromDB();
|
await services.restoreSecretsFromDB();
|
||||||
setTimeout(async () => {
|
|
||||||
const myProcesses = await services.getMyProcesses();
|
|
||||||
const db = await Database.getInstance();
|
|
||||||
await db.updateMyProcesses(myProcesses);
|
|
||||||
}, 200);
|
|
||||||
|
|
||||||
if (services.isPaired()) {
|
if (services.isPaired()) {
|
||||||
await navigate('process');
|
await navigate('process');
|
||||||
|
@ -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) {
|
public async handleApiReturn(apiReturn: ApiReturn) {
|
||||||
console.log(apiReturn);
|
console.log(apiReturn);
|
||||||
if (apiReturn.new_tx_to_send && apiReturn.new_tx_to_send.transaction.length != 0) {
|
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
|
// Save process to db
|
||||||
await this.saveProcessToDb(processId, updatedProcess.current_process);
|
await this.saveProcessToDb(processId, updatedProcess.current_process);
|
||||||
|
|
||||||
setTimeout(async () => {
|
|
||||||
try {
|
|
||||||
await this.updateProcessesWorker();
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
}, 0)
|
|
||||||
|
|
||||||
const isPaired = this.isPaired();
|
const isPaired = this.isPaired();
|
||||||
|
|
||||||
if (updatedProcess.diffs && updatedProcess.diffs.length != 0) {
|
if (updatedProcess.diffs && updatedProcess.diffs.length != 0) {
|
||||||
@ -1135,8 +1117,6 @@ export default class Services {
|
|||||||
for (const [processId, process] of Object.entries(newProcesses)) {
|
for (const [processId, process] of Object.entries(newProcesses)) {
|
||||||
const existing = await this.getProcess(processId);
|
const existing = await this.getProcess(processId);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
console.log(`${processId} already in db`);
|
|
||||||
|
|
||||||
const event = new CustomEvent('process-updated', {
|
const event = new CustomEvent('process-updated', {
|
||||||
detail: { processId }
|
detail: { processId }
|
||||||
});
|
});
|
||||||
@ -1152,7 +1132,6 @@ export default class Services {
|
|||||||
await this.saveProcessToDb(processId, process as Process);
|
await this.saveProcessToDb(processId, process as Process);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await this.updateProcessesWorker();
|
|
||||||
}
|
}
|
||||||
}, 500)
|
}, 500)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -1193,15 +1172,13 @@ export default class Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMyProcesses(): Promise<Set<string>> {
|
public async getMyProcesses(): Promise<string[]> {
|
||||||
try {
|
try {
|
||||||
const processes = await this.getProcesses();
|
const processes = await this.getProcesses();
|
||||||
const userProcessSet = new Set<string>();
|
|
||||||
|
|
||||||
for (const [processId, process] of Object.entries(processes)) {
|
for (const [processId, process] of Object.entries(processes)) {
|
||||||
// We use myProcesses attribute to not reevaluate all processes everytime
|
// We use myProcesses attribute to not reevaluate all processes everytime
|
||||||
if (this.myProcesses && this.myProcesses.has(processId)) {
|
if (this.myProcesses && this.myProcesses.has(processId)) {
|
||||||
userProcessSet.add(processId);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -1209,13 +1186,12 @@ export default class Services {
|
|||||||
|
|
||||||
if (this.rolesContainsUs(roles)) {
|
if (this.rolesContainsUs(roles)) {
|
||||||
this.myProcesses.add(processId);
|
this.myProcesses.add(processId);
|
||||||
userProcessSet.add(processId);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return userProcessSet;
|
return Array.from(this.myProcesses);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to get processes:", e);
|
console.error("Failed to get processes:", e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user