Skip to content

Commit

Permalink
add nfts
Browse files Browse the repository at this point in the history
  • Loading branch information
alissacrane-cb committed Nov 8, 2024
1 parent 9c151ef commit 1f1f2be
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 23 deletions.
65 changes: 50 additions & 15 deletions app/components/AgentAssets.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { type Token, TokenRow } from '@coinbase/onchainkit/token';
import { useCallback, useEffect, useState } from 'react';
// import useGetNFTs from "../hooks/useGetNFTs";
import type { Address } from 'viem';
import { useToken } from 'wagmi';
import { useCallback, useEffect, useMemo, useState } from 'react';
import useGetNFTs from '../hooks/useGetNFTs';
import { erc721Abi, type Address } from 'viem';
import { useContractRead, useToken } from 'wagmi';
import useGetTokens from '../hooks/useGetTokens';
import { NFTMintCard } from '@coinbase/onchainkit/nft';
import { NFTCollectionTitle } from '@coinbase/onchainkit/nft/mint';

type AgentTokenProps = {
type AgentAssetProps = {
tokenAddress: Address;
};

function AgentToken({ tokenAddress }: AgentTokenProps) {
function AgentToken({ tokenAddress }: AgentAssetProps) {
const { data } = useToken({ address: tokenAddress, chainId: 84532 });
const token: Token = {
address: tokenAddress,
Expand All @@ -20,38 +22,63 @@ function AgentToken({ tokenAddress }: AgentTokenProps) {
image: '',
};

return <TokenRow token={token} className="max-w-56 rounded" />;
return <TokenRow token={token} className="max-w-56 rounded font-mono" />;
}

function AgentNFT({ tokenAddress }: AgentAssetProps) {
const { data: name } = useContractRead({
address: tokenAddress,
abi: erc721Abi,
functionName: 'name',
chainId: 84532,
});

const nftData = useMemo(() => {
return {
name,
};
}, [name]);

if (!name) {
return null;
}

return (
<NFTMintCard contractAddress={tokenAddress} useNFTData={() => nftData}>
<NFTCollectionTitle className="font-mono text-sm" />
</NFTMintCard>
);
}
export default function AgentAssets() {
const [tab, setTab] = useState('tokens');
// const [nfts, setNFTs] = useState<string[]>([]);
const [nfts, setNFTs] = useState<Address[]>([]);
const [tokens, setTokens] = useState<Address[]>([]);

const { getTokens } = useGetTokens({ onSuccess: setTokens });
// const { getNFTs } = useGetNFTs({ onSuccess: setNFTs });
const { getNFTs } = useGetNFTs({ onSuccess: setNFTs });

const handleTabChange = useCallback((tab: string) => {
return () => setTab(tab);
}, []);

useEffect(() => {
// getNFTs();
getNFTs();
getTokens();
}, [getTokens]);
}, [getNFTs, getTokens]);

return (
<div className="mr-2 mb-4 rounded-sm bg-black p-4">
<div className="flex flex-col items-start gap-4">
<div className="flex w-full grow gap-6 border-zinc-700 border-b">
{/* <button
<button
type="button"
onClick={handleTabChange("nfts")}
onClick={handleTabChange('nfts')}
className={`flex items-center justify-center py-1 ${
tab === "nfts" ? "border-b border-[#5788FA]" : ""
tab === 'nfts' ? 'border-b border-[#5788FA]' : ''
}`}
>
NFTs
</button> */}
</button>
<button
type="button"
onClick={handleTabChange('tokens')}
Expand All @@ -68,6 +95,14 @@ export default function AgentAssets() {
tokens?.map((token) => (
<AgentToken key={token} tokenAddress={token} />
))}

{tab === 'nfts' && nfts && (
<div className="grid grid-col-1 sm:grid-cols-2 gap-4">
{nfts?.map((nft) => (
<AgentNFT key={nft} tokenAddress={nft} />
))}
</div>
)}
</div>
</div>
);
Expand Down
6 changes: 1 addition & 5 deletions app/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ export const AGENT_WALLET_ADDRESS =

export const AGENT_NAME = 'Based Agent';

export const DEFAULT_PROMPT =
'Be creative and same something interesting about the blockchain and your abilities in one sentence';

// export const DEFAULT_PROMPT =
// 'Be creative and do something interesting on the blockchain. Choose an action or set of actions and execute it in a way that highlights your abilities.';
export const DEFAULT_PROMPT = 'summarize the latest block data on base sepolia';
5 changes: 3 additions & 2 deletions app/hooks/useGetNFTs.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { useCallback, useState } from 'react';
import type { Address } from 'viem';
import { API_URL } from '../config';

type UseGetNFTsResponse = {
NFTs?: string[];
NFTs?: Address[];
error?: Error;
getNFTs: () => void;
isLoading: boolean;
};

type UseGetNFTsProps = {
onSuccess: (nfts: string[]) => void;
onSuccess: (addresses: Address[]) => void;
};

export default function useGetNFTs({
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"ci:lint": "biome ci --formatter-enabled=false --organize-imports-enabled=false"
},
"dependencies": {
"@coinbase/onchainkit": "latest",
"@coinbase/onchainkit": "0.35.5",
"concurrently": "^8.0.1",
"next": "14.2.15",
"react": "^18",
Expand Down

0 comments on commit 1f1f2be

Please sign in to comment.