@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
48 lines • 1.82 kB
JavaScript
import { BigNumber } from "bignumber.js";
export const 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.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.isBigNumber(medium) ? medium.toFixed() : "" };
},
buildTransactionPatch: values => {
const feePerByte = new BigNumber(values.feePerByte);
return {
feesStrategy: "custom",
customFeeRate: feePerByte.isNaN() || feePerByte.isNegative() ? new BigNumber(0) : feePerByte,
};
},
},
};
//# sourceMappingURL=fees.js.map