UNPKG

@ledgerhq/coin-celo

Version:
34 lines (25 loc) 1.06 kB
import BigNumber from "bignumber.js"; import { AccountBridge } from "@ledgerhq/types-live"; import { isValidAddress } from "@celo/utils/lib/address"; import getFeesForTransaction from "./getFeesForTransaction"; import { CeloAccount, Transaction } from "../types"; const sameFees = (a: BigNumber | null | undefined, b: BigNumber) => (!a || !b ? a === b : a.eq(b)); export const prepareTransaction: AccountBridge< Transaction, CeloAccount >["prepareTransaction"] = async (account, transaction) => { if (transaction.recipient && !isValidAddress(transaction.recipient)) return transaction; if (["send", "vote"].includes(transaction.mode) && !transaction.recipient) return transaction; if ( transaction.mode === "vote" && !transaction.useAllAmount && new BigNumber(transaction.amount).lte(0) ) return transaction; const fees = await getFeesForTransaction({ account, transaction }); if (!sameFees(transaction.fees, fees)) { return { ...transaction, fees }; } return transaction; }; export default prepareTransaction;