46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.MiscFeeLevels = exports.findBlocksForFee = void 0;
|
|
const bigNumber_1 = require("@trezor/utils/lib/bigNumber");
|
|
const findBlocksForFee = (feePerUnit, blocks) => {
|
|
const bn = new bigNumber_1.BigNumber(feePerUnit);
|
|
const lower = blocks.find(b => typeof b === 'string' && bn.gte(b));
|
|
if (!lower)
|
|
return -1;
|
|
return blocks.indexOf(lower);
|
|
};
|
|
exports.findBlocksForFee = findBlocksForFee;
|
|
class MiscFeeLevels {
|
|
coinInfo;
|
|
levels;
|
|
longTermFeeRate;
|
|
blocks = [];
|
|
constructor(coinInfo) {
|
|
this.coinInfo = coinInfo;
|
|
this.levels = coinInfo.defaultFees;
|
|
}
|
|
async load(blockchain) {
|
|
try {
|
|
const [response] = await blockchain.estimateFee({ blocks: [1] });
|
|
this.levels[0] = {
|
|
...this.levels[0],
|
|
...response,
|
|
feePerUnit: Math.min(this.coinInfo.maxFee, Math.max(this.coinInfo.minFee, parseInt(response.feePerUnit ?? '0', 10))).toString(),
|
|
};
|
|
}
|
|
catch {
|
|
}
|
|
return this.levels;
|
|
}
|
|
updateCustomFee(feePerUnit) {
|
|
this.levels = this.levels.filter(l => l.label !== 'custom');
|
|
const blocks = (0, exports.findBlocksForFee)(feePerUnit, this.blocks);
|
|
this.levels.push({
|
|
label: 'custom',
|
|
feePerUnit,
|
|
blocks,
|
|
});
|
|
}
|
|
}
|
|
exports.MiscFeeLevels = MiscFeeLevels;
|
|
//# sourceMappingURL=MiscFees.js.map
|