-
Notifications
You must be signed in to change notification settings - Fork 544
[Playground] Add Token components, fix links #5677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { APIHeader } from "@/components/blocks/APIHeader"; | ||
import {} from "@/components/headless-ui/nft-examples"; | ||
import { | ||
TokenCard, | ||
TokenImageBasic, | ||
TokenImageOverride, | ||
TokenNameBasic, | ||
TokenSymbolBasic, | ||
} from "@/components/headless-ui/token-examples"; | ||
import ThirdwebProvider from "@/components/thirdweb-provider"; | ||
import { metadataBase } from "@/lib/constants"; | ||
import type { Metadata } from "next"; | ||
|
||
export const metadata: Metadata = { | ||
metadataBase, | ||
title: "Token Components", | ||
description: | ||
"Elevate your ERC20 and native crypto token applications with our React headless UI components, designed for efficient digital currency transactions. These customizable, zero-styling components simplify token interactions, giving developers the flexibility to create their ideal user interface for DeFi platforms, wallets, and other crypto applications.", | ||
}; | ||
|
||
export default function Page() { | ||
return ( | ||
<ThirdwebProvider> | ||
<main className="container px-0 pb-20"> | ||
<APIHeader | ||
title="Token Components" | ||
description={ | ||
<> | ||
Elevate your ERC20 and native crypto token applications with our | ||
React headless UI components, designed for efficient digital | ||
currency transactions. These customizable, zero-styling components | ||
simplify token interactions, giving developers the flexibility to | ||
create their ideal user interface for DeFi platforms, wallets, and | ||
other crypto applications. | ||
</> | ||
} | ||
docsLink="https://portal.thirdweb.com/react/v5/components/onchain#tokens" | ||
heroLink="/headless-ui-header.png" | ||
/> | ||
<section className="space-y-8"> | ||
<TokenImageBasic /> | ||
</section> | ||
<section className="space-y-8"> | ||
<TokenImageOverride /> | ||
</section> | ||
<section className="space-y-8"> | ||
<TokenNameBasic /> | ||
</section> | ||
<section className="space-y-8"> | ||
<TokenSymbolBasic /> | ||
</section> | ||
<section className="space-y-8"> | ||
<TokenCard /> | ||
</section> | ||
</main> | ||
</ThirdwebProvider> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
245 changes: 245 additions & 0 deletions
245
apps/playground-web/src/components/headless-ui/token-examples.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
"use client"; | ||
|
||
import { THIRDWEB_CLIENT } from "@/lib/client"; | ||
import { NATIVE_TOKEN_ADDRESS } from "thirdweb"; | ||
import { ethereum } from "thirdweb/chains"; | ||
import { | ||
TokenIcon, | ||
TokenName, | ||
TokenProvider, | ||
TokenSymbol, | ||
} from "thirdweb/react"; | ||
import { CodeExample } from "../code/code-example"; | ||
|
||
const USDC_ADDRESS = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"; | ||
|
||
export function TokenImageBasic() { | ||
return ( | ||
<> | ||
<div className="space-y-2"> | ||
<h2 className="font-semibold text-2xl tracking-tight sm:text-3xl"> | ||
TokenIcon | ||
</h2> | ||
<p className="max-w-[600px] text-lg"> | ||
Show the default native icon of a network | ||
</p> | ||
</div> | ||
|
||
<CodeExample | ||
preview={ | ||
<TokenProvider | ||
address={NATIVE_TOKEN_ADDRESS} | ||
client={THIRDWEB_CLIENT} | ||
chain={ethereum} | ||
> | ||
<TokenIcon className="h-auto w-20 rounded-full" /> | ||
</TokenProvider> | ||
} | ||
code={`import { TokenProvider, TokenIcon } from "thirdweb/react"; | ||
|
||
function App() { | ||
return ( | ||
<TokenProvider | ||
address={NATIVE_TOKEN_ADDRESS} | ||
client={THIRDWEB_CLIENT} | ||
chain={ethereum} | ||
> | ||
<TokenIcon className="h-auto w-20 rounded-full" /> | ||
</TokenProvider> | ||
) | ||
}`} | ||
lang="tsx" | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export function TokenImageOverride() { | ||
return ( | ||
<> | ||
<div className="mt-8 space-y-2"> | ||
<h4 className="font-semibold text-lg"> | ||
Override the token's icon using the <b>iconResolver</b> prop. | ||
</h4> | ||
<p className="max-w-[600px] text-lg"> | ||
There is no official way to query the icon of a token. If you have a | ||
source, you can pass it to the iconResolver prop. | ||
</p> | ||
</div> | ||
|
||
<CodeExample | ||
preview={ | ||
<TokenProvider | ||
address={USDC_ADDRESS} | ||
client={THIRDWEB_CLIENT} | ||
chain={ethereum} | ||
> | ||
<TokenIcon | ||
className="h-auto w-20 rounded-full" | ||
iconResolver="/usdc.svg" | ||
/> | ||
</TokenProvider> | ||
} | ||
code={`import { TokenProvider, TokenIcon } from "thirdweb/react"; | ||
|
||
function App() { | ||
const USDC_ADDRESS = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"; | ||
return ( | ||
<TokenProvider | ||
address={USDC_ADDRESS} | ||
client={THIRDWEB_CLIENT} | ||
chain={ethereum} | ||
> | ||
<TokenIcon | ||
className="h-auto w-20 rounded-full" | ||
iconResolver="/usdc.svg" | ||
/> | ||
</TokenProvider> | ||
) | ||
}`} | ||
lang="tsx" | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export function TokenNameBasic() { | ||
return ( | ||
<> | ||
<div className="mt-8 space-y-2"> | ||
<h2 className="font-semibold text-2xl tracking-tight sm:text-3xl"> | ||
TokenName | ||
</h2> | ||
<p className="max-w-[600px] text-lg">Show the name of the token</p> | ||
</div> | ||
|
||
<CodeExample | ||
preview={ | ||
<TokenProvider | ||
address={USDC_ADDRESS} | ||
client={THIRDWEB_CLIENT} | ||
chain={ethereum} | ||
> | ||
<TokenName loadingComponent={<span>Loading...</span>} /> | ||
</TokenProvider> | ||
} | ||
code={`import { TokenProvider, TokenName } from "thirdweb/react"; | ||
|
||
function App() { | ||
return ( | ||
<TokenProvider | ||
address={USDC_ADDRESS} | ||
client={THIRDWEB_CLIENT} | ||
chain={ethereum} | ||
> | ||
<TokenName loadingComponent={<span>Loading...</span>} /> | ||
</TokenProvider> | ||
) | ||
}`} | ||
lang="tsx" | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export function TokenSymbolBasic() { | ||
return ( | ||
<> | ||
<div className="mt-8 space-y-2"> | ||
<h2 className="font-semibold text-2xl tracking-tight sm:text-3xl"> | ||
TokenSymbol | ||
</h2> | ||
<p className="max-w-[600px] text-lg">Show the symbol of the token</p> | ||
</div> | ||
|
||
<CodeExample | ||
preview={ | ||
<TokenProvider | ||
address={USDC_ADDRESS} | ||
client={THIRDWEB_CLIENT} | ||
chain={ethereum} | ||
> | ||
<TokenSymbol loadingComponent={<span>Loading...</span>} /> | ||
</TokenProvider> | ||
} | ||
code={`import { TokenProvider, TokenSymbol } from "thirdweb/react"; | ||
|
||
function App() { | ||
return ( | ||
<TokenProvider | ||
address={USDC_ADDRESS} | ||
client={THIRDWEB_CLIENT} | ||
chain={ethereum} | ||
> | ||
<TokenSymbol loadingComponent={<span>Loading...</span>} /> | ||
</TokenProvider> | ||
) | ||
}`} | ||
lang="tsx" | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export function TokenCard() { | ||
return ( | ||
<> | ||
<div className="mt-8 space-y-2"> | ||
<h2 className="font-semibold text-2xl tracking-tight sm:text-3xl"> | ||
Build a token card | ||
</h2> | ||
<p className="max-w-[600px] text-lg"> | ||
You can build a Token card by putting the Token components together | ||
</p> | ||
</div> | ||
|
||
<CodeExample | ||
preview={ | ||
<TokenProvider | ||
address={USDC_ADDRESS} | ||
client={THIRDWEB_CLIENT} | ||
chain={ethereum} | ||
> | ||
<div className="flex flex-row items-center gap-2 rounded-lg border bg-slate-950 px-4 py-1"> | ||
<TokenIcon className="h-10 w-10" iconResolver="/usdc.svg" /> | ||
<div className="flex flex-col"> | ||
<TokenName | ||
className="font-bold" | ||
loadingComponent={<span>Loading...</span>} | ||
/> | ||
<TokenSymbol | ||
className="text-gray-500" | ||
loadingComponent={<span>Loading...</span>} | ||
/> | ||
</div> | ||
</div> | ||
</TokenProvider> | ||
} | ||
code={`import { TokenProvider, TokenSymbol } from "thirdweb/react"; | ||
|
||
function App() { | ||
return ( | ||
<TokenProvider | ||
address={USDC_ADDRESS} | ||
client={THIRDWEB_CLIENT} | ||
chain={ethereum} | ||
> | ||
<div className="flex flex-row items-center gap-2 rounded-lg border bg-slate-950 px-4 py-1"> | ||
<TokenIcon className="h-10 w-10" iconResolver="/usdc.svg" /> | ||
<div className="flex flex-col"> | ||
<TokenName | ||
className="font-bold" | ||
/> | ||
<TokenSymbol | ||
className="text-gray-500" | ||
/> | ||
</div> | ||
</div> | ||
</TokenProvider> | ||
) | ||
}`} | ||
lang="tsx" | ||
/> | ||
</> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the only way? what happens if i pass nothing?
i think we have all these icons in the pay service, could we just fetch those from there for tokens we know about?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I did not know we have the icons over there. I will check an update it in a follow up PR.
About your question, if you don't pass the resolver for token erc20 the component will fail to render the image
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://thirdwebdev.slack.com/archives/C04LA5X7FNE/p1733916180045149