"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "GetTestUSDC", {
    enumerable: true,
    get: function() {
        return GetTestUSDC;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _lucidereact = require("lucide-react");
const _hooks = require("@orderly.network/hooks");
const _react = require("react");
const _modal = require("../../modal");
const _toast = require("../../toast");
const localStorageItem = "Orderly_GetTestUSDC";
const GetTestUSDC = ()=>{
    const { account, state } = (0, _hooks.useAccount)();
    const { configStore } = (0, _react.useContext)(_hooks.OrderlyContext);
    const [show, setShow] = (0, _react.useState)(false);
    const config = (0, _hooks.useConfig)();
    (0, _react.useEffect)(()=>{
        const value = localStorage.getItem(`${localStorageItem}_${state.accountId}`);
        if (!value) {
            setShow(()=>true);
        }
    }, []);
    const [getTestUSDC, { isMutating }] = (0, _hooks.useMutation)(`${config.get("operatorUrl")}/v1/faucet/usdc`);
    const onCloseClick = (0, _react.useCallback)(()=>{
        setShow(false);
        localStorage.setItem(`${localStorageItem}_${state.accountId}`, "1");
    }, []);
    const onGetClick = (0, _react.useCallback)((event)=>{
        event.preventDefault();
        const toastId = _toast.toast.loading("Getting test USDC...");
        if (!account || !account.wallet) {
            return;
        }
        getTestUSDC({
            chain_id: account.wallet.chainId.toString(),
            user_address: state.address,
            broker_id: configStore.get("brokerId")
        }).then((res)=>{
            if (res.success) {
                _toast.toast.dismiss(toastId);
                return _modal.modal.confirm({
                    title: "Get test USDC",
                    content: "1,000 USDC will be added to your balance. Please note this may take up to 3 minutes. Please check back later.",
                    onOk: ()=>{
                        return Promise.resolve();
                    }
                });
            } else {
                return Promise.reject(res);
            }
        }).catch((err)=>{
            _toast.toast.dismiss(toastId);
            err.message && _toast.toast.error(err.message);
        });
    }, [
        state
    ]);
    if (!show) {
        return null;
    }
    return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
        id: "orderly-get-usdc",
        className: "orderly-flex orderly-justify-between orderly-items-center orderly-fixed orderly-left-0 orderly-right-0 orderly-bottom-[64px] orderly-h-[40px] orderly-bg-base-700 orderly-z-20 orderly-px-2 orderly-animate-in orderly-fade-in",
        children: [
            /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                className: "orderly-text-3xs orderly-text-base-contrast/50 orderly-cursor-pointer",
                children: [
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                        className: "orderly-text-primary-light",
                        onClick: onGetClick,
                        children: "Get test USDC"
                    }),
                    " ",
                    "and start trading!"
                ]
            }),
            /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                className: "orderly-p-2",
                children: /*#__PURE__*/ (0, _jsxruntime.jsx)("button", {
                    className: "orderly-w-[16px] orderly-h-[16px] orderly-rounded-full orderly-bg-primary-light orderly-flex orderly-justify-center orderly-items-center",
                    onClick: onCloseClick,
                    children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_lucidereact.X, {
                        size: 14,
                        className: "orderly-text-base-100"
                    })
                })
            })
        ]
    });
};

//# sourceMappingURL=getTestUSDC.js.map