Skip to content

Commit ead1c01

Browse files
committed
fix, cleanup
1 parent 766d05f commit ead1c01

File tree

7 files changed

+222
-81
lines changed

7 files changed

+222
-81
lines changed

apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type CustomContractDeploymentFormData = {
7171
deployDeterministic: boolean;
7272
saltForCreate2: string;
7373
signerAsSalt: boolean;
74-
deployParams: Record<string, string>;
74+
deployParams: Record<string, string | ContractRef>;
7575
moduleData: Record<string, Record<string, string>>;
7676
contractMetadata?: {
7777
name: string;
@@ -82,6 +82,14 @@ type CustomContractDeploymentFormData = {
8282
recipients?: Recipient[];
8383
};
8484

85+
interface ContractRef {
86+
ref: {
87+
publisher: string;
88+
version: string;
89+
contractId: string;
90+
};
91+
}
92+
8593
export type CustomContractDeploymentForm =
8694
UseFormReturn<CustomContractDeploymentFormData>;
8795

@@ -210,9 +218,15 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
210218
acc[param.name] = activeAccount.address;
211219
}
212220

221+
// specify refs if present
222+
const ref = metadata?.constructorParams?.[param.name]?.ref;
223+
if (ref && acc[param.name] === "") {
224+
acc[param.name] = { ref };
225+
}
226+
213227
return acc;
214228
},
215-
{} as Record<string, string>,
229+
{} as Record<string, string | ContractRef>,
216230
),
217231
}),
218232
[deployParams, metadata?.constructorParams, activeAccount, walletChain?.id],
@@ -357,7 +371,11 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
357371
const contructorParams = metadata?.constructorParams || {};
358372
const extraMetadataParam = contructorParams[paramKey];
359373

