Skip to content

Commit 890f735

Browse files
committed
feat: completes job.reject() and job.rejectionReason
1 parent 77da4ae commit 890f735

1 file changed

Lines changed: 37 additions & 8 deletions

File tree

src/acpJob.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,31 @@ class AcpJob {
9191
return this.acpContractClient.config.baseFare;
9292
}
9393

94-
public get rejectionReason() {
95-
const requestMemo = this.memos.find(
94+
public get rejectionReason(): {
95+
rejectedBy: Address,
96+
reason: string | undefined
97+
} | undefined {
98+
const rejectedMemo: AcpMemo | undefined = this.memos.find(
9699
(m) =>
97-
m.nextPhase === AcpJobPhases.NEGOTIATION &&
98100
m.status === AcpMemoStatus.REJECTED
99101
);
100102

101-
if (requestMemo) {
102-
return requestMemo.signedReason;
103+
if (rejectedMemo) {
104+
return {
105+
rejectedBy: rejectedMemo.senderAddress,
106+
reason: rejectedMemo.signedReason
107+
};
103108
}
104109

105-
return this.memos.find((m) => m.nextPhase === AcpJobPhases.REJECTED)
106-
?.content;
110+
const rejectJobMemo: AcpMemo | undefined = this.memos.find((m) => m.nextPhase === AcpJobPhases.REJECTED);
111+
if (rejectJobMemo) {
112+
return {
113+
rejectedBy: rejectJobMemo.senderAddress,
114+
reason: rejectJobMemo.content,
115+
};
116+
}
117+
118+
return undefined;
107119
}
108120

109121
public get providerAgent() {
@@ -396,14 +408,31 @@ class AcpJob {
396408
async reject(reason?: string) {
397409
const memoContent = `Job ${this.id} rejected. ${reason || ""}`;
398410

399-
if (this.phase === AcpJobPhases.REQUEST) {
411+
const isProviderRequestPhase: boolean = (
412+
this.providerAddress === this.acpClient.walletAddress &&
413+
this.phase === AcpJobPhases.REQUEST
414+
);
415+
const isClientPaymentPhase: boolean = (
416+
this.clientAddress === this.acpClient.walletAddress &&
417+
this.phase === AcpJobPhases.NEGOTIATION
418+
);
419+
420+
if (isProviderRequestPhase) {
400421
const latestMemo = this.latestMemo;
401422
if (latestMemo?.nextPhase !== AcpJobPhases.NEGOTIATION) {
402423
throw new AcpError("No request memo found");
403424
}
404425
return await latestMemo.sign(false, memoContent);
405426
}
406427

428+
if (isClientPaymentPhase) {
429+
const latestMemo = this.latestMemo;
430+
if (latestMemo?.nextPhase !== AcpJobPhases.TRANSACTION) {
431+
throw new AcpError("No payment memo found");
432+
}
433+
return await latestMemo.sign(false, memoContent);
434+
}
435+
407436
const operations: OperationPayload[] = [];
408437
operations.push(
409438
this.acpContractClient.createMemo(

0 commit comments

Comments
 (0)