@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
56 lines (51 loc) • 1.21 kB
text/typescript
import { BigNumber } from "bignumber.js";
import { AccountLike } from "@ledgerhq/types-live";
export const getCustomFeesPerFamily = transaction => {
const { family, maxFeePerGas, maxPriorityFeePerGas, feePerByte, fees, utxoStrategy, gasPrice } =
transaction;
switch (family) {
case "evm": {
return {
maxFeePerGas,
maxPriorityFeePerGas,
gasPrice,
};
}
case "bitcoin": {
return {
feePerByte,
utxoStrategy,
};
}
default:
return {
fees,
};
}
};
export const convertToNonAtomicUnit = ({
amount,
account,
}: {
amount?: BigNumber;
account: AccountLike;
}) => {
const fromMagnitude =
account.type === "TokenAccount"
? account.token.units[0].magnitude || 0
: account.currency?.units[0].magnitude || 0;
return amount?.shiftedBy(-fromMagnitude);
};
export const convertToAtomicUnit = ({
amount,
account,
}: {
amount?: BigNumber;
account: AccountLike;
}) => {
const fromMagnitude =
account.type === "TokenAccount"
? account.token.units[0].magnitude || 0
: account.currency?.units[0].magnitude || 0;
return amount?.shiftedBy(fromMagnitude);
};