360-
if (shouldHide(paramKey) || !extraMetadataParam?.hidden) {
374+
if (
375+
shouldHide(paramKey) ||
376+
!extraMetadataParam?.hidden ||
377+
extraMetadataParam?.ref
378+
) {
361379
return null;
362380
}
363381

@@ -416,11 +434,12 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
416434
params: {
417435
name: params.contractMetadata?.name || "",
418436
contractURI: _contractURI,
419-
defaultAdmin: params.deployParams._defaultAdmin,
437+
defaultAdmin: params.deployParams._defaultAdmin as string,
420438
platformFeeBps: Number(params.deployParams._platformFeeBps),
421-
platformFeeRecipient: params.deployParams._platformFeeRecipient,
439+
platformFeeRecipient: params.deployParams
440+
._platformFeeRecipient as string,
422441
trustedForwarders: params.deployParams._trustedForwarders
423-
? JSON.parse(params.deployParams._trustedForwarders)
442+
? JSON.parse(params.deployParams._trustedForwarders as string)
424443
: undefined,
425444
},
426445
});
@@ -657,7 +676,7 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
657676
).error?.message,
658677
}}
659678
royaltyBps={{
660-
value: form.watch("deployParams._royaltyBps"),
679+
value: form.watch("deployParams._royaltyBps") as string,
661680
isInvalid: !!form.getFieldState(
662681
"deployParams._royaltyBps",
663682
form.formState,
@@ -754,7 +773,11 @@ export const CustomContractForm: React.FC<CustomContractFormProps> = ({
754773
const contructorParams = metadata?.constructorParams || {};
755774
const extraMetadataParam = contructorParams[paramKey];
756775

757-
if (shouldHide(paramKey) || extraMetadataParam?.hidden) {
776+
if (
777+
shouldHide(paramKey) ||
778+
extraMetadataParam?.hidden ||
779+
extraMetadataParam?.ref
780+
) {
758781
return null;
759782
}
760783

apps/dashboard/src/components/contract-components/contract-publish-form/contract-params-fieldset.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
Heading,
2626
Text,
2727
} from "tw-components";
28-
import { RefContractsFieldset } from "./ref-input-fieldset";
28+
import { RefContractInput } from "./ref-input";
2929

3030
interface ContractParamsFieldsetProps {
3131
deployParams: readonly AbiParameter[];
@@ -168,7 +168,7 @@ export const ContractParamsFieldset: React.FC<ContractParamsFieldsetProps> = ({
168168
/>
169169
</>
170170
) : (
171-
<RefContractsFieldset param={param} />
171+
<RefContractInput param={param} />
172172
)}
173173

174174
{param.type === "address" && (

apps/dashboard/src/components/contract-components/contract-publish-form/impl-params-fieldset.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
Heading,
2222
Text,
2323
} from "tw-components";
24-
import { RefContractsFieldset } from "./ref-input-fieldset";
24+
import { RefContractImplInput } from "./ref-input-impl";
2525

2626
interface ImplementationParamsFieldsetProps {
2727
implParams: readonly AbiParameter[];
@@ -126,7 +126,7 @@ export const ImplementationParamsFieldset: React.FC<
126126
/>
127127
</>
128128
) : (
129-
<RefContractsFieldset param={param} />
129+
<RefContractImplInput param={param} />
130130
)}
131131

132132
{param.type === "address" && (

apps/dashboard/src/components/contract-components/contract-publish-form/ref-input-fieldset.tsx

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import {
2+
Divider,
3+
Flex,
4+
FormControl,
5+
Input,
6+
Select,
7+
Skeleton,
8+
} from "@chakra-ui/react";
9+
import type { AbiParameter } from "abitype";
10+
import { useFormContext } from "react-hook-form";
11+
import { FormLabel } from "tw-components";
12+
import { useAllVersions, usePublishedContractsQuery } from "../hooks";
13+
14+
interface RefContractImplInputProps {
15+
param: AbiParameter;
16+
}
17+
18+
export const RefContractImplInput: React.FC<RefContractImplInputProps> = ({
19+
param,
20+
}) => {
21+
const form = useFormContext();
22+
23+
const publishedContractsQuery = usePublishedContractsQuery(
24+
form.watch(
25+
`implConstructorParams.${param.name ? param.name : "*"}.ref.publisherAddress`,
26+
),
27+
);
28+
29+
const allVersions = useAllVersions(
30+
form.watch(
31+
`implConstructorParams.${param.name ? param.name : "*"}.ref.publisherAddress`,
32+
),
33+
form.watch(
34+
`implConstructorParams.${param.name ? param.name : "*"}.ref.contractId`,
35+
),
36+
);
37+
38+
return (
39+
<Flex flexDir="column" gap={2}>
40+
<Flex
41+
w="full"
42+
gap={{ base: 4, md: 2 }}
43+
flexDir={{ base: "column", md: "row" }}
44+
>
45+
<FormControl
46+
as={Flex}
47+
flexDir="column"
48+
gap={1}
49+
isInvalid={
50+
!!form.getFieldState(
51+
`implConstructorParams.${param.name ? param.name : "*"}.ref.publisherAddress`,
52+
form.formState,
53+
).error
54+
}
55+
>
56+
<FormLabel textTransform="capitalize">Publisher</FormLabel>
57+
<Input
58+
placeholder="Address or ENS"
59+
{...form.register(
60+
`implConstructorParams.${param.name ? param.name : "*"}.ref.publisherAddress`,
61+
)}
62+
/>
63+
</FormControl>
64+
<FormControl as={Flex} flexDir="column" gap={1}>
65+
<FormLabel textTransform="capitalize">Contract Name</FormLabel>
66+
<Skeleton
67+
isLoaded={
68+
!!publishedContractsQuery.data ||
69+
!publishedContractsQuery.isFetching
70+
}
71+
borderRadius="lg"
72+
>
73+
<Select
74+
isDisabled={(publishedContractsQuery?.data || []).length === 0}
75+
{...form.register(
76+
`implConstructorParams.${param.name ? param.name : "*"}.ref.contractId`,
77+
)}
78+
placeholder={
79+
publishedContractsQuery.isFetched &&
80+
(publishedContractsQuery?.data || []).length === 0
81+
? "No extensions found"
82+
: "Select extension"
83+
}
84+
>
85+
{publishedContractsQuery?.data?.map(({ contractId }) => (
86+
<option key={contractId} value={contractId}>
87+
{contractId}
88+
</option>
89+
))}
90+
</Select>
91+
</Skeleton>
92+
</FormControl>
93+
94+
<FormControl as={Flex} flexDir="column" gap={1}>
95+
<FormLabel textTransform="capitalize">Contract Version</FormLabel>
96+
<Skeleton
97+
isLoaded={!!allVersions.data || !allVersions.isFetching}
98+
borderRadius="lg"
99+
>
100+
<Select
101+
w="full"
102+
isDisabled={!allVersions.data}
103+
{...form.register(
104+
`implConstructorParams.${param.name ? param.name : "*"}.ref.version`,
105+
)}
106+
borderRadius="lg"
107+
>
108+
<option value="">Always latest</option>
109+
{allVersions?.data?.map(({ version }) => (
110+
<option key={version} value={version}>
111+
{version}
112+
</option>
113+
))}
114+
</Select>
115+
</Skeleton>
116+
</FormControl>
117+
</Flex>
118+
<Divider />
119+
</Flex>
120+
);
121+
};

apps/dashboard/src/components/contract-components/contract-publish-form/ref-input.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ export const RefContractInput: React.FC<RefContractInputProps> = ({
2222

2323
const publishedContractsQuery = usePublishedContractsQuery(
2424
form.watch(
25-
`implConstructorParams.${param.name ? param.name : "*"}.ref.publisherAddress`,
25+
`constructorParams.${param.name ? param.name : "*"}.ref.publisherAddress`,
2626
),
2727
);
2828

2929
const allVersions = useAllVersions(
3030
form.watch(
31-
`implConstructorParams.${param.name ? param.name : "*"}.ref.publisherAddress`,
31+
`constructorParams.${param.name ? param.name : "*"}.ref.publisherAddress`,
3232
),
3333
form.watch(
34-
`implConstructorParams.${param.name ? param.name : "*"}.ref.contractId`,
34+
`constructorParams.${param.name ? param.name : "*"}.ref.contractId`,
3535
),
3636
);
3737

@@ -48,7 +48,7 @@ export const RefContractInput: React.FC<RefContractInputProps> = ({
4848
gap={1}
4949
isInvalid={
5050
!!form.getFieldState(
51-
`implConstructorParams.${param.name ? param.name : "*"}.ref.publisherAddress`,
51+
`constructorParams.${param.name ? param.name : "*"}.ref.publisherAddress`,
5252
form.formState,
5353
).error
5454
}
@@ -57,7 +57,7 @@ export const RefContractInput: React.FC<RefContractInputProps> = ({
5757
<Input
5858
placeholder="Address or ENS"
5959
{...form.register(
60-
`implConstructorParams.${param.name ? param.name : "*"}.ref.publisherAddress`,
60+
`constructorParams.${param.name ? param.name : "*"}.ref.publisherAddress`,
6161
)}
6262
/>
6363
</FormControl>
@@ -73,7 +73,7 @@ export const RefContractInput: React.FC<RefContractInputProps> = ({
7373
<Select
7474
isDisabled={(publishedContractsQuery?.data || []).length === 0}
7575
{...form.register(
76-
`implConstructorParams.${param.name ? param.name : "*"}.ref.contractId`,
76+
`constructorParams.${param.name ? param.name : "*"}.ref.contractId`,
7777
)}
7878
placeholder={
7979
publishedContractsQuery.isFetched &&
@@ -101,7 +101,7 @@ export const RefContractInput: React.FC<RefContractInputProps> = ({
101101
w="full"
102102
isDisabled={!allVersions.data}
103103
{...form.register(
104-
`implConstructorParams.${param.name ? param.name : "*"}.ref.version`,
104+
`constructorParams.${param.name ? param.name : "*"}.ref.version`,
105105
)}
106106
borderRadius="lg"
107107
>

0 commit comments

Comments
 (0)