Skip to content

Commit 9c9d8ea

Browse files
authored
feat(explorer): show explored world title (#3751)
1 parent 8c43faf commit 9c9d8ea

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

.changeset/curly-frogs-argue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@latticexyz/explorer": patch
3+
---
4+
5+
Address and name of verified worlds are now shown in the navigation tab.

packages/explorer/src/app/(explorer)/queries/useWorldsQuery.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async function getExternalWorlds(chain: MUDChain) {
8686
return data.items.map((world) => getAddress(world.address.hash));
8787
}
8888

89-
function useVerifiedWorldsQuery(chain: MUDChain) {
89+
export function useVerifiedWorldsQuery(chain: MUDChain) {
9090
return useQuery({
9191
queryKey: ["verifiedWorlds", chain.id],
9292
queryFn: async () => {
@@ -102,7 +102,7 @@ function useVerifiedWorldsQuery(chain: MUDChain) {
102102
});
103103
}
104104

105-
function useIndexerWorldsQuery(chain: MUDChain, indexer: ReturnType<typeof useIndexerForChainId>) {
105+
export function useIndexerWorldsQuery(chain: MUDChain, indexer: ReturnType<typeof useIndexerForChainId>) {
106106
return useQuery({
107107
queryKey: ["indexerWorlds", chain.id, indexer.type],
108108
queryFn: async () => {

packages/explorer/src/components/Navigation.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
"use client";
22

3-
import { LoaderIcon } from "lucide-react";
3+
import { BadgeCheckIcon, LoaderIcon } from "lucide-react";
44
import Link from "next/link";
5-
import { usePathname } from "next/navigation";
5+
import { useParams, usePathname } from "next/navigation";
6+
import { Address } from "viem";
7+
import { useChain } from "../app/(explorer)/hooks/useChain";
68
import { useReadOnly } from "../app/(explorer)/hooks/useReadOnly";
79
import { useWorldUrl } from "../app/(explorer)/hooks/useWorldUrl";
810
import { useWorldAbiQuery } from "../app/(explorer)/queries/useWorldAbiQuery";
11+
import { useVerifiedWorldsQuery } from "../app/(explorer)/queries/useWorldsQuery";
912
import { LatestBlock } from "../components/LatestBlock";
1013
import { Separator } from "../components/ui/Separator";
1114
import { cn } from "../utils";
1215
import { ChainSwitch } from "./ChainSwitch";
1316
import { ConnectButton } from "./ConnectButton";
17+
import { CopyButton } from "./CopyButton";
18+
import { TruncatedHex } from "./ui/TruncatedHex";
1419

1520
function NavigationLink({ href, children }: { href: string; children: React.ReactNode }) {
1621
const pathname = usePathname();
@@ -32,6 +37,28 @@ function NavigationLink({ href, children }: { href: string; children: React.Reac
3237
);
3338
}
3439

40+
function WorldTitle() {
41+
const chain = useChain();
42+
const { worldAddress } = useParams<{ worldAddress: Address }>();
43+
const { data: verifiedWorlds } = useVerifiedWorldsQuery(chain);
44+
const verifiedWorld = verifiedWorlds?.get(worldAddress);
45+
46+
return (
47+
<div className="flex items-center gap-x-2 text-sm">
48+
<span className="mx-2 opacity-30">|</span>
49+
{verifiedWorld && (
50+
<span className="flex items-center gap-x-2 text-sm font-semibold">
51+
{verifiedWorld} <BadgeCheckIcon className="h-4 w-4 text-green-500" />
52+
</span>
53+
)}
54+
<span className="text-white/70">
55+
<TruncatedHex hex={worldAddress} />
56+
</span>
57+
<CopyButton value={worldAddress} />
58+
</div>
59+
);
60+
}
61+
3562
export function Navigation() {
3663
const isReadOnly = useReadOnly();
3764
const { data, isFetched } = useWorldAbiQuery();
@@ -44,6 +71,7 @@ export function Navigation() {
4471
{!isReadOnly && <NavigationLink href="interact">Interact</NavigationLink>}
4572
<NavigationLink href="observe">Observe</NavigationLink>
4673
<NavigationLink href="decode">Decode</NavigationLink>
74+
<WorldTitle />
4775
</div>
4876

4977
{isFetched && !data?.isWorldDeployed && (

0 commit comments

Comments
 (0)