UNPKG

@ordao/privy-react-orclient

Version:

"Helpers for using orclient with privy and react"

45 lines (44 loc) 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OrclientNotFull = exports.OrclientUndefined = void 0; exports.useOrclient = useOrclient; exports.useRpcError = useRpcError; exports.useAssertOrclient = useAssertOrclient; exports.useAssertFullOrclient = useAssertFullOrclient; const react_1 = require("react"); const OrclientProvider_1 = require("./OrclientProvider"); const orclient_1 = require("@ordao/orclient"); class OrclientUndefined extends Error { constructor(message) { super(message ?? "ORClient is undefined"); } } exports.OrclientUndefined = OrclientUndefined; class OrclientNotFull extends Error { constructor(message) { super(message ?? "ORClient is not full"); } } exports.OrclientNotFull = OrclientNotFull; function useOrclient() { const { orclient } = (0, react_1.useContext)(OrclientProvider_1.OrclientContext); return orclient; } function useRpcError() { const { rpcError } = (0, react_1.useContext)(OrclientProvider_1.OrclientContext); return rpcError; } function useAssertOrclient() { const orclient = useOrclient(); if (orclient === undefined) { throw new OrclientUndefined("Orclient is undefined in useOrclientAssert"); } return orclient; } function useAssertFullOrclient() { const orclient = useOrclient(); if (!(0, orclient_1.isORClient)(orclient)) { throw new OrclientNotFull("Orclient is not full in useFullOrclientAssert"); } return orclient; }