-
Notifications
You must be signed in to change notification settings - Fork 306
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
7 changed files
with
290 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use client'; | ||
|
||
import { ParsedAccountRenderer } from '@components/account/ParsedAccountRenderer'; | ||
import React, { Suspense } from 'react'; | ||
|
||
import { CompressedNFTInfoCard } from '@/app/components/account/CompressedNFTInfoCard'; | ||
import { LoadingCard } from '@/app/components/common/LoadingCard'; | ||
|
||
type Props = Readonly<{ | ||
params: { | ||
address: string; | ||
}; | ||
}>; | ||
|
||
function CompressionCardRenderer({ | ||
account, | ||
onNotFound, | ||
}: React.ComponentProps<React.ComponentProps<typeof ParsedAccountRenderer>['renderComponent']>) { | ||
return ( | ||
<Suspense fallback={<LoadingCard />}> | ||
{<CompressedNFTInfoCard account={account} onNotFound={onNotFound} />} | ||
</Suspense> | ||
); | ||
} | ||
|
||
export default function CompressionPageClient({ params: { address } }: Props) { | ||
return <ParsedAccountRenderer address={address} renderComponent={CompressionCardRenderer} />; | ||
} |
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 CompressionPageClient from './page-client'; | ||
|
||
type Props = Readonly<{ | ||
params: { | ||
address: string; | ||
}; | ||
}>; | ||
|
||
export async function generateMetadata(props: AddressPageMetadataProps): Promise<Metadata> { | ||
return { | ||
description: `Information about the Compressed NFT with address ${props.params.address} on Solana`, | ||
title: `Compression Information | ${await getReadableTitleFromAddress(props)} | Solana`, | ||
}; | ||
} | ||
|
||
export default function CompressionPage(props: Props) { | ||
return <CompressionPageClient {...props} />; | ||
} |
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
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,131 @@ | ||
import { Account, useAccountInfo, useFetchAccountInfo } from '@providers/accounts'; | ||
import { ConcurrentMerkleTreeAccount, MerkleTree } from '@solana/spl-account-compression'; | ||
import { PublicKey } from '@solana/web3.js'; | ||
import React from 'react'; | ||
|
||
import { useCluster } from '@/app/providers/cluster'; | ||
import { | ||
CompressedNft, | ||
CompressedNftProof, | ||
useCompressedNft, | ||
useCompressedNftProof, | ||
} from '@/app/providers/compressed-nft'; | ||
|
||
import { Address } from '../common/Address'; | ||
import { TableCardBody } from '../common/TableCardBody'; | ||
|
||
export function CompressedNFTInfoCard({ account, onNotFound }: { account?: Account; onNotFound: () => never }) { | ||
const { url } = useCluster(); | ||
const compressedNft = useCompressedNft({ address: account?.pubkey.toString() ?? '', url }); | ||
const proof = useCompressedNftProof({ address: account?.pubkey.toString() ?? '', url }); | ||
|
||
if (compressedNft && compressedNft.compression.compressed && proof) { | ||
return <DasCompressionInfoCard proof={proof} compressedNft={compressedNft} />; | ||
} | ||
return onNotFound(); | ||
} | ||
|
||
function DasCompressionInfoCard({ proof, compressedNft }: { proof: CompressedNftProof; compressedNft: CompressedNft }) { | ||
const compressedInfo = compressedNft.compression; | ||
const fetchAccountInfo = useFetchAccountInfo(); | ||
const treeAccountInfo = useAccountInfo(compressedInfo.tree); | ||
const treeAddress = new PublicKey(compressedInfo.tree); | ||
|
||
React.useEffect(() => { | ||
fetchAccountInfo(treeAddress, 'raw'); | ||
}, [compressedInfo.tree]); // eslint-disable-line react-hooks/exhaustive-deps | ||
|
||
const root = new PublicKey(proof.root); | ||
const proofVerified = MerkleTree.verify(root.toBuffer(), { | ||
leaf: new PublicKey(compressedNft.compression.asset_hash).toBuffer(), | ||
leafIndex: compressedNft.compression.leaf_id, | ||
proof: proof.proof.map(proofData => new PublicKey(proofData).toBuffer()), | ||
root: root.toBuffer(), | ||
}); | ||
const canopyDepth = | ||
treeAccountInfo && treeAccountInfo.data && treeAccountInfo.data.data.raw | ||
? ConcurrentMerkleTreeAccount.fromBuffer(treeAccountInfo.data.data.raw).getCanopyDepth() | ||
: 0; | ||
const proofSize = proof.proof.length - canopyDepth; | ||
return ( | ||
<div className="card"> | ||
<div className="card-header align-items-center"> | ||
<h3 className="card-header-title">Compression Info</h3> | ||
</div> | ||
|
||
<TableCardBody> | ||
<tr> | ||
<td>Concurrent Merkle Tree</td> | ||
<td> | ||
<Address pubkey={treeAddress} alignRight link raw /> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>Current Tree Root {getVerifiedProofPill(proofVerified)}</td> | ||
<td> | ||
<Address pubkey={root} alignRight raw /> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>Proof Size {getProofSizePill(proofSize)}</td> | ||
<td className="text-lg-end">{proofSize}</td> | ||
</tr> | ||
<tr> | ||
<td>Leaf Number</td> | ||
<td className="text-lg-end">{compressedInfo.leaf_id}</td> | ||
</tr> | ||
<tr> | ||
<td>Sequence Number of Last Update</td> | ||
<td className="text-lg-end">{compressedInfo.seq}</td> | ||
</tr> | ||
<tr> | ||
<td>Compressed Nft Hash</td> | ||
<td> | ||
<Address pubkey={new PublicKey(compressedInfo.asset_hash)} alignRight raw /> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>Creators Hash</td> | ||
<td> | ||
<Address pubkey={new PublicKey(compressedInfo.creator_hash)} alignRight raw /> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>Metadata Hash</td> | ||
<td> | ||
<Address pubkey={new PublicKey(compressedInfo.data_hash)} alignRight raw /> | ||
</td> | ||
</tr> | ||
</TableCardBody> | ||
</div> | ||
); | ||
} | ||
|
||
function getVerifiedProofPill(verified: boolean) { | ||
return ( | ||
<div className={'d-inline-flex align-items-center ms-2'}> | ||
<span className={`badge badge-pill bg-dark ${verified ? '' : 'bg-danger-soft'}`}>{`Proof ${ | ||
verified ? '' : 'Not' | ||
} Verified`}</span> | ||
</div> | ||
); | ||
} | ||
|
||
function getProofSizePill(proofSize: number) { | ||
let text: string; | ||
let color = 'bg-dark'; | ||
if (proofSize == 0) { | ||
text = 'No Proof Required'; | ||
} else if (proofSize > 8) { | ||
text = `Composability Hazard`; | ||
color = 'bg-danger-soft'; | ||
} else { | ||
return <div />; | ||
} | ||
|
||
return ( | ||
<div className={'d-inline-flex align-items-center ms-2'}> | ||
<span className={`badge badge-pill ${color}`}>{text}</span> | ||
</div> | ||
); | ||
} |
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
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
Oops, something went wrong.