@ledgerhq/coin-algorand
Version:
Ledger Algorand Coin integration
24 lines (20 loc) • 941 B
text/typescript
import { BigNumber } from "bignumber.js";
import algorandAPI from "./api";
import { buildTransactionPayload, encodeToSign } from "./buildTransaction";
import type { AlgorandAccount, Transaction } from "./types";
// This is only true for a single signature. If we ever support different type of signatures
// (e.g multi signatures), we will have to add the correct corresponding number of bytes.
const SINGLE_SIGNATURE_SIZE = 71;
export const getEstimatedFees = async (
account: AlgorandAccount,
transaction: Transaction,
): Promise<BigNumber> => {
const params = await algorandAPI.getTransactionParams();
let suggestedFees = 0;
if (params.fee) {
const payload = await buildTransactionPayload(account, transaction);
const encoded = encodeToSign(payload);
suggestedFees = params.fee * (Buffer.from(encoded, "hex").length + SINGLE_SIGNATURE_SIZE);
}
return new BigNumber(Math.max(suggestedFees, params.minFee));
};