Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ import {
import { useActiveAccount, useActiveWalletChain } from "thirdweb/react";
import { upload } from "thirdweb/storage";
import { FormHelperText, FormLabel, Heading, Text } from "tw-components";
import { useCustomFactoryAbi, useFunctionParamsFromABI } from "../hooks";
import {
useCustomFactoryAbi,
useFunctionParamsFromABI,
useMintfeeManager,
useMultisig,
} from "../hooks";
import { addContractToMultiChainRegistry } from "../utils";
import { Fieldset } from "./common";
import { ContractMetadataFieldset } from "./contract-metadata-fieldset";
Expand Down Expand Up @@ -149,6 +154,9 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({

const isTWPublisher = checkTwPublisher(metadata?.publisher);

const multisig = useMultisig(walletChain?.id);
const mintfeeManager = useMintfeeManager(walletChain?.id);

const initializerParams = useFunctionParamsFromABI(
metadata?.deployType === "customFactory" && customFactoryAbi?.data
? customFactoryAbi.data
Expand Down Expand Up @@ -193,6 +201,8 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
{
connectedWallet: activeAccount?.address,
chainId: walletChain?.id,
multisig: multisig.data?.multisig,
mintFeeManager: mintfeeManager.data?.mintfeeManager,
},
);

Expand All @@ -212,7 +222,14 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
{} as Record<string, string>,
),
}),
[deployParams, metadata?.constructorParams, activeAccount, walletChain?.id],
[
deployParams,
metadata?.constructorParams,
activeAccount,
walletChain?.id,
mintfeeManager,
multisig,
],
);

