@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
51 lines • 1.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fees = void 0;
const bignumber_js_1 = require("bignumber.js");
exports.fees = {
hasPresets: true,
hasCustom: true,
presets: {
legend: { type: "feeRate", unit: "Sompi/byte", valueFrom: "presetAmount" },
strategyLabelInAmount: "legend",
getOptions: transaction => {
const info = transaction.networkInfo;
if (!info?.length)
return [];
const first = info[0];
const allSame = first !== undefined &&
info.every((item) => item.estimatedSeconds === first.estimatedSeconds);
return info.map((item) => ({
id: item.label,
amount: item.amount,
estimatedMs: item.estimatedSeconds * 1000,
disabled: (item.label === "slow" || item.label === "medium") && allSame,
}));
},
},
custom: {
inputs: [
{
key: "feePerByte",
type: "number",
unitLabel: "Sompi/byte",
},
],
getInitialValues: transaction => {
const tx = transaction;
if (bignumber_js_1.BigNumber.isBigNumber(tx.customFeeRate) && tx.customFeeRate.gt(0)) {
return { feePerByte: tx.customFeeRate.toFixed() };
}
const medium = tx.networkInfo?.find(item => item.label === "medium")?.amount;
return { feePerByte: bignumber_js_1.BigNumber.isBigNumber(medium) ? medium.toFixed() : "" };
},
buildTransactionPatch: values => {
const feePerByte = new bignumber_js_1.BigNumber(values.feePerByte);
return {
feesStrategy: "custom",
customFeeRate: feePerByte.isNaN() || feePerByte.isNegative() ? new bignumber_js_1.BigNumber(0) : feePerByte,
};
},
},
};
//# sourceMappingURL=fees.js.map