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

//# sourceMappingURL=marketProvider.js.map