@trezor/connect
Version:
High-level javascript interface for Trezor hardware wallet.
85 lines • 3.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("../constants");
const AbstractMethod_1 = require("../core/AbstractMethod");
const paramsValidator_1 = require("./common/paramsValidator");
const BlockchainLink_1 = require("../backend/BlockchainLink");
const coinInfo_1 = require("../data/coinInfo");
const BitcoinFees_1 = require("./bitcoin/BitcoinFees");
const MiscFees_1 = require("./common/MiscFees");
const EthereumFees_1 = require("./ethereum/EthereumFees");
class BlockchainEstimateFee extends AbstractMethod_1.AbstractMethod {
init() {
this.useDevice = false;
this.useUi = false;
const { payload } = this;
(0, paramsValidator_1.validateParams)(payload, [
{ name: 'coin', type: 'string', required: true },
{ name: 'identity', type: 'string' },
{ name: 'request', type: 'object' },
]);
const { request, identity } = payload;
if (request) {
(0, paramsValidator_1.validateParams)(request, [
{ name: 'blocks', type: 'array' },
{ name: 'specific', type: 'object' },
{ name: 'feeLevels', type: 'string' },
]);
if (request.specific) {
(0, paramsValidator_1.validateParams)(request.specific, [
{ name: 'conservative', type: 'boolean' },
{ name: 'data', type: 'string' },
{ name: 'from', type: 'string' },
{ name: 'to', type: 'string' },
{ name: 'txsize', type: 'number' },
{ name: 'newAccountProgramName', type: 'string' },
]);
}
}
const coinInfo = (0, coinInfo_1.getCoinInfo)(payload.coin);
if (!coinInfo) {
throw constants_1.ERRORS.TypedError('Method_UnknownCoin');
}
(0, BlockchainLink_1.isBackendSupported)(coinInfo);
this.params = {
coinInfo,
identity,
request,
};
}
async run() {
const { coinInfo, identity, request } = this.params;
const feeInfo = {
blockTime: coinInfo.blockTime,
minFee: coinInfo.minFee,
maxFee: coinInfo.maxFee,
dustLimit: coinInfo.type === 'bitcoin' ? coinInfo.dustLimit : undefined,
levels: [],
};
const getFees = () => {
switch (coinInfo.type) {
case 'bitcoin':
return new BitcoinFees_1.BitcoinFeeLevels(coinInfo);
case 'ethereum':
return new EthereumFees_1.EthereumFeeLevels(coinInfo);
default:
return new MiscFees_1.MiscFeeLevels(coinInfo);
}
};
if (request && request.feeLevels) {
const fees = getFees();
if (request.feeLevels === 'smart') {
const backend = await (0, BlockchainLink_1.initBlockchain)(coinInfo, this.postMessage, identity);
await fees.load(backend);
}
feeInfo.levels = fees.levels;
}
else {
const backend = await (0, BlockchainLink_1.initBlockchain)(coinInfo, this.postMessage, identity);
feeInfo.levels = await backend.estimateFee(request || {});
}
return feeInfo;
}
}
exports.default = BlockchainEstimateFee;
//# sourceMappingURL=blockchainEstimateFee.js.map