From 45dbd7725cfff9fc198f3c98dc5cbbbccf8f8325 Mon Sep 17 00:00:00 2001 From: Abraham Onoja <35797372+L-tech@users.noreply.github.com> Date: Thu, 6 Oct 2022 15:51:43 +0100 Subject: [PATCH] Add option to provide gas fee for make charge transaction (#18) --- build/subscription.d.ts | 2 +- build/subscription.js | 13 ++++++++++--- package.json | 2 +- src/subscription.ts | 28 +++++++++++++++++++++------- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/build/subscription.d.ts b/build/subscription.d.ts index 7eb94e0..c98427f 100644 --- a/build/subscription.d.ts +++ b/build/subscription.d.ts @@ -31,7 +31,7 @@ export default class extends Deployed { getStakedTokenAddress(): Promise; getDiscountSlabs(): Promise; getDataContract(): Promise; - makeCharge(u: string, d: Array): Promise; + makeCharge(u: string, d: Array, gp?: string): Promise; addTokens(d: Array): Promise; removeTokens(d: Array): Promise; changeUsdPrecision(n: number): Promise; diff --git a/build/subscription.js b/build/subscription.js index 8c29d70..783b7e3 100644 --- a/build/subscription.js +++ b/build/subscription.js @@ -264,8 +264,8 @@ class default_1 extends deployed_1.default { return this.vendor.parseDiscountSlabs(slabs); }); } - makeCharge(u, d) { - var _a, _b; + makeCharge(u, d, gp) { + var _a, _b, _c, _d; return __awaiter(this, void 0, void 0, function* () { const paramArray = []; const paramValue = []; @@ -273,7 +273,14 @@ class default_1 extends deployed_1.default { paramArray.push(d[i].param); paramValue.push(this.vendor.convertToBN(d[i].value.toString())); } - return yield ((_a = this.subscriptionPaymentContract) === null || _a === void 0 ? void 0 : _a.functions.chargeUser(u, paramArray, paramValue, ((_b = this.erc20Contract) === null || _b === void 0 ? void 0 : _b.address) || '')); + if (gp) { + return yield ((_a = this.subscriptionPaymentContract) === null || _a === void 0 ? void 0 : _a.functions.chargeUser(u, paramArray, paramValue, ((_b = this.erc20Contract) === null || _b === void 0 ? void 0 : _b.address) || '', { + gasPrice: this.vendor.convertToBN(gp), + })); + } + else { + return yield ((_c = this.subscriptionPaymentContract) === null || _c === void 0 ? void 0 : _c.functions.chargeUser(u, paramArray, paramValue, ((_d = this.erc20Contract) === null || _d === void 0 ? void 0 : _d.address) || '')); + } }); } addTokens(d) { diff --git a/package.json b/package.json index 3b430ce..5bd6baf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@spheron/desub-js", - "version": "2.0.0", + "version": "2.0.1", "description": "Typescript library for working with the decentralised subscription contracts in Spheron", "main": "build/index.js", "types": "build/index.d.ts", diff --git a/src/subscription.ts b/src/subscription.ts index 188907a..bf011d2 100644 --- a/src/subscription.ts +++ b/src/subscription.ts @@ -384,20 +384,34 @@ export default class extends Deployed { * this method is used when we want to charge user for the subscrption he will be buying. * @param u - address of user * @param d - array of parameters and their values + * @param mf - max gas fee + * @param m - max priority fee */ - async makeCharge(u: string, d: Array): Promise { + async makeCharge(u: string, d: Array, gp?: string): Promise { const paramArray: Array = [] const paramValue: Array = [] for (let i = 0; i < d.length; i++) { paramArray.push(d[i].param) paramValue.push(this.vendor.convertToBN(d[i].value.toString())) } - return await this.subscriptionPaymentContract?.functions.chargeUser( - u, - paramArray, - paramValue, - this.erc20Contract?.address || '', - ) + if (gp) { + return await this.subscriptionPaymentContract?.functions.chargeUser( + u, + paramArray, + paramValue, + this.erc20Contract?.address || '', + { + gasPrice: this.vendor.convertToBN(gp), + }, + ) + } else { + return await this.subscriptionPaymentContract?.functions.chargeUser( + u, + paramArray, + paramValue, + this.erc20Contract?.address || '', + ) + } } /** * @remarks