* initial /publish * custom contract init (#27) * clean up customContract interface for the moment * upgrade sdk & make multi-uri publish work * upgraded dependencies and customContract workflow * more custom contract stuff * publish ui update * basic publish & deploy flow works * cleanup eslint * update sdk * add contract address to toast and log it out * integrate newer sdk version * upgrade deps * full deploy loop functional with updated sdk * upgrade sdk * upgrade deps * upgrade sdk to fix big contracts * full flow! * update deps * update to latest sdk, support custom contracts in contracts list * one more sdk update * cache keys // analytics mapping * make mr. typescript happy * try catch the resolve type (need to fix it in SDK) * fix type check * upgrade sdk & handle `ipfs=` from cli * fix yarn lock * publishBatch * add very basic code tab * fix build * init cleaning up code tab * fix zindex issue * update code segments * prep some more stuff * remove duplication * this wont build and that is ok * fix build * upgrade react package * add super basic mint button * update sdk * clean up some custom contract interfaces a bit * updated sdks all around * change minting to useNFTMint * append contract.functions to signatures so you can copy paste * add byoc page tracking * new publish page * slightly fix hook * custom deploy form update * completely overhauled deploy flow now * some improvements, empty states etc * only show coming soon on non-mumbai * tw-components * fix contract items table * upgrade deps * fix secondary cta * fix string * fixed things more * fix up code-block * small code tab improvements * Add mint drawer if ERC721 (#95) * Update thumbnail/title/desc * Add custom nft mint * Fix FormHelperText * Delete unused imports * Remove imports * fix build issues etc * Add token drop (#93) * Update thumbnail/title/desc * Merge * wip * Token drop page working * Add claim phases tab, add TokenDrop to conditionals * update font size * NFTs/token conditional * Add QuantityInputWithUnlimited * Update SDK * Fix unlimited * Remove fontSize Co-authored-by: Jonas Daniels <[email protected]> * set tokendrop back to coming soon * remove "@dev" tag for sdk installation * fix mappings file * fix indentation on custom code tab * ship central 🚢 * fix build Co-authored-by: Joaquim Verges <[email protected]> Co-authored-by: Jake Loo <[email protected]> Co-authored-by: Nacho Iacovino <[email protected]>
134 lines
3.6 KiB
TypeScript
134 lines
3.6 KiB
TypeScript
import { contractRoleKeys } from "../cache-keys";
|
|
import {
|
|
useMutationWithInvalidate,
|
|
useQueryWithNetwork,
|
|
} from "./query/useQueryWithNetwork";
|
|
import { useWeb3 } from "@3rdweb-sdk/react";
|
|
import { AddressZero } from "@ethersproject/constants";
|
|
import {
|
|
Split,
|
|
ValidContractClass,
|
|
ValidContractInstance,
|
|
Vote,
|
|
} from "@thirdweb-dev/sdk";
|
|
import invariant from "tiny-invariant";
|
|
import { C, U } from "ts-toolbelt";
|
|
|
|
export type ContractWithRoles = U.Exclude<
|
|
ValidContractClass,
|
|
typeof Vote | typeof Split
|
|
>;
|
|
|
|
export type ContractWithRolesInstance = C.Instance<ContractWithRoles>;
|
|
|
|
export function isContractWithRoles(
|
|
contract?: ValidContractInstance,
|
|
): contract is C.Instance<ContractWithRoles> {
|
|
if (contract && "roles" in contract) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
export function useContractRoleMembersList<TContract extends ContractWithRoles>(
|
|
contract?: C.Instance<TContract>,
|
|
) {
|
|
return useQueryWithNetwork(
|
|
contractRoleKeys.list(contract?.getAddress()),
|
|
async () => {
|
|
return (await contract?.roles.getAll()) as
|
|
| Record<TContract["contractRoles"][number], string[]>
|
|
| undefined;
|
|
},
|
|
{
|
|
enabled: !!contract && !!contract.getAddress(),
|
|
},
|
|
);
|
|
}
|
|
|
|
export function useContractRoleMembers<TContract extends ContractWithRoles>(
|
|
role: TContract["contractRoles"][number],
|
|
contract?: C.Instance<TContract>,
|
|
) {
|
|
return useQueryWithNetwork(
|
|
contractRoleKeys.detail(contract?.getAddress(), role),
|
|
async () => await contract?.roles.get(role as any),
|
|
{
|
|
enabled: !!contract && !!contract.getAddress() && !!role,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function useSetAllRoleMembersMutation<
|
|
TContract extends ContractWithRoles,
|
|
>(contract?: C.Instance<TContract>) {
|
|
return useMutationWithInvalidate(
|
|
async (rolesWithAddresses: {
|
|
[role in TContract["contractRoles"][number]]: string[];
|
|
}) => {
|
|
invariant(contract, "contract is required");
|
|
await contract.roles.setAll(rolesWithAddresses);
|
|
},
|
|
{
|
|
onSuccess: (_data, variables, _options, invalidate) => {
|
|
return invalidate([contractRoleKeys.list(contract?.getAddress())]);
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
export function useAddRoleMemberMutation<TContract extends ContractWithRoles>(
|
|
contract?: C.Instance<TContract>,
|
|
) {
|
|
return useMutationWithInvalidate(
|
|
async (variables: {
|
|
role: TContract["contractRoles"][number];
|
|
address: string;
|
|
}) => {
|
|
invariant(contract, "contract is required");
|
|
await contract.roles.grant(variables.role as any, variables.address);
|
|
},
|
|
{
|
|
onSuccess: (_data, variables, _options, invalidate) => {
|
|
return invalidate([
|
|
contractRoleKeys.list(contract?.getAddress()),
|
|
contractRoleKeys.detail(contract?.getAddress(), variables.role),
|
|
]);
|
|
},
|
|
},
|
|
);
|
|
}
|
|
export function useIsAccountRole<TContract extends ContractWithRoles>(
|
|
role: TContract["contractRoles"][number],
|
|
contract?: C.Instance<TContract>,
|
|
account?: string,
|
|
): boolean {
|
|
const contractHasRoles = isContractWithRoles(contract);
|
|
const { data } = useContractRoleMembers(
|
|
role,
|
|
contractHasRoles ? contract : undefined,
|
|
);
|
|
|
|
if (contractHasRoles === false) {
|
|
return false;
|
|
}
|
|
|
|
if (data?.includes(AddressZero)) {
|
|
return true;
|
|
}
|
|
|
|
return !!(account && data?.includes(account));
|
|
}
|
|
|
|
export function useIsAdmin<TContract extends ValidContractClass>(
|
|
contract?: C.Instance<TContract>,
|
|
) {
|
|
const { address } = useWeb3();
|
|
const contractHasRoles = isContractWithRoles(contract);
|
|
return useIsAccountRole(
|
|
"admin",
|
|
contractHasRoles ? contract : undefined,
|
|
address,
|
|
);
|
|
}
|