Files
js/@3rdweb-sdk/react/hooks/useDeploy.ts
T
Jonas DanielsandJoaquim Verges 1b91237787 [Upgrade SDKs] - new drops (#621)
* updated claim conditions

* fix several things

* update embed

* allow single phase to be added

* fix claimer snapshot button

* fix it for realz

* fix learn more suffs

* it workz!

* update to re-allow claiming etc

* make it nightly & update sdk

* update to latest SDK with all chains enabled

* fix various claim condition things

* fix snapshot defaults

* change explainer

* fix snapshot with overrides

* fix eiman-bug

* fix small stuff

* maybe we should actually pass the damn data?

* update SDK to fix custom price claims

* update embed uri

* update sdks and embed logic, etc

* actually deploy specific versions for prebuilt contracts

* update to latest dev version of sdk

* driveby add new gnosis safe supported chains

* fix latest deploy on initial load

* stable sdks and embed

* remove withSentry (no longer needed)

Co-authored-by: Joaquim Verges <[email protected]>
2022-11-16 22:21:45 +00:00

51 lines
1.6 KiB
TypeScript

import { useMutationWithInvalidate } from "./query/useQueryWithNetwork";
import { contractKeys } from "@3rdweb-sdk/react";
import { useSDK } from "@thirdweb-dev/react";
import {
DeploySchemaForPrebuiltContractType,
PrebuiltContractType,
} from "@thirdweb-dev/sdk/evm";
import { AnalyticsEvents } from "constants/analytics";
import posthog from "posthog-js";
import invariant from "tiny-invariant";
import { z } from "zod";
export function useDeploy<TContractType extends PrebuiltContractType>(
contractType?: TContractType,
contractVersion = "latest",
) {
const sdk = useSDK();
return useMutationWithInvalidate(
async (
metadata: z.input<DeploySchemaForPrebuiltContractType<TContractType>>,
) => {
invariant(
sdk,
`[Contract:deploy] - attempting to deploy ${contractType} contract without an active sdk`,
);
invariant(contractType, "[Contract:deploy] - contractType is required");
const contractAddress = await sdk.deployer.deployBuiltInContract(
contractType,
metadata,
contractVersion ? contractVersion : "latest",
);
return { contractAddress };
},
{
onSuccess: ({ contractAddress }, _variables, _options, invalidate) => {
console.info("contract deployed with information", {
contractAddress,
contractType,
});
if (contractType) {
posthog.capture(AnalyticsEvents.DeploymentEvents[contractType], {
contractAddress,
});
}
return invalidate([contractKeys.list()]);
},
},
);
}