diff --git a/frontend/package.json b/frontend/package.json index 54e0924..c9c2175 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -3,6 +3,7 @@ "version": "1.0.0", "private": true, "devDependencies": { + "0xsequence": "^1.1.15", "@types/react": "^18.2.21", "@types/react-dom": "^18.2.7", "@walletconnect/client": "^1.8.0", diff --git a/frontend/src/chains.ts b/frontend/src/chains.ts index c0f3fc1..db37a33 100644 --- a/frontend/src/chains.ts +++ b/frontend/src/chains.ts @@ -1,3 +1,4 @@ +import { SequenceIndexerServices } from "@0xsequence/indexer" import { mainnet, goerli, @@ -23,3 +24,11 @@ export const CHAINS = { export type ChainId = keyof typeof CHAINS export const DEFAULT_CHAIN = CHAINS[5] + +export const SEQUENCER_ENDPOINTS: Record = { + 1: SequenceIndexerServices.MAINNET, + 5: SequenceIndexerServices.GOERLI, + 100: SequenceIndexerServices.GNOSIS, + 137: SequenceIndexerServices.POLYGON, + 80001: SequenceIndexerServices.POLYGON_MUMBAI, +} diff --git a/frontend/src/components/NFTGrid/index.tsx b/frontend/src/components/NFTGrid/index.tsx index b2576d7..5296270 100644 --- a/frontend/src/components/NFTGrid/index.tsx +++ b/frontend/src/components/NFTGrid/index.tsx @@ -1,63 +1,43 @@ -import { useEffect, useState } from "react" - -import useNFTsByOwner, { MechNFT } from "../../hooks/useNFTsByOwner" +import { ContractType, TokenBalance } from "@0xsequence/indexer" import NFTGridItem from "../NFTGridItem" import Spinner from "../Spinner" -import Button from "../Button" import classes from "./NFTGrid.module.css" import clsx from "clsx" import { useChainId } from "wagmi" import { useDeployedMechs } from "../../hooks/useDeployMech" import { calculateMechAddress } from "../../utils/calculateMechAddress" +import useTokenBalances from "../../hooks/useTokenBalances" interface Props { address: string } const NFTGrid: React.FC = ({ address }) => { - const [pageToken, setPageToken] = useState(undefined) - const chainId = useChainId() - const { data, isLoading } = useNFTsByOwner({ - walletAddress: address, + const { balances, isLoading } = useTokenBalances({ + accountAddress: address, chainId, - pageToken, }) - const [nftData, setNftData] = useState([]) - - useEffect(() => { - setNftData((nftData) => { - if (nftData.length === 0) { - return data?.assets || [] - } - const ids = new Set( - nftData.map((nft) => nft.nft.tokenID + nft.contractAddress) - ) - - // merge and dedupe - return [ - ...nftData, - ...data?.assets.filter( - (nft) => !ids.has(nft.nft.tokenID + nft.contractAddress) - ), - ] - }) - }, [data]) + const nftBalances = balances.filter( + (balance) => + balance.contractType === ContractType.ERC721 || + balance.contractType === ContractType.ERC1155 + ) - const deployedMechs = useDeployedMechs(nftData) + const deployedMechs = useDeployedMechs(nftBalances) - const isDeployed = (nft: MechNFT) => + const isDeployed = (nft: TokenBalance) => deployedMechs.some( (mech) => mech.chainId === chainId && mech.address.toLowerCase() === calculateMechAddress(nft).toLowerCase() ) - const deployed = nftData.filter(isDeployed) - const undeployed = nftData.filter((nft) => !isDeployed(nft)) + const deployed = nftBalances.filter(isDeployed) + const undeployed = nftBalances.filter((nft) => !isDeployed(nft)) return (
@@ -75,7 +55,7 @@ const NFTGrid: React.FC = ({ address }) => {
    {deployed.map((nft, index) => (
  • - +
  • ))}
@@ -89,24 +69,12 @@ const NFTGrid: React.FC = ({ address }) => {
    {undeployed.map((nft, index) => (
  • - +
  • ))}
)} - {isLoading ? ( - - ) : ( - - )} + {isLoading && }
) } diff --git a/frontend/src/components/NFTGridItem/index.tsx b/frontend/src/components/NFTGridItem/index.tsx index 6a1df48..4e4229f 100644 --- a/frontend/src/components/NFTGridItem/index.tsx +++ b/frontend/src/components/NFTGridItem/index.tsx @@ -1,3 +1,4 @@ +import { TokenBalance } from "@0xsequence/indexer" import { useState } from "react" import copy from "copy-to-clipboard" import clsx from "clsx" @@ -7,47 +8,49 @@ import classes from "./NFTItem.module.css" import Button from "../Button" import { shortenAddress } from "../../utils/shortenAddress" import Spinner from "../Spinner" -import { MechNFT } from "../../hooks/useNFTsByOwner" import ChainIcon from "../ChainIcon" import { calculateMechAddress } from "../../utils/calculateMechAddress" import { CHAINS, ChainId } from "../../chains" import { useDeployMech } from "../../hooks/useDeployMech" interface Props { - nftData: MechNFT + tokenBalance: TokenBalance } -const NFTGridItem: React.FC = ({ nftData }) => { +const NFTGridItem: React.FC = ({ tokenBalance }) => { const [imageError, setImageError] = useState(false) - const chain = CHAINS[parseInt(nftData.blockchain.shortChainID) as ChainId] + const chain = CHAINS[tokenBalance.chainId as ChainId] - const mechAddress = calculateMechAddress(nftData) - const { deploy, deployPending, deployed } = useDeployMech(nftData) + const mechAddress = calculateMechAddress(tokenBalance) + const { deploy, deployPending, deployed } = useDeployMech(tokenBalance) + + const name = + tokenBalance.tokenMetadata?.name || tokenBalance.contractInfo?.name return (

- {nftData.nft.title || nftData.nft.contractTitle || "..."} + {name || "..."}

- {nftData.nft.tokenID.length < 5 && ( -

{nftData.nft.tokenID || "..."}

+ {tokenBalance.tokenID.length < 5 && ( +

{tokenBalance.tokenID || "..."}

)}
- {(!nftData.nft.previews || imageError) && ( + {(imageError || !tokenBalance.tokenMetadata?.image) && (
)} - {!imageError && nftData.nft.previews && ( + {!imageError && tokenBalance.tokenMetadata?.image && (
{nftData.nft.contractTitle} setImageError(true)} /> @@ -68,7 +71,7 @@ const NFTGridItem: React.FC = ({ nftData }) => {
{deployed ? (