explorer icon indicating copy to clipboard operation
explorer copied to clipboard

Solana Explorer: Token display names vs addresses in detailed mode

Open amilz opened this issue 2 years ago • 1 comments

Problem

Solana Explorer Token Details tab loses known token names for some tokens (my hunch is those with newer Metaplex metadata post token registry). See example below:

https://user-images.githubusercontent.com/85324096/211457978-7d416ac5-4b3f-4772-849f-2dc7d2d4861d.mov

Expected Results: either mint token display name is displayed for all tokens in or the public key is show for all in detailed mode (not a mix of both).

Experienced: (see video) some tokens toggle to Public Key in detailed mode while others maintain their display name (eg, Samo). Link to example

Proposed Solution

My hunch is there's a state issue with the token registry and the newer metaplex metadata. Probably an easy fix. I'll try to do some research when I have more time.

amilz avatar Jan 10 '23 03:01 amilz

The <Address > component for mint is passed with parameters link and truncate at line 133: https://github.com/solana-labs/solana/blob/db0bff06686c9b1778fd99f2fa376aa72b99d749/explorer/src/components/account/OwnedTokensCard.tsx#L133

Here's where the addressLabel is defined: https://github.com/solana-labs/solana/blob/db0bff06686c9b1778fd99f2fa376aa72b99d749/explorer/src/components/common/Address.tsx#L46-59

  let addressLabel = raw
    ? address
    : displayAddress(address, cluster, tokenRegistry);

  var metaplexData = useTokenMetadata(useMetadata, address);
  if (metaplexData && metaplexData.data)
    addressLabel = metaplexData.data.data.name;
  if (truncateChars && addressLabel === address) {
    addressLabel = addressLabel.slice(0, truncateChars) + "…";
  }

  if (overrideText) {
    addressLabel = overrideText;
  }

Since raw is not called in <Address>, any token in the tokenRegisry will return their name. useMetaData, however, is not called, so newer tokens would not return their name.

Proposed Solution Update https://github.com/solana-labs/solana/blob/db0bff06686c9b1778fd99f2fa376aa72b99d749/explorer/src/components/account/OwnedTokensCard.tsx#L133 with

  • Option A: add raw : <Address pubkey={tokenAccount.info.mint} link truncate raw /> outcome: display only truncated addresses for all
  • Option B: add useMetadata : <Address pubkey={tokenAccount.info.mint} link truncate useMetadata /> outcome: display names for any with names (should match the basic view)

Personally, I prefer option B even in detail but I think there's a strong case for Option A. I'll try and give these a test later this week and can get a PR put together. LMK if you have an opinion!

amilz avatar Jan 10 '23 05:01 amilz