ef28667d13
* feat: add token and nft injection * feat: basic tests * fix: get jest configured properly * fix: change timeout * fix: uninstall port ready * fix: readd port ready * fix: local tests work * Update yarn.lock * add lint disable for setup files * fix: update dependencies * fix: basic test suite for nfts/tokens * feat: collection data * fix: make tests more comprehensive * fix: change matches to contains * fix: tests for twitter alt image tag * fix: image gen * fix: add patch-package * fix: update yarn install * feat: basic image gen for nfts and collections * fix: remove vibrant attempt * use watermark asset * dynamically grab color * modularize code and prototype for token preview * refactor code * finalize css * fix color grabber * update tests * fix up css * refactor code a bit more * remove console logs * tests * update tests * update images based on design feedback * network logos * update lint * slight refactoring * more refactoring * fix packages * Update yarn.lock * remove dynamically generated image stuff * cleanup return values * Create README.md * Revert "Create README.md" This reverts commit 7a91c98d384995fba914c9bf9a2fb3072793621f. * First round of feedback * comments * feedback round 2 * final feedback * final final feedback * nest twitter:image:alt in image check * better title handling --------- Co-authored-by: Zach Pomerantz <zzmp@uniswap.org>
39 lines
960 B
TypeScript
39 lines
960 B
TypeScript
import { AssetDocument } from '../../src/graphql/data/__generated__/types-and-hooks'
|
|
import client from '../client'
|
|
|
|
function formatTitleName(name: string, collectionName: string, tokenId: string) {
|
|
if (name) {
|
|
return name
|
|
}
|
|
if (collectionName && tokenId) {
|
|
return collectionName + ' #' + tokenId
|
|
}
|
|
if (tokenId) {
|
|
return 'Asset #' + tokenId
|
|
}
|
|
return 'View NFT on Uniswap'
|
|
}
|
|
|
|
export default async function getAsset(collectionAddress: string, tokenId: string, url: string) {
|
|
const { data } = await client.query({
|
|
query: AssetDocument,
|
|
variables: {
|
|
address: collectionAddress,
|
|
filter: {
|
|
tokenIds: [tokenId],
|
|
},
|
|
},
|
|
})
|
|
const asset = data?.nftAssets?.edges[0]?.node
|
|
if (!asset) {
|
|
return undefined
|
|
}
|
|
const title = formatTitleName(asset.name, asset.collection?.name, asset.tokenId)
|
|
const formattedAsset = {
|
|
title,
|
|
image: asset.image?.url,
|
|
url,
|
|
}
|
|
return formattedAsset
|
|
}
|