"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Withdraw", {
    enumerable: true,
    get: function() {
        return Withdraw;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _withdrawForm = require("./withdrawForm");
const _hooks = require("@orderly.network/hooks");
const _page = require("../../page");
const _utils = require("@orderly.network/utils");
const Withdraw = (props)=>{
    const { connectedChain, wallet, setChain } = (0, _hooks.useWalletConnector)();
    const networkId = (0, _hooks.useConfig)("networkId");
    const [chains, { findByChainId }] = (0, _hooks.useChains)(networkId, {
        pick: "network_infos"
    });
    // @ts-ignore
    const currentChain = (0, _react.useMemo)(()=>{
        if (!connectedChain) return null;
        // const chainId = parseInt(connectedChain.id);
        const { id } = connectedChain;
        const chainId = (0, _utils.praseChainIdToNumber)(id);
        const chain = findByChainId(chainId);
        return {
            ...connectedChain,
            id: chainId,
            info: chain
        };
    }, [
        connectedChain,
        findByChainId
    ]);
    const { maxAmount, availableBalance, availableWithdraw, unsettledPnL, withdraw } = (0, _hooks.useWithdraw)();
    const context = (0, _react.useContext)(_page.TradingPageContext);
    const symbol = context.symbol;
    const [data] = (0, _hooks.usePositionStream)(symbol);
    const hasPositions = data?.rows?.length > 0;
    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_withdrawForm.WithdrawForm, {
        address: wallet?.accounts?.[0].address,
        chain: currentChain,
        // @ts-ignore
        chains: chains,
        walletName: wallet?.label,
        switchChain: setChain,
        // @ts-ignore
        decimals: chains?.decimals ?? 2,
        // @ts-ignore
        minAmount: chains?.minimum_withdraw_amount ?? 1,
        maxAmount: maxAmount,
        availableBalance: availableBalance,
        unsettledPnL: unsettledPnL,
        hasPositions: hasPositions,
        onWithdraw: withdraw,
        onOk: props.onOk
    });
};

//# sourceMappingURL=withdraw.js.map