import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useCallback } from "react";
import { useAccount, useMutation, useConfig } from "@orderly.network/hooks";
import { modal } from "../modal";
import { toast } from "../toast";
export const MarketContext = /*#__PURE__*/ createContext({});
export const MarketProvider = (props)=>{
    const { account, state } = useAccount();
    const config = useConfig();
    const [doGetTestUSDC, { isMutating }] = useMutation(`${config.get("operatorUrl")}/v1/faucet/usdc`);
    const brokerId = config.get("brokerId");
    const getTestUSDC = useCallback(()=>{
        return doGetTestUSDC({
            chain_id: account.wallet?.chainId.toString(),
            user_address: state.address,
            broker_id: brokerId
        }).then((res)=>{
            if (res.success) {
                return 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();
                    }
                });
            }
            res.message && toast.error(res.message);
            return Promise.reject(res);
        }).catch((error)=>{
            toast.error(error.message);
        // res.message && toast.error(res.message);
        });
    }, [
        state
    ]);
    return /*#__PURE__*/ _jsx(MarketContext.Provider, {
        value: {
            getTestUSDC
        }
    });
};

//# sourceMappingURL=marketProvider.js.map