forked from solana-foundation/explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/page title token name (solana-foundation#249)
For the title metadata generation, Next.js doesn't allow using client-side hooks on server-side components (see [this issue](vercel/next.js#46372)). Thus, we can't use `useTokenRegistry` as it's marked with 'use client' for frontend. When users visit each address page with the token name title, both the client-side and server-side rendering fetches the token list. These identical fetches are optimized by Next.js via [automatic fetch request deduping](https://nextjs.org/docs/app/building-your-application/data-fetching#automatic-fetch-request-deduping). > It's very important not to create two URLs with the same page title. Consider the case where two tokens have identical names; how would you prevent their URLs from rendering the same title? 1. We could append a small slice of address to the token name, e.g. USD Coin (EPjFW), but this wouldn't prevent same token names with the same "small slice" (using vanity address). 2. Another method could be just highlighting the official tokens, e.g. USD Coin (official), and leaving the other non-official tokens as-is, but this requires an active management of "official" tokens. Fixes solana-foundation#243. --------- Co-authored-by: steveluscher <[email protected]>
- Loading branch information
1 parent
15eff2f
commit a12cbc1
Showing
19 changed files
with
125 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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,46 @@ | ||
import { Strategy } from '@solana/spl-token-registry'; | ||
import { Cluster } from '@utils/cluster'; | ||
import getTokenList from '@utils/get-token-list'; | ||
|
||
export type AddressPageMetadataProps = Readonly<{ | ||
params: { | ||
address: string; | ||
}; | ||
searchParams: { | ||
cluster: string; | ||
}; | ||
}>; | ||
|
||
export default async function getReadableTitleFromAddress(props: AddressPageMetadataProps): Promise<string> { | ||
const { | ||
params: { address }, | ||
searchParams: { cluster: clusterParam }, | ||
} = props; | ||
|
||
let cluster: Cluster; | ||
switch (clusterParam) { | ||
case 'custom': | ||
cluster = Cluster.Custom; | ||
break; | ||
case 'devnet': | ||
cluster = Cluster.Devnet; | ||
break; | ||
case 'testnet': | ||
cluster = Cluster.Testnet; | ||
break; | ||
default: | ||
cluster = Cluster.MainnetBeta; | ||
} | ||
|
||
try { | ||
const tokenList = await getTokenList(cluster, Strategy.Solana); | ||
const tokenName = tokenList.get(address)?.name; | ||
if (tokenName == null) { | ||
return address; | ||
} | ||
const tokenDisplayAddress = address.slice(0, 2) + '\u2026' + address.slice(-2); | ||
return `Token | ${tokenName} (${tokenDisplayAddress})`; | ||
} catch { | ||
return address; | ||
} | ||
} |
Oops, something went wrong.