UNPKG

@roochnetwork/rooch-sdk-kit

Version:
75 lines (67 loc) 2.18 kB
// src/hooks/client/useTransferObject.ts import { useMutation } from "@tanstack/react-query"; // src/hooks/client/useRoochContext.ts import { useContext } from "react"; // src/provider/clientProvider.tsx import { createContext, useMemo, useState } from "react"; import { getRoochNodeUrl, RoochClient } from "@roochnetwork/rooch-sdk"; // src/constants/roochMutationKeys.ts function formMutationKeyFn(baseEntity) { return function mutationKeyFn(additionalKeys = []) { return [{ ...roochMutationKeys.all, baseEntity }, ...additionalKeys]; }; } var roochMutationKeys = { all: { baseScope: "rooch" }, addNetwork: formMutationKeyFn("add-network"), switchNetwork: formMutationKeyFn("switch-network"), removeNetwork: formMutationKeyFn("remove-network"), removeSession: formMutationKeyFn("remove-session"), transferObject: formMutationKeyFn("transfer-object"), transferCoin: formMutationKeyFn("transfer-coin"), signAndExecuteTransaction: formMutationKeyFn("sign-and-execute-transaction") }; // src/provider/clientProvider.tsx import { jsx } from "react/jsx-runtime"; var ClientContext = createContext(null); var DEFAULT_NETWORKS = { localnet: { url: getRoochNodeUrl("localnet") } }; // src/hooks/client/useRoochContext.ts function useRoochContext() { const context = 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/useTransferObject.ts function useTransferObject({ mutationKey, ...mutationOptions } = {}) { const client = useRoochClient(); return useMutation({ mutationKey: roochMutationKeys.transferObject(mutationKey), mutationFn: async (args) => { const result = await client.transferObject(args); if (result.execution_info.status.type !== "executed") { Error("transfer failed" + result.execution_info.status.type); } }, ...mutationOptions }); } export { useTransferObject }; //# sourceMappingURL=useTransferObject.js.map