import { useEffect } from "react";
import { useCurrenciesByMarketcap } from "../../../currencies/hooks";
import { listCryptoCurrencies } from "../../../currencies";
import { getAvailableAccountsById } from "../utils";
// Pick a default source account if none are selected.
export const usePickDefaultAccount = (accounts, fromAccount, setFromAccount) => {
    const list = listCryptoCurrencies();
    const allCurrencies = useCurrenciesByMarketcap(list);
    useEffect(() => {
        if (!fromAccount && allCurrencies.length > 0) {
            const defaultAccount = allCurrencies
                .map(({ id }) => getAvailableAccountsById(id, accounts).filter(account => account.balance.gt(0)))
                .flat(1)
                .find(Boolean);
            if (defaultAccount && defaultAccount?.id !== fromAccount?.["id"])
                setFromAccount(defaultAccount);
        }
    }, [accounts, allCurrencies, fromAccount, setFromAccount]);
};
//# sourceMappingURL=usePickDefaultAccount.js.map