UNPKG

@hashlike-official/extend-web3-react-wrapper

Version:

web3-react wrapper - it offers a common interface for different wallet providers

77 lines (76 loc) 3.39 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.KaikasContract = void 0; /* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-explicit-any */ const WrappedContract_1 = require("../types/WrappedContract"); /** * * {@link https://docs.klaytn.foundation/dapp/sdk/caver-js/v1.4.1/api-references/caver.klay.contract} * */ class KaikasContract extends WrappedContract_1.WrappedContract { constructor(originContract) { super(originContract); } call({ methodName, params = [], option = {} }) { return __awaiter(this, void 0, void 0, function* () { if (!this.originContract.methods[methodName]) { throw Error('Not Exist Method'); } const opt = this.parseOption({ option }); if (!opt.gas) { opt.gas = yield this.estimateGas({ methodName, params, option }); } return yield this.originContract.methods[methodName](...params).call(opt); }); } send({ methodName, params = [], option = {}, callback }) { return __awaiter(this, void 0, void 0, function* () { if (!this.originContract.methods[methodName]) { throw Error('Not Exist Method'); } const opt = this.parseOption({ option }); if (!opt.gas) { opt.gas = yield this.estimateGas({ methodName, params, option }); } return yield this.originContract.methods[methodName](...params).send(opt, (err, txHash) => { var _a, _b; if (err) (_a = callback === null || callback === void 0 ? void 0 : callback.onError) === null || _a === void 0 ? void 0 : _a.call(callback, err); if (txHash) (_b = callback === null || callback === void 0 ? void 0 : callback.onTransactionHash) === null || _b === void 0 ? void 0 : _b.call(callback, txHash); }); }); } estimateGas({ methodName, params = [], option = {} }) { return __awaiter(this, void 0, void 0, function* () { return yield this.originContract.methods[methodName](...params).estimateGas(Object.assign({}, this.parseOption({ option }))); }); } parseOption({ option }) { let opt = {}; if (option) { opt = Object.assign({}, option); if (option.gasLimit) { opt['gas'] = option.gasLimit; } } return opt; } } exports.KaikasContract = KaikasContract;