Skip to content

Commit

Permalink
fix: accountHeader name (#343)
Browse files Browse the repository at this point in the history
Uses the metadata pointer to get the token name and renders in the
AccountHeader

---------

Co-authored-by: pkxro <n/a>
  • Loading branch information
pkxro authored May 29, 2024
1 parent 261f5c8 commit d6800e5
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app/address/[address]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ import { PublicKey } from '@solana/web3.js';
import { Cluster, ClusterStatus } from '@utils/cluster';
import { FEATURE_PROGRAM_ID } from '@utils/parseFeatureAccount';
import { useClusterPath } from '@utils/url';
import { MetadataPointer, TokenMetadata } from '@validators/accounts/token-extension'
import Link from 'next/link';
import { redirect, useSelectedLayoutSegment } from 'next/navigation';
import React, { PropsWithChildren, Suspense } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import { create } from 'superstruct';
import useSWRImmutable from 'swr/immutable';
import { Base58EncodedAddress } from 'web3js-experimental';

Expand Down Expand Up @@ -269,11 +271,25 @@ function AccountHeader({
}

if (isToken && !isTokenInfoLoading) {
let token;
let token: { logoURI?: string; name?: string } = {};
let unverified = false;

const metadataExtension = mintInfo?.extensions?.find(({ extension }: { extension: string }) => extension === 'tokenMetadata');
const metadataPointerExtension = mintInfo?.extensions?.find(({ extension }: { extension: string }) => extension === 'metadataPointer');


if (metadataPointerExtension && metadataExtension) {
const tokenMetadata = create(metadataExtension.state, TokenMetadata);
const { metadataAddress } = create(metadataPointerExtension.state, MetadataPointer);

// Handles the basic case where MetadataPointer is reference the Token Metadata extension directly
// Does not handle the case where MetadataPointer is pointing at a separate account.
if (metadataAddress?.toString() === address) {
token.name = tokenMetadata.name
}
}
// Fall back to legacy token list when there is stub metadata (blank uri), updatable by default by the mint authority
if (!parsedData?.nftData?.metadata.data.uri && tokenInfo) {
else if (!parsedData?.nftData?.metadata.data.uri && tokenInfo) {
token = tokenInfo;
} else if (parsedData?.nftData) {
token = {
Expand Down

0 comments on commit d6800e5

Please sign in to comment.