@ordao/privy-react-orclient
Version:
"Helpers for using orclient with privy and react"
32 lines (31 loc) • 952 B
JavaScript
import { useContext } from "react";
import { OrclientContext } from "./OrclientProvider";
import { isORClient } from "@ordao/orclient";
export class OrclientUndefined extends Error {
constructor(message) {
super(message ?? "ORClient is undefined");
}
}
export class OrclientNotFull extends Error {
constructor(message) {
super(message ?? "ORClient is not full");
}
}
export function useOrclient() {
const { orclient } = useContext(OrclientContext);
return orclient;
}
export function useAssertOrclient() {
const orclient = useOrclient();
if (orclient === undefined) {
throw new OrclientUndefined("Orclient is undefined in useOrclientAssert");
}
return orclient;
}
export function useAssertFullOrclient() {
const orclient = useOrclient();
if (!isORClient(orclient)) {
throw new OrclientNotFull("Orclient is not full in useFullOrclientAssert");
}
return orclient;
}