"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: all[name]
    });
}
_export(exports, {
    Deposit: function() {
        return Deposit;
    },
    DepositStatus: function() {
        return DepositStatus;
    },
    default: function() {
        return _default;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _depositForm = require("./depositForm");
const _hooks = require("@orderly.network/hooks");
const _DepositProvider = require("./DepositProvider");
const _utils = require("@orderly.network/utils");
var DepositStatus;
(function(DepositStatus) {
    DepositStatus["Checking"] = "Checking";
    DepositStatus["InsufficientBalance"] = "InsufficientBalance";
    DepositStatus["Normal"] = "Normal";
})(DepositStatus || (DepositStatus = {}));
const Deposit = (props)=>{
    const networkId = (0, _hooks.useConfig)("networkId");
    // @ts-ignore
    const [chains, { findByChainId }] = (0, _hooks.useChains)(networkId, {
        pick: "network_infos",
        filter: (chain)=>chain.network_infos?.bridge_enable || chain.network_infos?.bridgeless
    });
    const { connectedChain, wallet, setChain, settingChain } = (0, _hooks.useWalletConnector)();
    const [token, setToken] = (0, _react.useState)();
    // @ts-ignore
    const currentChain = (0, _react.useMemo)(()=>{
        if (!connectedChain) return null;
        const chainId = (0, _utils.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 } = (0, _hooks.useDeposit)({
        address: token?.address,
        decimals: token?.decimals,
        srcChainId: currentChain?.id,
        srcToken: token?.symbol
    });
    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_DepositProvider.DepositProvider, {
        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_depositForm.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
        })
    });
};
const _default = Deposit;

//# sourceMappingURL=deposit.js.map