Skip to content

Commit 0195ffc

Browse files
author
Zuhwa
committed
Skip x402 payment for zero budget
1 parent 5b67963 commit 0195ffc

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

src/acpJob.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ class AcpJob {
160160
}
161161

162162
const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
163-
const isPercentagePricing: boolean = this.priceType === PriceType.PERCENTAGE;
163+
const isPercentagePricing: boolean =
164+
this.priceType === PriceType.PERCENTAGE;
164165

165166
operations.push(
166167
this.acpContractClient.createPayableMemo(
@@ -171,9 +172,7 @@ class AcpJob {
171172
isPercentagePricing
172173
? BigInt(Math.round(this.priceValue * 10000)) // convert to basis points
173174
: feeAmount.amount,
174-
isPercentagePricing
175-
? FeeType.PERCENTAGE_FEE
176-
: FeeType.NO_FEE,
175+
isPercentagePricing ? FeeType.PERCENTAGE_FEE : FeeType.NO_FEE,
177176
AcpJobPhases.TRANSACTION,
178177
type,
179178
expiredAt,
@@ -241,11 +240,13 @@ class AcpJob {
241240
)
242241
);
243242

244-
const x402PaymentDetails =
245-
await this.acpContractClient.getX402PaymentDetails(this.id);
243+
if (this.price > 0) {
244+
const x402PaymentDetails =
245+
await this.acpContractClient.getX402PaymentDetails(this.id);
246246

247-
if (x402PaymentDetails.isX402) {
248-
await this.performX402Payment(this.price);
247+
if (x402PaymentDetails.isX402) {
248+
await this.performX402Payment(this.price);
249+
}
249250
}
250251

251252
return await this.acpContractClient.handleOperation(operations);
@@ -371,7 +372,8 @@ class AcpJob {
371372
);
372373

373374
const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
374-
const isPercentagePricing: boolean = this.priceType === PriceType.PERCENTAGE && !skipFee;
375+
const isPercentagePricing: boolean =
376+
this.priceType === PriceType.PERCENTAGE && !skipFee;
375377

376378
operations.push(
377379
this.acpContractClient.createPayableMemo(
@@ -382,9 +384,7 @@ class AcpJob {
382384
isPercentagePricing
383385
? BigInt(Math.round(this.priceValue * 10000)) // convert to basis points
384386
: feeAmount.amount,
385-
isPercentagePricing
386-
? FeeType.PERCENTAGE_FEE
387-
: FeeType.NO_FEE,
387+
isPercentagePricing ? FeeType.PERCENTAGE_FEE : FeeType.NO_FEE,
388388
AcpJobPhases.COMPLETED,
389389
MemoType.PAYABLE_TRANSFER,
390390
expiredAt,
@@ -437,7 +437,8 @@ class AcpJob {
437437
);
438438

439439
const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
440-
const isPercentagePricing: boolean = this.priceType === PriceType.PERCENTAGE && !skipFee;
440+
const isPercentagePricing: boolean =
441+
this.priceType === PriceType.PERCENTAGE && !skipFee;
441442

442443
operations.push(
443444
this.acpContractClient.createPayableMemo(
@@ -448,9 +449,7 @@ class AcpJob {
448449
isPercentagePricing
449450
? BigInt(Math.round(this.priceValue * 10000)) // convert to basis points
450451
: feeAmount.amount,
451-
isPercentagePricing
452-
? FeeType.PERCENTAGE_FEE
453-
: FeeType.NO_FEE,
452+
isPercentagePricing ? FeeType.PERCENTAGE_FEE : FeeType.NO_FEE,
454453
AcpJobPhases.COMPLETED,
455454
MemoType.PAYABLE_NOTIFICATION,
456455
expiredAt,

0 commit comments

Comments
 (0)