Skip to content

Commit

Permalink
feat: update get metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobcreech committed Jun 17, 2022
1 parent 14158a0 commit a2e803f
Showing 1 changed file with 53 additions and 53 deletions.
106 changes: 53 additions & 53 deletions src/components/GetMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { FC, useState, useCallback } from 'react';
import { useConnection } from '@solana/wallet-adapter-react';
import { PublicKey } from '@solana/web3.js';
import { Metadata } from '@metaplex-foundation/mpl-token-metadata';
import { findMetadataPda } from '@metaplex-foundation/js';


export const GetMetadata: FC = () => {
const { connection } = useConnection();
Expand All @@ -13,9 +15,13 @@ export const GetMetadata: FC = () => {
const getMetadata = useCallback(
async (form) => {
const tokenMint = form.tokenAddress;
const metadataPDA = await Metadata.getPDA(new PublicKey(tokenMint));
const metadata = await Metadata.load(connection, metadataPDA);
let logoRes = await fetch(metadata.data.data.uri);
const metadataPDA = await findMetadataPda(new PublicKey(tokenMint));
console.log(metadataPDA.toBase58());
const metadataAccount = await connection.getAccountInfo(metadataPDA);
console.log(metadataAccount);
const [metadata, _] = await Metadata.deserialize(metadataAccount.data);
console.log(metadata);
let logoRes = await fetch(metadata.data.uri);
let logoJson = await logoRes.json();
let { image } = logoJson;
setTokenMetadata({ tokenMetadata, ...metadata.data });
Expand Down Expand Up @@ -44,57 +50,51 @@ export const GetMetadata: FC = () => {
</div>
<div className='my-6'>
{!loaded ? undefined : (
<>
{tokenMetadata.tokenStandard === 1 ? (
<div className='bg-white shadow overflow-hidden sm:rounded-lg'>
<div className='px-4 py-5 sm:px-6'>
<h3 className='text-lg leading-6 font-medium text-gray-900'>
Token Metadata
</h3>
</div>
<div className='border-t border-gray-200'>
<dl className='divide-y divide-gray-200'>
<>
<div className='bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6'>
<dt className='text-sm font-medium text-gray-500'>
logo
</dt>
<dd className='mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2'>
<img src={logo} alt='token' className='w-1/4 h-full inline-block object-center object-cover lg:w-1/4 lg:h-full'/>
</dd>
</div>
<div className='bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6'>
<dt className='text-sm font-medium text-gray-500'>
name
</dt>
<dd className='mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2'>
{tokenMetadata.data.name}
</dd>
</div>
<div className='bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6'>
<dt className='text-sm font-medium text-gray-500'>
symbol
</dt>
<dd className='mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2'>
{tokenMetadata.data.symbol || 'undefined'}
</dd>
</div>
<div className='bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6'>
<dt className='text-sm font-medium text-gray-500'>
uri
</dt>
<dd className='mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2'>
<a href={tokenMetadata.data.uri} target='_blank'>{tokenMetadata.data.uri}</a>
</dd>
</div>
</>
</dl>
</div>
<div className='bg-white shadow overflow-hidden sm:rounded-lg'>
<div className='px-4 py-5 sm:px-6'>
<h3 className='text-lg leading-6 font-medium text-gray-900'>
Token Metadata
</h3>
</div>
<div className='border-t border-gray-200'>
<dl className='divide-y divide-gray-200'>
<>
<div className='bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6'>
<dt className='text-sm font-medium text-gray-500'>
logo
</dt>
<dd className='mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2'>
<img src={logo} alt='token' className='w-1/4 h-full inline-block object-center object-cover lg:w-1/4 lg:h-full'/>
</dd>
</div>
<div className='bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6'>
<dt className='text-sm font-medium text-gray-500'>
name
</dt>
<dd className='mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2'>
{tokenMetadata.name}
</dd>
</div>
<div className='bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6'>
<dt className='text-sm font-medium text-gray-500'>
symbol
</dt>
<dd className='mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2'>
{tokenMetadata.symbol || 'undefined'}
</dd>
</div>
<div className='bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6'>
<dt className='text-sm font-medium text-gray-500'>
uri
</dt>
<dd className='mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2'>
<a href={tokenMetadata.uri} target='_blank'>{tokenMetadata.uri}</a>
</dd>
</div>
</>
</dl>
</div>
) : (
<p className='mt-1 text-sm text-white'>Nothing to display.</p>
)}
</>
</div>
)}
</div>
</>
Expand Down

1 comment on commit a2e803f

@vercel
Copy link

@vercel vercel bot commented on a2e803f Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.