-
Notifications
You must be signed in to change notification settings - Fork 306
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
fix: add logo support for PYUSD & USDP #347
Merged
ngundotra
merged 6 commits into
solana-labs:master
from
catalinred:pyusd-usdp-logo-support
Aug 28, 2024
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
03d7b2e
fix: add logo support for PYUSD & USDP
catalinred a75d9d4
Define proper interface
catalinred 12f447d
Format fix
catalinred 59d270f
Merge branch 'master' into pyusd-usdp-logo-support
catalinred 3d03869
Add basic error handling
catalinred a571683
refactor existing token headers
ngundotra 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
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 |
---|---|---|
|
@@ -257,6 +257,11 @@ function AccountHeader({ | |
tokenInfo?: FullTokenInfo; | ||
isTokenInfoLoading: boolean; | ||
}) { | ||
interface State { | ||
name: string; | ||
image: string; | ||
} | ||
const [tokenData, setTokenData] = React.useState<State>({ image: '', name: '' }); | ||
const mintInfo = useMintAccountInfo(address); | ||
|
||
const parsedData = account?.data.parsed; | ||
|
@@ -275,20 +280,32 @@ function AccountHeader({ | |
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'); | ||
|
||
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); | ||
|
||
(async () => { | ||
// Avoid re-renders once tokenData has been set | ||
if (!tokenData.name && !tokenData.image) { | ||
const response = await fetch(tokenMetadata.uri); | ||
setTokenData(await response.json()); | ||
} | ||
})(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of using the iife here i think a more canonical React hook would make sure the state works as expected:
|
||
|
||
// 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 | ||
token.name = tokenData?.name; | ||
token.logoURI = tokenData?.image; | ||
} | ||
} | ||
} | ||
// Fall back to legacy token list when there is stub metadata (blank uri), updatable by default by the mint authority | ||
else if (!parsedData?.nftData?.metadata.data.uri && tokenInfo) { | ||
token = tokenInfo; | ||
|
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.
@jnwng I tried to implement your code suggestion but unfortunately didn't succeed. It seems that
tokenMetadata
is available only within this conditional, which is why I added the IIFE function withinAccountHeader
.From my testing, I haven't noticed any inconsistencies with the state, but please let me know if you observe otherwise.
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.
hmm okay, gotcha. i think this is okay for now
can you do some validation on the response / some error handling?
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.
@jnwng I just added a basic error handling block.