-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
963 additions
and
13 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
26 changes: 26 additions & 0 deletions
26
app/address/[address]/nifty-asset-extensions/page-client.tsx
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,26 @@ | ||
'use client'; | ||
|
||
import { NiftyAssetExtensionsCard } from '@/app/components/account/nifty-asset/AssetExtensionsCard'; | ||
import { ParsedAccountRenderer } from '@components/account/ParsedAccountRenderer'; | ||
import { Asset, getAssetAccountDataSerializer } from '@nifty-oss/asset'; | ||
import React from 'react'; | ||
|
||
type Props = Readonly<{ | ||
params: { | ||
address: string; | ||
}; | ||
}>; | ||
|
||
function NiftyAssetExtensionsCardRenderer({ | ||
account, | ||
onNotFound, | ||
}: React.ComponentProps<React.ComponentProps<typeof ParsedAccountRenderer>['renderComponent']>) { | ||
const data = account?.data.raw; | ||
const asset = data && (getAssetAccountDataSerializer().deserialize(data)[0] as Asset); | ||
|
||
return asset && asset.extensions.length > 0 ? <NiftyAssetExtensionsCard asset={asset} /> : onNotFound(); | ||
} | ||
|
||
export default function MetaplexNFTMetadataPageClient({ params: { address } }: Props) { | ||
return <ParsedAccountRenderer address={address} renderComponent={NiftyAssetExtensionsCardRenderer} />; | ||
} |
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,21 @@ | ||
import getReadableTitleFromAddress, { AddressPageMetadataProps } from '@utils/get-readable-title-from-address'; | ||
import { Metadata } from 'next/types'; | ||
|
||
import NiftyAssetExtensionsPageClient from './page-client'; | ||
|
||
type Props = Readonly<{ | ||
params: { | ||
address: string; | ||
}; | ||
}>; | ||
|
||
export async function generateMetadata(props: AddressPageMetadataProps): Promise<Metadata> { | ||
return { | ||
description: `Extensions for the asset with address ${props.params.address} on Solana`, | ||
title: `Asset Extensions | ${await getReadableTitleFromAddress(props)} | Solana`, | ||
}; | ||
} | ||
|
||
export default function MetaplexNFTMetadataPage(props: Props) { | ||
return <NiftyAssetExtensionsPageClient {...props} />; | ||
} |
34 changes: 34 additions & 0 deletions
34
app/address/[address]/nifty-asset-metadata/page-client.tsx
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,34 @@ | ||
'use client'; | ||
|
||
import { NiftyAssetMetadataCard } from '@/app/components/account/nifty-asset/AssetMetadataCard'; | ||
import { ParsedAccountRenderer } from '@components/account/ParsedAccountRenderer'; | ||
import { Asset, ExtensionType, getAssetAccountDataSerializer, getExtension } from '@nifty-oss/asset'; | ||
import React from 'react'; | ||
|
||
type Props = Readonly<{ | ||
params: { | ||
address: string; | ||
}; | ||
}>; | ||
|
||
function NiftyAssetMetadataCardRenderer({ | ||
account, | ||
onNotFound, | ||
}: React.ComponentProps<React.ComponentProps<typeof ParsedAccountRenderer>['renderComponent']>) { | ||
const data = account?.data.raw; | ||
const asset = data && getAssetAccountDataSerializer().deserialize(data); | ||
|
||
if (asset) { | ||
const metadata = asset && getExtension(asset[0] as Asset, ExtensionType.Metadata); | ||
|
||
if (metadata && metadata.uri) { | ||
return <NiftyAssetMetadataCard asset={asset[0] as Asset} />; | ||
} | ||
} | ||
|
||
return onNotFound(); | ||
} | ||
|
||
export default function MetaplexNFTMetadataPageClient({ params: { address } }: Props) { | ||
return <ParsedAccountRenderer address={address} renderComponent={NiftyAssetMetadataCardRenderer} />; | ||
} |
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,21 @@ | ||
import getReadableTitleFromAddress, { AddressPageMetadataProps } from '@utils/get-readable-title-from-address'; | ||
import { Metadata } from 'next/types'; | ||
|
||
import NiftyAssetMetadataPageClient from './page-client'; | ||
|
||
type Props = Readonly<{ | ||
params: { | ||
address: string; | ||
}; | ||
}>; | ||
|
||
export async function generateMetadata(props: AddressPageMetadataProps): Promise<Metadata> { | ||
return { | ||
description: `Metadata for the asset with address ${props.params.address} on Solana`, | ||
title: `Asset Metadata | ${await getReadableTitleFromAddress(props)} | Solana`, | ||
}; | ||
} | ||
|
||
export default function MetaplexNFTMetadataPage(props: Props) { | ||
return <NiftyAssetMetadataPageClient {...props} />; | ||
} |
111 changes: 111 additions & 0 deletions
111
app/components/account/nifty-asset/AssetAccountCard.tsx
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,111 @@ | ||
import { Address } from '@components/common/Address'; | ||
import { SolBalance } from '@components/common/SolBalance'; | ||
import { TableCardBody } from '@components/common/TableCardBody'; | ||
import { toWeb3JsPublicKey } from '@metaplex-foundation/umi-web3js-adapters'; | ||
import { Asset, State, getAssetAccountDataSerializer } from '@nifty-oss/asset'; | ||
import { Account } from '@providers/accounts'; | ||
import { useCluster } from '@providers/cluster'; | ||
import { addressLabel } from '@utils/tx'; | ||
|
||
export function NiftyAssetAccountCard({ account }: { account: Account }) { | ||
const { cluster } = useCluster(); | ||
|
||
const label = addressLabel(account.pubkey.toBase58(), cluster); | ||
const data = account.data.raw; | ||
const asset = data && (getAssetAccountDataSerializer().deserialize(data)[0] as Asset); | ||
|
||
return ( | ||
<div className="card"> | ||
<div className="card-header align-items-center"> | ||
<h3 className="card-header-title">Overview</h3> | ||
</div> | ||
|
||
<TableCardBody> | ||
<tr> | ||
<td>Address</td> | ||
<td className="text-lg-end"> | ||
<Address pubkey={account.pubkey} alignRight raw /> | ||
</td> | ||
</tr> | ||
{label && ( | ||
<tr> | ||
<td>Address Label</td> | ||
<td className="text-lg-end">{label}</td> | ||
</tr> | ||
)} | ||
<tr> | ||
<td>Balance (SOL)</td> | ||
<td className="text-lg-end"> | ||
{account.lamports === 0 ? 'Account does not exist' : <SolBalance lamports={account.lamports} />} | ||
</td> | ||
</tr> | ||
|
||
{account.space !== undefined && ( | ||
<tr> | ||
<td>Allocated Data Size</td> | ||
<td className="text-lg-end">{account.space} byte(s)</td> | ||
</tr> | ||
)} | ||
|
||
{asset && ( | ||
<tr> | ||
<td>Authority</td> | ||
<td className="text-lg-end"> | ||
<Address pubkey={toWeb3JsPublicKey(asset.authority)} alignRight link /> | ||
</td> | ||
</tr> | ||
)} | ||
|
||
{asset && ( | ||
<tr> | ||
<td>Owner</td> | ||
<td className="text-lg-end"> | ||
<Address pubkey={toWeb3JsPublicKey(asset.owner)} alignRight link /> | ||
</td> | ||
</tr> | ||
)} | ||
|
||
{asset && ( | ||
<tr> | ||
<td>Group</td> | ||
<td className="text-lg-end"> | ||
{asset.group ? ( | ||
<Address pubkey={toWeb3JsPublicKey(asset.group)} alignRight link /> | ||
) : ( | ||
<div className="text-muted">None</div> | ||
)} | ||
</td> | ||
</tr> | ||
)} | ||
|
||
{asset && ( | ||
<tr> | ||
<td>Delegate</td> | ||
<td className="text-lg-end"> | ||
{asset.delegate ? ( | ||
<Address pubkey={toWeb3JsPublicKey(asset.delegate.address)} alignRight link /> | ||
) : ( | ||
<div className="text-muted">None</div> | ||
)} | ||
</td> | ||
</tr> | ||
)} | ||
|
||
{asset && ( | ||
<tr> | ||
<td>State</td> | ||
<td className="text-lg-end"> | ||
<h3 className="mb-0"> | ||
{asset.state === State.Unlocked ? ( | ||
<span className="badge badge-pill bg-info-soft">Unlocked</span> | ||
) : ( | ||
<span className="badge badge-pill bg-danger-soft">Locked</span> | ||
)} | ||
</h3> | ||
</td> | ||
</tr> | ||
)} | ||
</TableCardBody> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.