UNPKG

@ledgerhq/live-common

Version:
69 lines 2.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.evmSendDescriptor = void 0; const bignumber_js_1 = require("bignumber.js"); const fees_1 = require("./fees"); const EVM_STRATEGIES = ["slow", "medium", "fast"]; function getMaxFeeFromGasOption(maxFeePerGas, gasPrice) { if ((0, fees_1.isBigNumber)(maxFeePerGas)) { return maxFeePerGas; } if ((0, fees_1.isBigNumber)(gasPrice)) { return gasPrice; } return new bignumber_js_1.BigNumber(0); } exports.evmSendDescriptor = { inputs: { recipientSupportsDomain: true, }, fees: { hasPresets: true, hasCustom: true, presets: { getOptions: transaction => { if (!(0, fees_1.isRecord)(transaction)) { return []; } const gasLimit = transaction.gasLimit; const gasOptions = transaction.gasOptions; if (!(0, fees_1.isBigNumber)(gasLimit) || !(0, fees_1.isRecord)(gasOptions)) { return []; } const options = []; for (const strategy of EVM_STRATEGIES) { const gasOption = gasOptions[strategy]; if (!(0, fees_1.isRecord)(gasOption)) { continue; } const maxFeePerGas = gasOption.maxFeePerGas; const gasPrice = gasOption.gasPrice; const maxFee = getMaxFeeFromGasOption(maxFeePerGas, gasPrice); const estimatedFees = maxFee.times(gasLimit); const getEstimatedMs = (strategyType) => { if (strategyType === "slow") return 2 * 60 * 1000; if (strategyType === "medium") return 30 * 1000; return 15 * 1000; }; options.push({ id: strategy, amount: estimatedFees, estimatedMs: getEstimatedMs(strategy), }); } return options; }, }, custom: fees_1.evmCustomFeeConfig, }, amount: { getPlugins: () => ["evmGasOptionsSync"], }, selfTransfer: "free", errors: { userRefusedTransaction: "UserRefusedOnDevice", }, }; //# sourceMappingURL=descriptor.js.map