71 lines
2.8 KiB
JavaScript
71 lines
2.8 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.EthereumFeeLevels = void 0;
|
|
const bigNumber_1 = require("@trezor/utils/lib/bigNumber");
|
|
const MiscFees_1 = require("../common/MiscFees");
|
|
class EthereumFeeLevels extends MiscFees_1.MiscFeeLevels {
|
|
coinInfo;
|
|
levels;
|
|
blocks = [];
|
|
constructor(coinInfo) {
|
|
super(coinInfo);
|
|
this.coinInfo = coinInfo;
|
|
this.levels = coinInfo.defaultFees;
|
|
}
|
|
async load(blockchain) {
|
|
try {
|
|
const [response] = await blockchain.estimateFee({ blocks: [1] });
|
|
if (response.eip1559) {
|
|
const eip1559ResponseLevelKeys = [
|
|
'low',
|
|
'medium',
|
|
'high',
|
|
];
|
|
const { eip1559 } = response;
|
|
const eip1559Levels = eip1559ResponseLevelKeys.map(levelKey => {
|
|
const level = eip1559[levelKey];
|
|
const calculatedMaxFeePerGas = bigNumber_1.BigNumber.minimum(new bigNumber_1.BigNumber(level?.maxFeePerGas || '0'), new bigNumber_1.BigNumber(eip1559.baseFeePerGas || '0').plus(level?.maxPriorityFeePerGas || '0')).toFixed();
|
|
const label = levelKey === 'medium'
|
|
? 'normal'
|
|
: levelKey;
|
|
return {
|
|
label,
|
|
maxFeePerGas: level?.maxFeePerGas || '0',
|
|
effectiveGasPrice: calculatedMaxFeePerGas,
|
|
maxPriorityFeePerGas: level?.maxPriorityFeePerGas || '0',
|
|
baseFeePerGas: eip1559.baseFeePerGas,
|
|
minWaitTimeEstimate: level?.minWaitTimeEstimate
|
|
? level.minWaitTimeEstimate / 1000
|
|
: undefined,
|
|
maxWaitTimeEstimate: level?.maxWaitTimeEstimate
|
|
? level.maxWaitTimeEstimate / 1000
|
|
: undefined,
|
|
feePerUnit: '0',
|
|
feeLimit: response.feeLimit,
|
|
blocks: -1,
|
|
};
|
|
});
|
|
this.levels = [...eip1559Levels];
|
|
}
|
|
else {
|
|
super.load(blockchain);
|
|
}
|
|
}
|
|
catch {
|
|
}
|
|
return this.levels;
|
|
}
|
|
updateEthereumCustomFee(feePerUnit, effectiveGasPrice, maxPriorityFeePerGas) {
|
|
this.levels = this.levels.filter(l => l.label !== 'custom');
|
|
const blocks = (0, MiscFees_1.findBlocksForFee)(feePerUnit, this.blocks);
|
|
this.levels.push({
|
|
label: 'custom',
|
|
feePerUnit,
|
|
blocks,
|
|
maxPriorityFeePerGas,
|
|
effectiveGasPrice,
|
|
});
|
|
}
|
|
}
|
|
exports.EthereumFeeLevels = EthereumFeeLevels;
|
|
//# sourceMappingURL=EthereumFees.js.map
|