* homepage: infinite looping logo carousel * split partners logo among two rows on mobile * remove lazy loading from partner logos * Fix partner logo cut off on safari * fade-in logo carousel at the container edge * v1 * v2 * remove temp code changes * switch network *technically* works, and new chains package * Fix src warning in AsyncContractTypeCell * Updated Design for config form, fix metadata error * add initial deployment status modal * Fix contract duplication bug in dashboard * Make RPC url always editable * v3 - middleware + refactor * reset form when selecting custom option * Fix crash on sources tab for unsupported chains * add missing deps in effects * /evm - use SSG with fallback * /evm - add ensQuery dehydration back * /solana - fix program page loading issue * Allow editing details for custom chains * solana program context * fix build crash * fix all the networkOrAddress getters * use chain icons from chains package * separation of fallback and final page * Fix wrong default network type in form * validation improvements in configure network form * disable custom chains from dropdown on On non thirdweb contracts deploy page * Fix wrong network slug * custom chain improvement * Fix Lightmode UI of Network Config Form * UI improvements for network search dropdown * UI tweaks * code review cleanup * UI tweaks * Network Config Form: Better Keyboard UX * fix broken /contracts/release and /contracts/deploy routes * add configure networks button for custom contract deployment page * UI tweaks for network configurator * fix merge * add the icon to the custom chain * Bunch of Improvements * Improve auto chain configuration * Do not allow adding custom network with existing chain id * Show delete default chains with 1-click add * Convert delete dialog to a popover * Retain all fields when selecting a chain from list * Allow configuring chain Icons * Allow using chainId as network slug for custom networks * Remove unnecessary chainInfos object passed in provider * configurable slug + prefill form * improve scrollbar styling * upgrade to newer sdk etc * make it work * Various testjame improvements * Stop form submit event propagation * preselect “testnet” for custom network based on name * Clear form errors when selecting a network from list * Improved UI for Delete network popover * Disable “Add Network” button when on add network page * Change fallback chain icon * custom and search tabs * reduce layout shift when switching tabs * allChains caching with idb * Add IPFS upload button for icon input * Deploy Modal, chain icon, code cleanup * Fix Deploy Modal not working for custom contract deployment * Fix Fantom testnet icon * Remove useDashboardNetwork() * Update Deploy Modal wording in case for 3 prompt scenario * Remove hardhat and localhost from CURRENCIES object * Remove gateway.ipfscdn.io from images.remotePatterns in next config * add chain config tracking * remove useChainInfos() * Remove EVM_RPC_URL_MAP usage as much as possible * Fix Network Switcher for non-default chains * upgrade new dev sdk versions * fix versions * Fix contractInfo.chain not available on contract page of custom chain * Fix contract page links in overview page * Update default chain Icon * bunch of UI improvements for network configuration modal * Better active state for add network button and chains * Suggest a slug for custom network * Show chain id next to network names in list * Allow searching by chain id * Autofocus on first input of the form * Add cross button for clearing search input * Toggle search results open state with chevron icon * Add icons in chain list * handle wallet connected to unsupported network in <SupportedNetworkSelect/> * No reload required after adding a network * revert last commit - reload still required * handle case where wallet is connected to an auto configured chain - show it as unknown network * update dependencies and switch to activeChain and supportedChains * nightly sdk versions * Improved Icon Uploader * always use default chains for polygon registry work * dev version & updated list fetching * Improved Chain ID input in Network Configurator * Improved Network ID validation and prefill * Hide etherscan verification button for non-default chains * Form Refactor + network type toolip * update deps * update package versions * upgrade dependencies * show "create custom" when no search results found * slug calculated from prefillName should not be considered dirty * open edit screen when selecting already configured network from list * fuzzy search with fuse.js * replace thirdweb key with it's value in form * temp fix for getChainRPC throwing error * update to newer chains package * lots of rpc cleanup etc * fix nightly maybe? * upgrade to nightly packages * add initial import contract search input * fix localhost * clean up smoe more stuff * lots of updates * Show "Request Testnet Funds" button in wallet when applicable (#856) * fix crash on events page * Fix Links in Overview page * import contract improvements * Fix wrong explorer tab link in ContractPermissionsPage * make search faster (individual queries) * properly split contract and program routing * remove all via stuff etc * various further improvements * add a proxy and setup storage to hit that proxy * further cleanup --------- Co-authored-by: Jonas Daniels <[email protected]> Co-authored-by: Joaquim Verges <[email protected]>
124 lines
3.7 KiB
TypeScript
124 lines
3.7 KiB
TypeScript
import { useMutationWithInvalidate } from "./query/useQueryWithNetwork";
|
|
import { contractKeys, networkKeys } from "@3rdweb-sdk/react";
|
|
import { useQueryClient } from "@tanstack/react-query";
|
|
import { useAddress, useSDK, useSigner } from "@thirdweb-dev/react";
|
|
import {
|
|
DeploySchemaForPrebuiltContractType,
|
|
PrebuiltContractType,
|
|
} from "@thirdweb-dev/sdk/evm";
|
|
import {
|
|
stepAddToRegistry,
|
|
stepCustomChainDeploy,
|
|
stepDeploy,
|
|
useDeployContextModal,
|
|
} from "components/contract-components/contract-deploy-form/deploy-context-modal";
|
|
import { addContractToMultiChainRegistry } from "components/contract-components/utils";
|
|
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>(
|
|
chainId?: number,
|
|
contractType?: TContractType,
|
|
contractVersion = "latest",
|
|
addToDashboard = true,
|
|
isDefaultChain = true,
|
|
) {
|
|
const sdk = useSDK();
|
|
const signer = useSigner();
|
|
const queryClient = useQueryClient();
|
|
const walletAddress = useAddress();
|
|
const deployContext = useDeployContextModal();
|
|
|
|
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");
|
|
|
|
// open the modal with the appropriate steps
|
|
deployContext.open(
|
|
addToDashboard
|
|
? [
|
|
isDefaultChain ? stepDeploy : stepCustomChainDeploy,
|
|
stepAddToRegistry,
|
|
]
|
|
: [stepDeploy],
|
|
);
|
|
|
|
let contractAddress: string;
|
|
|
|
try {
|
|
// deploy contract
|
|
contractAddress = await sdk.deployer.deployBuiltInContract(
|
|
contractType,
|
|
metadata,
|
|
contractVersion ? contractVersion : "latest",
|
|
);
|
|
// advance to next step
|
|
deployContext.nextStep();
|
|
} catch (e) {
|
|
// failed to deploy contract - close modal for now
|
|
deployContext.close();
|
|
// re-throw error
|
|
throw e;
|
|
}
|
|
|
|
try {
|
|
// let user decide if they want this or not
|
|
if (addToDashboard) {
|
|
// add to new multi-chain registry
|
|
invariant(
|
|
chainId,
|
|
`[Contract:add-to-registry] - chainId is required`,
|
|
);
|
|
await addContractToMultiChainRegistry(
|
|
{
|
|
address: contractAddress,
|
|
chainId,
|
|
},
|
|
signer,
|
|
);
|
|
// advance to next step
|
|
deployContext.nextStep();
|
|
}
|
|
} catch (e) {
|
|
// failed to add to dashboard - for now just close the modal
|
|
deployContext.close();
|
|
// not re-throwing the error, this is not technically a failure to deploy, just to add to dashboard - the contract is deployed already at this stage
|
|
}
|
|
|
|
// always close the modal
|
|
deployContext.close();
|
|
|
|
return { contractAddress };
|
|
},
|
|
{
|
|
onSuccess: ({ contractAddress }, _variables, _options, invalidate) => {
|
|
console.info("contract deployed with information", {
|
|
contractAddress,
|
|
contractType,
|
|
});
|
|
if (contractType) {
|
|
posthog.capture(AnalyticsEvents.DeploymentEvents[contractType], {
|
|
contractAddress,
|
|
});
|
|
}
|
|
|
|
return Promise.all([
|
|
invalidate([contractKeys.list()]),
|
|
queryClient.invalidateQueries([
|
|
networkKeys.multiChainRegistry,
|
|
walletAddress || "",
|
|
]),
|
|
]);
|
|
},
|
|
},
|
|
);
|
|
}
|