Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/acpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
IAcpJob,
IAcpMemoData,
IAcpResponse,
IAcpMemoContent,
} from "./interfaces";
import AcpError from "./acpError";
import { FareAmountBase } from "./acpFare";
Expand Down Expand Up @@ -374,6 +375,7 @@ class AcpClient {
job.phase,
job.context,
job.contractAddress,
job.deliverable,
job.netPayableAmount
);
} catch (err) {
Expand Down Expand Up @@ -745,7 +747,7 @@ class AcpClient {
}

async createMemoContent(jobId: number, content: string) {
const response = await this._fetch(
const response = await this._fetch<IAcpMemoContent>(
`/memo-contents`,
"POST",
{},
Expand Down
26 changes: 18 additions & 8 deletions src/acpJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class AcpJob {
public phase: AcpJobPhases,
public context: Record<string, any>,
public contractAddress: Address,
public deliverable: DeliverablePayload | null,
public netPayableAmount?: number
) {
const content = this.memos.find(
Expand Down Expand Up @@ -90,11 +91,6 @@ class AcpJob {
return this.acpContractClient.config.baseFare;
}

public get deliverable() {
return this.memos.find((m) => m.nextPhase === AcpJobPhases.COMPLETED)
?.content;
}

public get rejectionReason() {
const requestMemo = this.memos.find(
(m) =>
Expand Down Expand Up @@ -436,13 +432,22 @@ class AcpJob {
}

async deliver(deliverable: DeliverablePayload) {
if (this.phase !== AcpJobPhases.TRANSACTION) {
throw new AcpError("Job is not in transaction phase");
}

const operations: OperationPayload[] = [];

const memoContent = await this.acpClient.createMemoContent(
this.id,
preparePayload(deliverable)
);

operations.push(
this.acpContractClient.createMemo(
this.id,
preparePayload(deliverable),
MemoType.MESSAGE,
memoContent?.url,
MemoType.CONTEXT_URL,
true,
AcpJobPhases.COMPLETED
)
Expand Down Expand Up @@ -480,10 +485,15 @@ class AcpJob {
const isPercentagePricing: boolean =
this.priceType === PriceType.PERCENTAGE && !skipFee;

const memoContent = await this.acpClient.createMemoContent(
this.id,
preparePayload(deliverable)
);

operations.push(
this.acpContractClient.createPayableMemo(
this.id,
preparePayload(deliverable),
memoContent.url,
amount.amount,
this.clientAddress,
isPercentagePricing
Expand Down
8 changes: 7 additions & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export enum AcpMemoState {
PENDING,
IN_PROGRESS,
FAILED,
COMPLETED
COMPLETED,
}

export interface PayableDetails {
Expand Down Expand Up @@ -254,3 +254,9 @@ export type CheckTransactionConfig = {
};
tag?: "pending";
};

export type IAcpMemoContent = {
id: number;
content: string;
url: string;
};
Loading