Skip to content
Merged
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
5 changes: 3 additions & 2 deletions apps/dashboard/src/@/components/blocks/FormFieldSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import { ToolTipLabel } from "@/components/ui/tooltip";
import { AsteriskIcon, InfoIcon } from "lucide-react";

export function FormFieldSetup(props: {
htmlFor: string;
htmlFor?: string;
label: string;
errorMessage: React.ReactNode | undefined;
children: React.ReactNode;
tooltip?: React.ReactNode;
isRequired: boolean;
helperText?: React.ReactNode;
className?: string;
}) {
return (
<div>
<div className={props.className}>
<div className="mb-2 inline-flex items-center gap-1">
<Label htmlFor={props.htmlFor}>{props.label}</Label>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default async function PublishContractPage(
}

return (
<div className="container flex flex-col gap-8 py-8">
<div className="container flex max-w-[1130px] flex-col gap-8 py-8">
<ChakraProviderSetup>
<ContractPublishForm
jwt={token}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type CustomContractDeploymentFormData = {
deployDeterministic: boolean;
saltForCreate2: string;
signerAsSalt: boolean;
deployParams: Record<string, string>;
deployParams: Record<string, string | DynamicValue>;
moduleData: Record<string, Record<string, string>>;
contractMetadata?: {
name: string;
Expand All @@ -80,6 +80,18 @@ type CustomContractDeploymentFormData = {
recipients?: Recipient[];
};

export interface DynamicValue {
dynamicValue: {
type: string;
refContracts?: {
publisherAddress: string;
version: string;
contractId: string;
salt?: string;
}[];
};
}

export type CustomContractDeploymentForm =
UseFormReturn<CustomContractDeploymentFormData>;

Expand Down Expand Up @@ -159,6 +171,8 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
"initialize",
);

const implementationConstructorParams = metadata?.implConstructorParams;

const isFactoryDeployment =
metadata?.isDeployableViaFactory ||
metadata?.isDeployableViaProxy ||
Expand Down Expand Up @@ -206,9 +220,16 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
acc[param.name] = activeAccount.address;
}

// specify refs if present
const dynamicValue =
metadata?.constructorParams?.[param.name]?.dynamicValue;
if (dynamicValue && acc[param.name] === "") {
acc[param.name] = { dynamicValue };
}

return acc;
},
{} as Record<string, string>,
{} as Record<string, string | DynamicValue>,
),
}),
[deployParams, metadata?.constructorParams, activeAccount, walletChain?.id],
Expand Down Expand Up @@ -353,7 +374,11 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
const contructorParams = metadata?.constructorParams || {};
const extraMetadataParam = contructorParams[paramKey];

