Files
js/@3rdweb-sdk/react/components/roles/admin-only.tsx
T
Jonas Daniels 5b32c3d05e refactor(solana): remove support for solana (#1733)
* refactor(solana): remove support for solana

* chore: update @thirdweb-dev/react and @thirdweb-dev/sdk versions

* remove unused code & re-update-next-versions

* refactor: Remove unused Solana currency metadata

* fix build
2023-10-09 19:46:47 +00:00

45 lines
961 B
TypeScript

import {
useIsAdmin,
useIsAdminOrSelf,
} from "@3rdweb-sdk/react/hooks/useContractRoles";
import { ValidContractInstance } from "@thirdweb-dev/sdk";
import { ComponentWithChildren } from "types/component-with-children";
interface AdminOnlyProps {
contract?: ValidContractInstance;
fallback?: JSX.Element;
}
export const AdminOnly: ComponentWithChildren<AdminOnlyProps> = ({
children,
contract,
fallback,
}) => {
const isAdmin = useIsAdmin(contract);
if (!isAdmin) {
return fallback ?? null;
}
return <>{children}</>;
};
interface AdminOrSelfOnlyProps extends AdminOnlyProps {
/**
* The address of the account to check against
*/
self: string;
}
export const AdminOrSelfOnly: ComponentWithChildren<AdminOrSelfOnlyProps> = ({
children,
self,
fallback,
contract,
}) => {
const isAdminOrSelf = useIsAdminOrSelf(contract, self);
if (!isAdminOrSelf) {
return fallback ?? null;
}
return <>{children}</>;
};