Skip to content

Commit f323f7c

Browse files
committed
[TOOL-2990] Dashboard: Fix invalid form validation when updating custom chain (#5913)
--- title: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" --- If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on refining the network selection and configuration logic in the dashboard, specifically improving how favorite and recent networks are displayed, enhancing the handling of deprecated chains, and simplifying error messages related to network slugs. ### Detailed summary - Rearranged the `chainSections` to maintain the `Favorites` section at the top. - Updated logic for `rpcUrl` to handle deprecated chains more clearly. - Simplified error message when a slug is taken, removing specific references to existing chains. - Enhanced validation logic for checking if a slug is unique, considering custom chains. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent b2b5ae3 commit f323f7c

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

apps/dashboard/src/@3rdweb-sdk/react/components/connect-wallet/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ export const CustomConnectWallet = (props: {
9393

9494
const chainSections: NetworkSelectorProps["sections"] = useMemo(() => {
9595
return [
96-
{
97-
label: "Favorites",
98-
chains: favoriteChainsWithMetadata,
99-
},
10096
{
10197
label: "Recent",
10298
chains: recentlyUsedChainsWithMetadata,
10399
},
100+
{
101+
label: "Favorites",
102+
chains: favoriteChainsWithMetadata,
103+
},
104104
{
105105
label: "Popular",
106106
chains: popularChainsWithMetadata,

apps/dashboard/src/components/configure-networks/ConfigureNetworkForm.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
6262
values: {
6363
name: editingChain?.name || prefillSlug || "",
6464
rpcUrl:
65-
editingChain && editingChain?.status !== "deprecated"
66-
? getDashboardChainRpc(editingChain.chainId, editingChain)
67-
: "",
65+
(!editingChain || editingChain.status === "deprecated"
66+
? ""
67+
: // if chain is custom or modified, show the rpc as is
68+
editingChain.isCustom || editingChain.isModified
69+
? editingChain.rpc[0]
70+
: getDashboardChainRpc(editingChain.chainId, editingChain)) || "",
6871
chainId: editingChain?.chainId
6972
? `${editingChain?.chainId}`
7073
: prefillChainId || "",

apps/dashboard/src/components/configure-networks/Form/NetworkIdInput.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ export const NetworkIDInput: React.FC<{
88
form: UseFormReturn<NetworkConfigFormData>;
99
disabled?: boolean;
1010
}> = ({ form, disabled }) => {
11-
const slug = form.watch("slug");
1211
const { slugToChain } = useAllChainsData();
13-
const existingChain = slugToChain.get(slug);
1412

1513
return (
1614
<FormFieldSetup
@@ -29,12 +27,7 @@ export const NetworkIDInput: React.FC<{
2927
}
3028
errorMessage={
3129
form.formState.errors.slug?.type === "taken" ? (
32-
<>
33-
Can not use {`"${slug}"`}.{" "}
34-
{slug &&
35-
existingChain &&
36-
`It is being used by "${existingChain.name}"`}
37-
</>
30+
<>Slug is taken by other network</>
3831
) : undefined
3932
}
4033
>
@@ -59,7 +52,13 @@ export const NetworkIDInput: React.FC<{
5952
return true;
6053
}
6154

62-
return !slugToChain.has(_slug);
55+
const chainForSlug = slugToChain.get(_slug);
56+
57+
if (chainForSlug && !chainForSlug.isCustom) {
58+
return false;
59+
}
60+
61+
return true;
6362
},
6463
},
6564
})}

0 commit comments

Comments
 (0)