import { BigNumber } from "bignumber.js";
import { NotEnoughBalance, RecipientRequired, InvalidAddress, FeeTooHigh } from "@ledgerhq/errors";
import { getSerializedAddressParameters, updateTransaction, } from "@ledgerhq/coin-framework/bridge/jsHelpers";
import { scanAccounts, signOperation, signRawOperation, broadcast, sync, isInvalidRecipient, } from "../../../bridge/mockHelpers";
import { getMainAccount } from "../../../account";
import { makeAccountBridgeReceive } from "../../../bridge/mockHelpers";
import { validateAddress } from "../../../bridge/validateAddress";
const receive = makeAccountBridgeReceive();
const createTransaction = () => ({
    family: "icon",
    mode: "send",
    amount: new BigNumber(0),
    recipient: "",
    useAllAmount: false,
    fees: null,
});
const prepareTransaction = async (a, t) => t;
const estimateMaxSpendable = ({ account, parentAccount, transaction }) => {
    const mainAccount = getMainAccount(account, parentAccount);
    const estimatedFees = transaction?.fees || new BigNumber(5000);
    return Promise.resolve(BigNumber.max(0, mainAccount.spendableBalance.minus(estimatedFees)));
};
const getTransactionStatus = (account, t) => {
    const errors = {};
    const warnings = {};
    const useAllAmount = !!t.useAllAmount;
    const estimatedFees = new BigNumber(5000);
    const totalSpent = useAllAmount ? account.balance : new BigNumber(t.amount).plus(estimatedFees);
    const amount = useAllAmount ? account.balance.minus(estimatedFees) : new BigNumber(t.amount);
    if (amount.gt(0) && estimatedFees.times(10).gt(amount)) {
        warnings.amount = new FeeTooHigh();
    }
    if (totalSpent.gt(account.balance)) {
        errors.amount = new NotEnoughBalance();
    }
    if (!t.recipient) {
        errors.recipient = new RecipientRequired();
    }
    else if (isInvalidRecipient(t.recipient)) {
        errors.recipient = new InvalidAddress();
    }
    return Promise.resolve({
        errors,
        warnings,
        estimatedFees,
        amount,
        totalSpent,
    });
};
const accountBridge = {
    estimateMaxSpendable,
    createTransaction,
    updateTransaction,
    getTransactionStatus,
    prepareTransaction,
    sync,
    receive,
    signOperation,
    signRawOperation,
    broadcast,
    getSerializedAddressParameters,
    validateAddress,
};
const currencyBridge = {
    scanAccounts,
    preload: (async () => { }),
    hydrate: () => { },
};
export default { currencyBridge, accountBridge };
//# sourceMappingURL=mock.js.map