Skip to content

Commit c58dcaa

Browse files
committed
[TOOL-3009] Dashboard: Support all valid domains as ENS name and not just .eth
1 parent 332536b commit c58dcaa

File tree

15 files changed

+154
-31
lines changed

15 files changed

+154
-31
lines changed

.changeset/happy-carrots-appear.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Add `isValidENSName` utility function to `thirdweb` package for checking if a string is can be a valid ENS name - It does not check if the name is registered on the ENS registry, it only checks if the string is in a valid format for an ENS name.
6+
7+
```ts
8+
isValidENSName("thirdweb.eth"); // true
9+
isValidENSName("foo.bar.com"); // true
10+
isValidENSName("foo"); // false
11+
```

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/overview/components/published-by-ui.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { getBytecode, getContract } from "thirdweb/contract";
66
import { getPublishedUriFromCompilerUri } from "thirdweb/extensions/thirdweb";
77
import { getInstalledModules } from "thirdweb/modules";
88
import { download } from "thirdweb/storage";
9-
import { extractIPFSUri } from "thirdweb/utils";
9+
import { extractIPFSUri, isValidENSName } from "thirdweb/utils";
1010
import { fetchPublishedContractsFromDeploy } from "../../../../../../../components/contract-components/fetchPublishedContractsFromDeploy";
11-
import { isEnsName, resolveEns } from "../../../../../../../lib/ens";
11+
import { resolveEns } from "../../../../../../../lib/ens";
1212

