From 3f42cb27a7fc2fdfdf1a55c98bf63d028bc1d8d0 Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Wed, 26 Mar 2025 14:44:00 +0100 Subject: [PATCH] Slight refactoring and cleanup --- src/services/service.ts | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/services/service.ts b/src/services/service.ts index c16c1ac..a5d8c41 100755 --- a/src/services/service.ts +++ b/src/services/service.ts @@ -529,8 +529,11 @@ export default class Services { } } - // Create prd update for current process and update - public createPrdUpdate(processId: string, stateId: string): ApiReturn { + public async createPrdUpdate(processId: string, stateId: string): Promise { + const process = await this.getProcess(processId); + if (!process) { + throw new Error('Unknown process'); + } try { return this.sdkClient.create_update_message(process, stateId, this.getAllMembers()); } catch (e) { @@ -538,15 +541,15 @@ export default class Services { } } - public createPrdResponse(pcdMerkleRoot: string): ApiReturn { - if (!this.currentProcess) { - throw new Error('No current process defined'); + public async createPrdResponse(processId: string, stateId: string): Promise { + const process = await this.getProcess(processId); + if (!process) { + throw new Error('Unknown process'); } - try { return this.sdkClient.create_response_prd(process, pcdMerkleRoot, this.getAllMembers()); } catch (e) { - throw e; + throw new Error(`Failed to create response prd: ${e}`); } } @@ -686,8 +689,8 @@ export default class Services { if (updatedProcess.encrypted_data && Object.keys(updatedProcess.encrypted_data).length != 0) { for (const [hash, cipher] of Object.entries(updatedProcess.encrypted_data)) { - console.log(hash); - console.log(cipher); + // console.log(hash); + // console.log(cipher); const blob = this.hexToBlob(cipher); try { await this.saveBlobToDb(hash, blob); @@ -730,9 +733,14 @@ export default class Services { } } - public async openPairingConfirmationModal(firstState: ProcessState) { + public async openPairingConfirmationModal(processId: string) { + const process = await this.getProcess(processId); + if (!process) { + console.error('Failed to find pairing process'); + return; + } + const firstState = process.states[0]; const roles = firstState.roles; - const processId = firstState.commited_in; const stateId = firstState.state_id; try { await this.routingInstance.openPairingConfirmationModal(roles, processId, stateId);