UNPKG

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

Version:

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

49 lines (48 loc) 2.42 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.MetamaskContract = void 0; const units_1 = require("@ethersproject/units"); const WrappedContract_1 = require("../types/WrappedContract"); class MetamaskContract extends WrappedContract_1.WrappedContract { constructor(originContract) { super(originContract); } call({ methodName, params = [], option = {} }) { return __awaiter(this, void 0, void 0, function* () { if (!this.originContract.functions[methodName]) { throw Error('Not Exist Method'); } return yield this.originContract[methodName](...params, option); }); } send({ methodName, params = [], option = {}, callback }) { var _a; return __awaiter(this, void 0, void 0, function* () { if (!this.originContract[methodName]) { throw Error('Not Exist Method'); } if (!option.gasPrice) { option.gasPrice = yield this.originContract.provider.getGasPrice(); } const result = yield this.originContract[methodName](...params, option); (_a = callback === null || callback === void 0 ? void 0 : callback.onTransactionHash) === null || _a === void 0 ? void 0 : _a.call(callback, result.hash); return yield result.wait(); }); } estimateGas({ methodName, params = [], option = {} }) { return __awaiter(this, void 0, void 0, function* () { const estimation = yield this.originContract.estimateGas[methodName](...params, option); return (0, units_1.formatEther)(estimation); }); } } exports.MetamaskContract = MetamaskContract;