UNPKG

@ledgerhq/coin-casper

Version:
27 lines (19 loc) 803 B
import BigNumber from "bignumber.js"; import { AccountBridge } from "@ledgerhq/types-live"; import { getMainAccount } from "@ledgerhq/coin-framework/account/index"; import { getEstimatedFees } from "./bridgeHelpers/fee"; import { Transaction } from "../types"; export const estimateMaxSpendable: AccountBridge<Transaction>["estimateMaxSpendable"] = async ({ account, parentAccount, transaction, }) => { const mainAccount = getMainAccount(account, parentAccount); let balance = mainAccount.spendableBalance; if (balance.eq(0)) return balance; const estimatedFees = transaction?.fees ?? getEstimatedFees(); if (balance.lte(estimatedFees)) return new BigNumber(0); balance = balance.minus(estimatedFees); // log("debug", "[estimateMaxSpendable] finish fn"); return balance; };