Slight refactoring and cleanup

This commit is contained in:
NicolasCantu 2025-03-26 14:44:00 +01:00
parent 2601418aaf
commit 3f42cb27a7

View File

@ -529,8 +529,11 @@ export default class Services {
} }
} }
// Create prd update for current process and update public async createPrdUpdate(processId: string, stateId: string): Promise<ApiReturn> {
public createPrdUpdate(processId: string, stateId: string): ApiReturn { const process = await this.getProcess(processId);
if (!process) {
throw new Error('Unknown process');
}
try { try {
return this.sdkClient.create_update_message(process, stateId, this.getAllMembers()); return this.sdkClient.create_update_message(process, stateId, this.getAllMembers());
} catch (e) { } catch (e) {
@ -538,15 +541,15 @@ export default class Services {
} }
} }
public createPrdResponse(pcdMerkleRoot: string): ApiReturn { public async createPrdResponse(processId: string, stateId: string): Promise<ApiReturn> {
if (!this.currentProcess) { const process = await this.getProcess(processId);
throw new Error('No current process defined'); if (!process) {
throw new Error('Unknown process');
} }
try { try {
return this.sdkClient.create_response_prd(process, pcdMerkleRoot, this.getAllMembers()); return this.sdkClient.create_response_prd(process, pcdMerkleRoot, this.getAllMembers());
} catch (e) { } 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) { if (updatedProcess.encrypted_data && Object.keys(updatedProcess.encrypted_data).length != 0) {
for (const [hash, cipher] of Object.entries(updatedProcess.encrypted_data)) { for (const [hash, cipher] of Object.entries(updatedProcess.encrypted_data)) {
console.log(hash); // console.log(hash);
console.log(cipher); // console.log(cipher);
const blob = this.hexToBlob(cipher); const blob = this.hexToBlob(cipher);
try { try {
await this.saveBlobToDb(hash, blob); 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 roles = firstState.roles;
const processId = firstState.commited_in;
const stateId = firstState.state_id; const stateId = firstState.state_id;
try { try {
await this.routingInstance.openPairingConfirmationModal(roles, processId, stateId); await this.routingInstance.openPairingConfirmationModal(roles, processId, stateId);