const transformedQueryData = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
Input,
InputGroup,
InputRightElement,
Select,
Textarea,
Tooltip,
useBreakpointValue,
} from "@chakra-ui/react";
import type { AbiParameter } from "abitype";
Expand All @@ -15,8 +15,6 @@ import { camelToTitle } from "contract-ui/components/solidity-inputs/helpers";
import { getTemplateValuesForType } from "lib/deployment/template-values";
import { useFormContext } from "react-hook-form";
import {
Button,
Card,
Checkbox,
FormErrorMessage,
FormHelperText,
Expand Down Expand Up @@ -133,44 +131,27 @@ export const ContractParamsFieldset: React.FC<ContractParamsFieldsetProps> = ({
/>
</Flex>
{paramTemplateValues.length > 0 && (
<InputRightElement width="10.5rem">
<Tooltip
bg="transparent"
boxShadow="none"
shouldWrapChildren
label={
<Card
as={Flex}
flexDir="column"
gap={2}
bgColor="backgroundHighlight"
>
<Text>
{paramTemplateValues[0]?.helperText} Click to
apply.
</Text>
</Card>
}
<InputRightElement width="12rem">
<Select
size="xs"
placeholder="Select value"
onChange={(e) => {
form.setValue(
`constructorParams.${param.name ? param.name : "*"}.defaultValue`,
e.target.value,
{ shouldDirty: true },
);
}}
>
<Button
size="xs"
padding="3"
paddingY="3.5"
onClick={() => {
form.setValue(
`constructorParams.${
param.name ? param.name : "*"
}.defaultValue`,
paramTemplateValues[0]?.value,
{
shouldDirty: true,
},
);
}}
>
{paramTemplateValues[0]?.value}
</Button>
</Tooltip>
{paramTemplateValues.map((paramTemplate) => (
<option
key={paramTemplate.value}
value={paramTemplate?.value}
>
{paramTemplate?.value}
</option>
))}
</Select>
</InputRightElement>
)}
</InputGroup>
Expand Down
76 changes: 75 additions & 1 deletion apps/dashboard/src/components/contract-components/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import type { Abi } from "abitype";
import { isEnsName, resolveEns } from "lib/ens";
import { useV5DashboardChain } from "lib/v5-adapter";
import { useMemo } from "react";
import { type ThirdwebContract, getContract } from "thirdweb";
import { type ThirdwebContract, ZERO_ADDRESS, getContract } from "thirdweb";
import { resolveContractAbi } from "thirdweb/contract";
import {
getPredictedMintFeeManagerAddress,
getPredictedMultisigAddress,
} from "thirdweb/deploys";
import { isAddress } from "thirdweb/utils";
import {
type PublishedContractWithVersion,
Expand Down Expand Up @@ -150,6 +154,68 @@ export function usePublishedContractsQuery(address?: string) {
});
}

function multisigQuery(chainId: number | undefined) {
let chainIdFinal = chainId;
if (!chainIdFinal) {
chainIdFinal = 1;
}

return queryOptions({
queryKey: ["multisig", chainIdFinal],
queryFn: async () => {
const chain = useV5DashboardChain(chainIdFinal);
const client = useThirdwebClient();

const multisig = await getPredictedMultisigAddress({ client, chain });

return {
multisig,
};
},
enabled: !!chainId,
// 24h
gcTime: 60 * 60 * 24 * 1000,
// 1h
staleTime: 60 * 60 * 1000,
// default to zero address
placeholderData: { multisig: ZERO_ADDRESS },
retry: false,
});
}

function mintfeeManagerQuery(chainId: number | undefined) {
let chainIdFinal = chainId;

if (!chainIdFinal) {
chainIdFinal = 1;
}

return queryOptions({
queryKey: ["mintfee-manager", chainIdFinal],
queryFn: async () => {
const chain = useV5DashboardChain(chainIdFinal);
const client = useThirdwebClient();

const mintfeeManager = await getPredictedMintFeeManagerAddress({
client,
chain,
});

return {
mintfeeManager,
};
},
enabled: !!chainId,
// 24h
gcTime: 60 * 60 * 24 * 1000,
// 1h
staleTime: 60 * 60 * 1000,
// default to zero address
placeholderData: { mintfeeManager: ZERO_ADDRESS },
retry: false,
});
}

function ensQuery(addressOrEnsName?: string) {
// if the address is `thirdweb.eth` we actually want `deployer.thirdweb.eth` here...
if (addressOrEnsName === "thirdweb.eth") {
Expand Down Expand Up @@ -208,6 +274,14 @@ export function useEns(addressOrEnsName?: string) {
return useQuery(ensQuery(addressOrEnsName));
}

export function useMultisig(chainId: number | undefined) {
return useQuery(multisigQuery(chainId));
}

export function useMintfeeManager(chainId: number | undefined) {
return useQuery(mintfeeManagerQuery(chainId));
}

export function useContractEvents(abi: Abi) {
return abi.filter((a) => a.type === "event");
}
Expand Down
22 changes: 22 additions & 0 deletions apps/dashboard/src/lib/deployment/template-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { SolidityType } from "lib/solidity-types";
interface ReplacementProps {
connectedWallet?: string;
chainId?: number;
mintFeeManager?: string;
multisig?: string;
}

interface TemplateValue {
Expand All @@ -25,6 +27,26 @@ const ADDRESS_TEMPLATE_VALUES: TemplateValue[] = [
);
},
},
{
value: "{{tw_mintfee_manager}}",
helperText: "Replaced with the address of the thirdweb mint fee manager.",
replacerFunction: (searchValue, replacers) => {
return searchValue.replaceAll(
"{{tw_mintfee_manager}}",
replacers.mintFeeManager || "",
);
},
},
{
value: "{{tw_multisig}}",
helperText: "Replaced with the address of the thirdweb multisig.",
replacerFunction: (searchValue, replacers) => {
return searchValue.replaceAll(
"{{tw_multisig}}",
replacers.multisig || "",
);
},
},
];

const ADDRESS_ARRAY_TEMPLATE_VALUES: TemplateValue[] = [
Expand Down
Loading
Loading