Skip to content

Commit 498a26e

Browse files
committed
[Playground] Chain components (#5678)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR introduces new `Chain` components to enhance the user interface for blockchain applications, allowing for the display of chain icons and names. It includes new pages and components that integrate these features into the existing playground web application. ### Detailed summary - Added a new `Chain` entry in `navLinks.ts`. - Created a new page in `page.tsx` for `Chain` components with metadata. - Integrated `ThirdwebProvider`, `APIHeader`, `ChainIconBasic`, and `ChainNameBasic` components. - Implemented `ChainIconBasic` and `ChainNameBasic` components in `chain-examples.tsx` to showcase chain icons and names. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 8761fe6 commit 498a26e

File tree

5 files changed

+127
-2
lines changed

5 files changed

+127
-2
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { APIHeader } from "@/components/blocks/APIHeader";
2+
import {
3+
ChainIconBasic,
4+
ChainNameBasic,
5+
} from "@/components/headless-ui/chain-examples";
6+
import ThirdwebProvider from "@/components/thirdweb-provider";
7+
import { metadataBase } from "@/lib/constants";
8+
import type { Metadata } from "next";
9+
10+
export const metadata: Metadata = {
11+
metadataBase,
12+
title: "Chain Components",
13+
description:
14+
"Enhance your applications with our Chain components, featuring a collection of chain icons, names, and symbols. These customizable components simplify the integration of blockchain information, allowing developers to easily display and manage multiple chains in their user interfaces.",
15+
};
16+
17+
export default function Page() {
18+
return (
19+
<ThirdwebProvider>
20+
<main className="container px-0 pb-20">
21+
<APIHeader
22+
title="Chain Components"
23+
description={
24+
<>
25+
Enhance your applications with our Chain components, featuring a
26+
collection of chain icons, names, and symbols. These customizable
27+
components simplify the integration of blockchain information,
28+
allowing developers to easily display and manage multiple chains
29+
in their user interfaces.
30+
</>
31+
}
32+
docsLink="https://portal.thirdweb.com/react/v5/components/onchain#chains"
33+
heroLink="/headless-ui-header.png"
34+
/>
35+
<section className="space-y-8">
36+
<ChainIconBasic />
37+
</section>
38+
<section className="space-y-8">
39+
<ChainNameBasic />
40+
</section>
41+
</main>
42+
</ThirdwebProvider>
43+
);
44+
}

apps/playground-web/src/app/connect/ui/token/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { APIHeader } from "@/components/blocks/APIHeader";
2-
import {} from "@/components/headless-ui/nft-examples";
32
import {
43
TokenCard,
54
TokenImageBasic,

apps/playground-web/src/app/navLinks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ export const navLinks: SidebarLink[] = [
127127
name: "Token",
128128
href: "/connect/ui/token",
129129
},
130+
{
131+
name: "Chain",
132+
href: "/connect/ui/chain",
133+
},
130134
],
131135
},
132136
];
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"use client";
2+
3+
import { THIRDWEB_CLIENT } from "@/lib/client";
4+
import { avalanche } from "thirdweb/chains";
5+
import { ChainIcon, ChainName, ChainProvider } from "thirdweb/react";
6+
import { CodeExample } from "../code/code-example";
7+
8+
export function ChainIconBasic() {
9+
return (
10+
<>
11+
<div className="space-y-2">
12+
<h2 className="font-semibold text-2xl tracking-tight sm:text-3xl">
13+
ChainIcon
14+
</h2>
15+
<p className="max-w-[600px] text-lg">
16+
Show the native icon of a network
17+
</p>
18+
</div>
19+
20+
<CodeExample
21+
preview={
22+
<ChainProvider chain={avalanche}>
23+
<ChainIcon
24+
client={THIRDWEB_CLIENT}
25+
className="h-auto w-20 rounded-full"
26+
loadingComponent={<span>Loading...</span>}
27+
/>
28+
</ChainProvider>
29+
}
30+
code={`import { ChainProvider, ChainIcon } from "thirdweb/react";
31+
32+
function App() {
33+
return (
34+
<ChainProvider chain={avalanche}>
35+
<ChainIcon
36+
client={THIRDWEB_CLIENT}
37+
className="h-auto w-20 rounded-full"
38+
loadingComponent={<span>Loading...</span>}
39+
/>
40+
</ChainProvider>
41+
)
42+
}`}
43+
lang="tsx"
44+
/>
45+
</>
46+
);
47+
}
48+
49+
export function ChainNameBasic() {
50+
return (
51+
<>
52+
<div className="mt-8 space-y-2">
53+
<h2 className="font-semibold text-2xl tracking-tight sm:text-3xl">
54+
ChainName
55+
</h2>
56+
<p className="max-w-[600px] text-lg">Show the name of the chain</p>
57+
</div>
58+
59+
<CodeExample
60+
preview={
61+
<ChainProvider chain={avalanche}>
62+
<ChainName loadingComponent={<span>Loading...</span>} />
63+
</ChainProvider>
64+
}
65+
code={`import { ChainProvider, ChainName } from "thirdweb/react";
66+
67+
function App() {
68+
return (
69+
<ChainProvider chain={avalanche}>
70+
<ChainName loadingComponent={<span>Loading...</span>} />
71+
</ChainProvider>
72+
)
73+
}`}
74+
lang="tsx"
75+
/>
76+
</>
77+
);
78+
}

packages/thirdweb/src/react/web/ui/prebuilt/Chain/icon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export function ChainIcon({
143143
}
144144
// Check if the chain object already has "icon"
145145
if (chain.icon?.url) {
146-
return chain.icon.url;
146+
return resolveScheme({ uri: chain.icon.url, client });
147147
}
148148
const possibleUrl = await getChainMetadata(chain).then(
149149
(data) => data.icon?.url,

0 commit comments

Comments
 (0)