if (shouldHide(paramKey) || !extraMetadataParam?.hidden) {
if (
shouldHide(paramKey) ||
extraMetadataParam?.hidden !== true ||
extraMetadataParam?.dynamicValue
) {
return null;
}

Expand Down Expand Up @@ -412,11 +437,12 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
params: {
name: params.contractMetadata?.name || "",
contractURI: _contractURI,
defaultAdmin: params.deployParams._defaultAdmin,
defaultAdmin: params.deployParams._defaultAdmin as string,
platformFeeBps: Number(params.deployParams._platformFeeBps),
platformFeeRecipient: params.deployParams._platformFeeRecipient,
platformFeeRecipient: params.deployParams
._platformFeeRecipient as string,
trustedForwarders: params.deployParams._trustedForwarders
? JSON.parse(params.deployParams._trustedForwarders)
? JSON.parse(params.deployParams._trustedForwarders as string)
: undefined,
},
});
Expand All @@ -442,6 +468,7 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
client: thirdwebClient,
deployMetadata: metadata,
initializeParams,
implementationConstructorParams,
salt,
modules: modules?.map((m) => ({
deployMetadata: m,
Expand Down Expand Up @@ -652,7 +679,7 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
).error?.message,
}}
royaltyBps={{
value: form.watch("deployParams._royaltyBps"),
value: form.watch("deployParams._royaltyBps") as string,
isInvalid: !!form.getFieldState(
"deployParams._royaltyBps",
form.formState,
Expand Down Expand Up @@ -749,7 +776,11 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
const contructorParams = metadata?.constructorParams || {};
const extraMetadataParam = contructorParams[paramKey];

if (shouldHide(paramKey) || extraMetadataParam?.hidden) {
if (
shouldHide(paramKey) ||
extraMetadataParam?.hidden === true ||
extraMetadataParam?.dynamicValue
) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { Flex, FormControl, InputGroup } from "@chakra-ui/react";
import { SolidityInput } from "contract-ui/components/solidity-inputs";
import { FormErrorMessage, FormHelperText, FormLabel } from "tw-components";
import { Fieldset } from "./common";
import type { CustomContractDeploymentForm } from "./custom-contract";
import type {
CustomContractDeploymentForm,
DynamicValue,
} from "./custom-contract";

interface TrustedForwardersFieldsetProps {
form: CustomContractDeploymentForm;
Expand All @@ -11,56 +14,65 @@ interface TrustedForwardersFieldsetProps {
export const TrustedForwardersFieldset: React.FC<
TrustedForwardersFieldsetProps
> = ({ form }) => {
const isDynamicValue = (val: string | DynamicValue): val is DynamicValue => {
return typeof val === "object" && val !== null && "dynamicValue" in val;
};

const value = form.watch("deployParams._trustedForwarders");
return (
<Fieldset legend="Gasless">
<FormControl
isRequired
isInvalid={
!!form.getFieldState(
"deployParams._trustedForwarders",
form.formState,
).error
}
>
<div className="flex items-center justify-between gap-6">
{/* left */}
<div>
<FormLabel>Trusted Forwarders</FormLabel>
<>
{!isDynamicValue(value) && (
<Fieldset legend="Gasless">
<FormControl
isRequired
isInvalid={
!!form.getFieldState(
"deployParams._trustedForwarders",
form.formState,
).error
}
>
<div className="flex items-center justify-between gap-6">
{/* left */}
<div>
<FormLabel>Trusted Forwarders</FormLabel>

<FormHelperText className="!text-sm text-muted-foreground">
<span className="mb-1 block text-muted-foreground text-sm">
Trusted forwarder addresses to enable ERC-2771 transactions
(i.e. gasless).
</span>
<FormHelperText className="!text-sm text-muted-foreground">
<span className="mb-1 block text-muted-foreground text-sm">
Trusted forwarder addresses to enable ERC-2771 transactions
(i.e. gasless).
</span>

<span className="block text-muted-foreground text-sm">
You can provide your own forwarder.
</span>
</FormHelperText>
</div>
</div>
<span className="block text-muted-foreground text-sm">
You can provide your own forwarder.
</span>
</FormHelperText>
</div>
</div>

<div className="fade-in-0 block animate-in pt-3 duration-400">
<InputGroup size="md">
<Flex flexDir="column" w="full">
<SolidityInput
value={form.watch("deployParams._trustedForwarders")}
solidityType="address[]"
{...form.register("deployParams._trustedForwarders")}
/>
</Flex>
</InputGroup>
<div className="fade-in-0 block animate-in pt-3 duration-400">
<InputGroup size="md">
<Flex flexDir="column" w="full">
<SolidityInput
value={value}
solidityType="address[]"
{...form.register("deployParams._trustedForwarders")}
/>
</Flex>
</InputGroup>

<FormErrorMessage>
{
form.getFieldState(
"deployParams._trustedForwarders",
form.formState,
).error?.message
}
</FormErrorMessage>
</div>
</FormControl>
</Fieldset>
<FormErrorMessage>
{
form.getFieldState(
"deployParams._trustedForwarders",
form.formState,
).error?.message
}
</FormErrorMessage>
</div>
</FormControl>
</Fieldset>
)}
</>
);
};
Loading
Loading