Files
js/@3rdweb-sdk/react/components/roles/minter-only.tsx
T
Jonas Daniels 3b647fccc1 react 18 upgrade (#80)
* react 18 upgrade (WIP)

* fix typography logic

* fix lots of lint issues
2022-05-12 18:03:53 -07:00

29 lines
622 B
TypeScript

import {
isContractWithRoles,
useIsAccountRole,
useWeb3,
} from "@3rdweb-sdk/react";
import { ValidContractInstance } from "@thirdweb-dev/sdk";
import { ComponentWithChildren } from "types/component-with-children";
interface IMinterOnlyProps {
contract?: ValidContractInstance;
}
export const MinterOnly: ComponentWithChildren<IMinterOnlyProps> = ({
children,
contract,
}) => {
const { address } = useWeb3();
const isMinter = useIsAccountRole(
"minter",
isContractWithRoles(contract) ? contract : undefined,
address,
);
if (!isMinter) {
return null;
}
return <>{children}</>;
};