-
Notifications
You must be signed in to change notification settings - Fork 577
Adding Metaplex Core support #431
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
Closed
blockiosaurus
wants to merge
14
commits into
solana-foundation:master
from
metaplex-foundation:feat/mpl-core
+995
−807
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8d57d2b
WIP for updated metaplex sdks.
blockiosaurus 4254dd9
Rolling to previous version.
blockiosaurus 044914e
Weirdly working
blockiosaurus a1567c7
Fixing and finishing off NFT update.
blockiosaurus e1ee281
Removing commented out code.
blockiosaurus 8524eec
Removing commented out code.
blockiosaurus ea4b932
minor fix.
blockiosaurus 401836b
Removing implicit any.
blockiosaurus f43ef38
WIP commit for basic MPL-Core support.
blockiosaurus e7fb07e
Updating routing to handle collections.
blockiosaurus 4246279
Adding tests.
blockiosaurus f2e8c09
Fixing nits.
blockiosaurus 940feb3
Merging in main.
blockiosaurus f453b93
Adding name arg.
blockiosaurus 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 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,54 @@ | ||
| 'use client'; | ||
|
|
||
| import { CoreMetadataCard } from '@components/account/CoreMetadataCard'; | ||
| import { ParsedAccountRenderer } from '@components/account/ParsedAccountRenderer'; | ||
| import { AssetV1, CollectionV1, deserializeAssetV1, deserializeCollectionV1, Key } from '@metaplex-foundation/mpl-core'; | ||
| import { lamports, RpcAccount } from '@metaplex-foundation/umi'; | ||
| import { fromWeb3JsPublicKey } from '@metaplex-foundation/umi-web3js-adapters'; | ||
| import React, { useEffect } from 'react'; | ||
|
|
||
| import { ErrorCard } from '@/app/components/common/ErrorCard'; | ||
|
|
||
| type Props = Readonly<{ | ||
| params: { | ||
| address: string; | ||
| }; | ||
| }>; | ||
|
|
||
| function CoreMetadataCardRenderer({ | ||
| account, | ||
| }: React.ComponentProps<React.ComponentProps<typeof ParsedAccountRenderer>['renderComponent']>) { | ||
| const [asset, setAsset] = React.useState<AssetV1 | CollectionV1 | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| if (!account) { | ||
| return; | ||
| } | ||
|
|
||
| const rpcAccount: RpcAccount = { | ||
| data: Uint8Array.from(account.data.raw || new Uint8Array()), | ||
| executable: account.executable, | ||
| lamports: lamports(account.lamports), | ||
| owner: fromWeb3JsPublicKey(account.owner), | ||
| publicKey: fromWeb3JsPublicKey(account.pubkey), | ||
| }; | ||
|
|
||
| if (rpcAccount.data[0] === Key.AssetV1) { | ||
| setAsset(deserializeAssetV1(rpcAccount)); | ||
| } else if (rpcAccount.data[0] === Key.CollectionV1) { | ||
| setAsset(deserializeCollectionV1(rpcAccount)); | ||
| } | ||
| }, [account]); | ||
|
|
||
| if (!account) { | ||
| return <ErrorCard text="Account is undefined" />; | ||
| } else if (!asset) { | ||
| return <ErrorCard text="Asset is undefined" />; | ||
| } else { | ||
| return <CoreMetadataCard asset={asset} />; | ||
| } | ||
| } | ||
|
|
||
| export default function MetaplexNFTMetadataPageClient({ params: { address } }: Props) { | ||
| return <ParsedAccountRenderer address={address} renderComponent={CoreMetadataCardRenderer} />; | ||
| } | ||
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,21 @@ | ||
| import getReadableTitleFromAddress, { AddressPageMetadataProps } from '@utils/get-readable-title-from-address'; | ||
| import { Metadata } from 'next/types'; | ||
|
|
||
| import CoreNFTMetadataPageClient from './page-client'; | ||
|
|
||
| type Props = Readonly<{ | ||
| params: { | ||
| address: string; | ||
| }; | ||
| }>; | ||
|
|
||
| export async function generateMetadata(props: AddressPageMetadataProps): Promise<Metadata> { | ||
| return { | ||
| description: `Metadata for the Core NFT with address ${props.params.address} on Solana`, | ||
| title: `Core NFT Metadata | ${await getReadableTitleFromAddress(props)} | Solana`, | ||
| }; | ||
| } | ||
|
|
||
| export default function CoreNFTMetadataPage(props: Props) { | ||
| return <CoreNFTMetadataPageClient {...props} />; | ||
| } |
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,24 @@ | ||
| import { AssetV1, CollectionV1 } from '@metaplex-foundation/mpl-core'; | ||
| import ReactJson from 'react-json-view'; | ||
|
|
||
| export function CoreMetadataCard({ asset }: { asset: AssetV1 | CollectionV1 | null }) { | ||
| // Here we grossly stringify and parse the metadata to avoid the bigints which ReactJsonView does not support. | ||
| const json = JSON.parse(JSON.stringify(asset, (_, v) => typeof v === 'bigint' ? v.toString() : v)); | ||
| return ( | ||
| <> | ||
| <div className="card"> | ||
| <div className="card-header"> | ||
| <div className="row align-items-center"> | ||
| <div className="col"> | ||
| <h3 className="card-header-title">Metaplex Core Metadata</h3> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="card metadata-json-viewer m-4"> | ||
| <ReactJson name={false} src={json} theme={'solarized'} style={{ padding: 25 }} /> | ||
| </div> | ||
| </div> | ||
| </> | ||
| ); | ||
| } |
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
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,33 @@ | ||
| import { Key } from '@metaplex-foundation/mpl-core'; | ||
| import * as Umi from '@metaplex-foundation/umi'; | ||
| import { fromWeb3JsPublicKey } from '@metaplex-foundation/umi-web3js-adapters'; | ||
| import { Account } from '@providers/accounts'; | ||
| import React, { useEffect } from 'react'; | ||
|
|
||
| import { ErrorCard } from '../../common/ErrorCard'; | ||
| import { CoreAssetHeader } from './CoreAssetHeader'; | ||
| import { CoreCollectionHeader } from './CoreCollectionHeader'; | ||
|
|
||
| export function CoreAccountHeader({ account }: { account: Account }) { | ||
| const [umiAccount, setUmiAccount] = React.useState<Umi.RpcAccount | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| const rpcAccount: Umi.RpcAccount = { | ||
| data: Uint8Array.from(account.data.raw || new Uint8Array()), | ||
| executable: account.executable, | ||
| lamports: Umi.lamports(account.lamports), | ||
| owner: fromWeb3JsPublicKey(account.owner), | ||
| publicKey: fromWeb3JsPublicKey(account.pubkey), | ||
| }; | ||
|
|
||
| setUmiAccount(rpcAccount); | ||
| }, [account]); | ||
|
|
||
| if (umiAccount && umiAccount.data[0] === Key.AssetV1) { | ||
| return <CoreAssetHeader account={account} /> | ||
| } else if (umiAccount && umiAccount.data[0] === Key.CollectionV1) { | ||
| return <CoreCollectionHeader account={account} /> | ||
| } else { | ||
| return <ErrorCard text="Invalid Core Account" /> | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.