import { jsx as _jsx } from "react/jsx-runtime";
import { useMemo, useState } from "react";
import { DepositForm } from "./depositForm";
import { useDeposit, useChains, useWalletConnector, useConfig } from "@orderly.network/hooks";
import { DepositProvider } from "./DepositProvider";
import { praseChainIdToNumber } from "@orderly.network/utils";
export var DepositStatus;
(function(DepositStatus) {
    DepositStatus["Checking"] = "Checking";
    DepositStatus["InsufficientBalance"] = "InsufficientBalance";
    DepositStatus["Normal"] = "Normal";
})(DepositStatus || (DepositStatus = {}));
export const Deposit = (props)=>{
    const networkId = useConfig("networkId");
    // @ts-ignore
    const [chains, { findByChainId }] = useChains(networkId, {
        pick: "network_infos",
        filter: (chain)=>chain.network_infos?.bridge_enable || chain.network_infos?.bridgeless
    });
    const { connectedChain, wallet, setChain, settingChain } = useWalletConnector();
    const [token, setToken] = useState();
    // @ts-ignore
    const currentChain = useMemo(()=>{
        if (!connectedChain) return null;
        const chainId = praseChainIdToNumber(connectedChain.id);
        const chain = findByChainId(chainId);
        return {
            ...connectedChain,
            id: chainId,
            info: chain
        };
    }, [
        connectedChain,
        findByChainId
    ]);
    const { dst, balance, allowance, depositFeeRevalidating, depositFee, quantity, setQuantity, approve, deposit, isNativeToken, balanceRevalidating, fetchBalance } = useDeposit({
        address: token?.address,
        decimals: token?.decimals,
        srcChainId: currentChain?.id,
        srcToken: token?.symbol
    });
    return /*#__PURE__*/ _jsx(DepositProvider, {
        children: /*#__PURE__*/ _jsx(DepositForm, {
            dst: dst,
            allowance: allowance,
            address: wallet?.accounts?.[0].address,
            chain: currentChain,
            // @ts-ignore
            chains: chains,
            walletName: wallet?.label,
            switchChain: setChain,
            displayDecimals: 2,
            switchToken: setToken,
            token: token,
            isNativeToken: isNativeToken,
            minAmount: 0,
            maxAmount: balance,
            approve: approve,
            deposit: deposit,
            fetchBalance: fetchBalance,
            onOk: props.onOk,
            balanceRevalidating: balanceRevalidating,
            settingChain: settingChain,
            quantity: quantity,
            setQuantity: setQuantity,
            depositFee: depositFee,
            depositFeeRevalidating: depositFeeRevalidating
        })
    });
};
export default Deposit;

//# sourceMappingURL=deposit.js.map