@roochnetwork/rooch-sdk-kit
Version:
Rooch SDK Kit
75 lines (67 loc) • 2.51 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/hooks/client/useRoochClientQuery.ts
var useRoochClientQuery_exports = {};
__export(useRoochClientQuery_exports, {
useRoochClientQuery: () => useRoochClientQuery
});
module.exports = __toCommonJS(useRoochClientQuery_exports);
var import_react_query = require("@tanstack/react-query");
// src/hooks/client/useCurrentNetwork.ts
function useCurrentNetwork() {
return useRoochContext().network;
}
// src/hooks/client/useRoochContext.ts
var import_react2 = require("react");
// src/provider/clientProvider.tsx
var import_react = require("react");
var import_rooch_sdk = require("@roochnetwork/rooch-sdk");
var import_jsx_runtime = require("react/jsx-runtime");
var ClientContext = (0, import_react.createContext)(null);
var DEFAULT_NETWORKS = {
localnet: { url: (0, import_rooch_sdk.getRoochNodeUrl)("localnet") }
};
// src/hooks/client/useRoochContext.ts
function useRoochContext() {
const context = (0, import_react2.useContext)(ClientContext);
if (!context) {
throw new Error(
"Could not find RoochClientContext. Ensure that you have set up the RoochClientProvider."
);
}
return context;
}
// src/hooks/client/useRoochClient.ts
function useRoochClient() {
return useRoochContext().client;
}
// src/hooks/client/useRoochClientQuery.ts
function useRoochClientQuery(...args) {
const [method, params, { queryKey = [], ...options } = {}] = args;
const network = useCurrentNetwork();
const roochClient = useRoochClient();
return (0, import_react_query.useQuery)({
...options,
queryKey: [network, method, params, ...queryKey],
queryFn: async () => {
return await roochClient[method](params);
}
});
}
//# sourceMappingURL=useRoochClientQuery.js.map