1313
type ModuleMetadataPickedKeys = {
1414
publisher: string;
@@ -52,7 +52,7 @@ export async function getPublishedByCardProps(params: {
5252

5353
// get publisher address/ens
5454
let publisherAddressOrEns = publishedContractToShow.publisher;
55-
if (!isEnsName(publishedContractToShow.publisher)) {
55+
if (!isValidENSName(publishedContractToShow.publisher)) {
5656
try {
5757
const res = await resolveEns(publishedContractToShow.publisher);
5858
if (res.ensName) {

apps/dashboard/src/app/(dashboard)/profile/[addressOrEns]/resolveAddressAndEns.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getAddress, isAddress } from "thirdweb";
2+
import { isValidENSName } from "thirdweb/utils";
23
import { mapThirdwebPublisher } from "../../../../components/contract-components/fetch-contracts-with-versions";
3-
import { isEnsName, resolveEns } from "../../../../lib/ens";
4+
import { resolveEns } from "../../../../lib/ens";
45

56
type ResolvedAddressInfo = {
67
address: string;
@@ -17,7 +18,7 @@ export async function resolveAddressAndEns(
1718
};
1819
}
1920

20-
if (isEnsName(addressOrEns)) {
21+
if (isValidENSName(addressOrEns)) {
2122
const mappedEns = mapThirdwebPublisher(addressOrEns);
2223
const res = await resolveEns(mappedEns).catch(() => null);
2324
if (res?.address) {

apps/dashboard/src/app/(dashboard)/published-contract/[publisher]/[contract_id]/[version]/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export default async function PublishedContractPage(
8585
<SimpleGrid columns={12} gap={{ base: 6, md: 10 }} w="full">
8686
<PublishedContract
8787
publishedContract={publishedContract}
88-
walletOrEns={params.publisher}
8988
twAccount={account}
9089
/>
9190
</SimpleGrid>

apps/dashboard/src/app/(dashboard)/published-contract/[publisher]/[contract_id]/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export default async function PublishedContractPage(
5454
<div className="grid w-full grid-cols-12 gap-6 md:gap-10">
5555
<PublishedContract
5656
publishedContract={publishedContract}
57-
walletOrEns={params.publisher}
5857
twAccount={account}
5958
/>
6059
</div>

apps/dashboard/src/components/contract-components/hooks.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import { useThirdwebClient } from "@/constants/thirdweb.client";
44
import { queryOptions, useQuery } from "@tanstack/react-query";
55
import type { Abi } from "abitype";
6-
import { isEnsName, resolveEns } from "lib/ens";
6+
import { resolveEns } from "lib/ens";
77
import { useV5DashboardChain } from "lib/v5-adapter";
88
import { useMemo } from "react";
99
import type { ThirdwebContract } from "thirdweb";
1010
import { getContract, resolveContractAbi } from "thirdweb/contract";
11-
import { isAddress } from "thirdweb/utils";
11+
import { isAddress, isValidENSName } from "thirdweb/utils";
1212
import {
1313
type PublishedContractWithVersion,
1414
fetchPublishedContractVersions,
@@ -130,7 +130,7 @@ function ensQuery(addressOrEnsName?: string) {
130130
return placeholderData;
131131
}
132132
// if it is neither an address or an ens name then return the placeholder data only
133-
if (!isAddress(addressOrEnsName) && !isEnsName(addressOrEnsName)) {
133+
if (!isAddress(addressOrEnsName) && !isValidENSName(addressOrEnsName)) {
134134
throw new Error("Invalid address or ENS name.");
135135
}
136136

@@ -143,7 +143,7 @@ function ensQuery(addressOrEnsName?: string) {
143143
}),
144144
);
145145

146-
if (isEnsName(addressOrEnsName) && !address) {
146+
if (isValidENSName(addressOrEnsName) && !address) {
147147
throw new Error("Failed to resolve ENS name.");
148148
}
149149

@@ -154,7 +154,7 @@ function ensQuery(addressOrEnsName?: string) {
154154
},
155155
enabled:
156156
!!addressOrEnsName &&
157-
(isAddress(addressOrEnsName) || isEnsName(addressOrEnsName)),
157+
(isAddress(addressOrEnsName) || isValidENSName(addressOrEnsName)),
158158
// 24h
159159
gcTime: 60 * 60 * 24 * 1000,
160160
// 1h

apps/dashboard/src/components/contract-components/published-contract/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@ interface ExtendedPublishedContract extends PublishedContractWithVersion {
4242

4343
interface PublishedContractProps {
4444
publishedContract: ExtendedPublishedContract;
45-
walletOrEns: string;
4645
twAccount: Account | undefined;
4746
}
4847

4948
export const PublishedContract: React.FC<PublishedContractProps> = ({
5049
publishedContract,
51-
walletOrEns,
5250
twAccount,
5351
}) => {
5452
const address = useActiveAccount()?.address;
@@ -154,7 +152,9 @@ export const PublishedContract: React.FC<PublishedContractProps> = ({
154152
</GridItem>
155153
<GridItem colSpan={{ base: 12, md: 3 }}>
156154
<Flex flexDir="column" gap={6}>
157-
{walletOrEns && <PublisherHeader wallet={walletOrEns} />}
155+
{publishedContract.publisher && (
156+
<PublisherHeader wallet={publishedContract.publisher} />
157+
)}
158158
<Divider />
159159
<Flex flexDir="column" gap={4}>
160160
<Heading as="h4" size="title.sm">

apps/dashboard/src/components/contract-components/publisher/publisher-header.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,16 @@ export const PublisherHeader: React.FC<PublisherHeaderProps> = ({
8383
>
8484
<AccountName
8585
fallbackComponent={
86-
<AccountAddress
87-
formatFn={(addr) =>
88-
shortenIfAddress(replaceDeployerAddress(addr))
89-
}
90-
/>
86+
// When social profile API support other TLDs as well - we can remove this condition
87+
ensQuery.data?.ensName ? (
88+
<span> {ensQuery.data?.ensName} </span>
89+
) : (
90+
<AccountAddress
91+
formatFn={(addr) =>
92+
shortenIfAddress(replaceDeployerAddress(addr))
93+
}
94+
/>
95+
)
9196
}
9297
loadingComponent={<Skeleton className="h-8 w-40" />}
9398
formatFn={(name) => replaceDeployerAddress(name)}

apps/dashboard/src/lib/address-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { isAddress } from "thirdweb";
2-
import { isEnsName } from "./ens";
2+
import { isValidENSName } from "thirdweb/utils";
33

44
// if a string is a valid address or ens name
55
export function isPossibleEVMAddress(address?: string, ignoreEns?: boolean) {
66
if (!address) {
77
return false;
88
}
9-
if (isEnsName(address) && !ignoreEns) {
9+
if (isValidENSName(address) && !ignoreEns) {
1010
return true;
1111
}
1212
return isAddress(address);

apps/dashboard/src/lib/ens.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { getThirdwebClient } from "@/constants/thirdweb.server";
22
import { isAddress } from "thirdweb";
33
import { resolveAddress, resolveName } from "thirdweb/extensions/ens";
4+
import { isValidENSName } from "thirdweb/utils";
45

56
interface ENSResolveResult {
67
ensName: string | null;
78
address: string | null;
89
}
910

10-
export function isEnsName(name: string): boolean {
11-
return name?.endsWith(".eth");
12-
}
13-
1411
export async function resolveEns(
1512
ensNameOrAddress: string,
1613
): Promise<ENSResolveResult> {
@@ -24,7 +21,7 @@ export async function resolveEns(
2421
};
2522
}
2623

27-
if (!isEnsName(ensNameOrAddress)) {
24+
if (!isValidENSName(ensNameOrAddress)) {
2825
throw new Error("Invalid ENS name");
2926
}
3027

0 commit comments

Comments
 (0)