diff --git a/playground/nextjs-app-router/components/AppProvider.tsx b/playground/nextjs-app-router/components/AppProvider.tsx index fef9d3f7d4..a9b7aafba8 100644 --- a/playground/nextjs-app-router/components/AppProvider.tsx +++ b/playground/nextjs-app-router/components/AppProvider.tsx @@ -173,7 +173,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => { }} > - {!names ? 'Loading...' : (names[nameIndex] || `${address.substring(0, 6)}...${address.substring(38)}`)} - - ); -} - -// Component for useAvatars resolution - shows avatar image + address -function AvatarItem({ address, nameIndex, names, avatars }: { - address: `0x${string}`, - nameIndex: number, - names: (string | null)[] | undefined, - avatars: (string | null)[] | undefined -}) { - const name = names ? names[nameIndex] : null; - const avatar = avatars && name ? avatars[nameIndex] : null; - - return ( -
  • - {!names || !avatars ? ( - 'Loading...' - ) : ( - <> - {avatar && Avatar} - {name || `${address.substring(0, 6)}...${address.substring(38)}`} - - )} -
  • - ); -} - -// Component for getNames resolution - only shows name/address text -function GetNameItem({ address, nameIndex, names, isLoading }: { - address: `0x${string}`, - nameIndex: number, - names: (string | null)[], - isLoading: boolean -}) { - return ( -
  • - {isLoading ? 'Loading...' : names[nameIndex] || `${address.substring(0, 6)}...${address.substring(38)}`} -
  • - ); -} - -// Component for getAvatars resolution - shows avatar image + address -function GetAvatarItem({ address, nameIndex, names, avatars, isLoading }: { - address: `0x${string}`, - nameIndex: number, - names: (string | null)[], - avatars: (string | null)[], - isLoading: boolean -}) { - return ( -
  • - {isLoading ? ( - 'Loading...' - ) : ( - <> - {avatars[nameIndex] && Avatar} - {names[nameIndex] || `${address.substring(0, 6)}...${address.substring(38)}`} - - )} -
  • - ); -} export function IdentityCardDemo() { const { address } = useAccount(); - const [addresses, setAddresses] = useState([]); - - // For getNames and getAvatars - const [batchNames, setBatchNames] = useState<(string | null)[]>([]); - const [batchAvatars, setBatchAvatars] = useState<(string | null)[]>([]); - const [isLoadingNames, setIsLoadingNames] = useState(true); - const [isLoadingAvatars, setIsLoadingAvatars] = useState(true); - - const { apiKey, chain } = useOnchainKit(); - - // For useNames and useAvatars - const { data: hookNames, isLoading: isLoadingHookNames } = useNames({ - addresses: addresses as `0x${string}`[], - chain: mainnet - }); - - const { data: hookAvatars, isLoading: isLoadingHookAvatars } = useAvatars({ - ensNames: hookNames?.filter(Boolean) as string[] || [], - chain: mainnet - }); - - // Generate addresses with the first one fixed and the rest random - useEffect(() => { - const generateAddresses = () => { - // Start with the specific address - const result: string[] = ['0x4bEf0221d6F7Dd0C969fe46a4e9b339a84F52FDF']; - - // Add the specified second address - result.push('0x849151d7D0bF1F34b70d5caD5149D28CC2308bf1'); - - // Add 3 more random addresses (for a total of 5) - for (let i = 0; i < 3; i++) { - // Create variation in the last 4 characters of the address - const hexIndex = i.toString(16).padStart(4, '0'); - result.push(`0x4bEf0221d6F7Dd0C969fe46a4e9b339a84F5${hexIndex}`); - } - setAddresses(result); - }; - - generateAddresses(); - }, []); - - // Fetch names and avatars using getNames and getAvatars - useEffect(() => { - const fetchData = async () => { - if (!addresses.length || !apiKey) return; - - try { - setIsLoadingNames(true); - - // Set the OnchainKit config before making the call - setOnchainKitConfig({ - apiKey, - chain, - }); - - // Get names for all addresses in a batch - const nameResults = await getNames({ - addresses: addresses as `0x${string}`[], - chain: mainnet - }); - - setBatchNames(nameResults); - setIsLoadingNames(false); - - // Get avatars for all names in a batch - setIsLoadingAvatars(true); - const validNames = nameResults.filter(Boolean) as string[]; - - if (validNames.length > 0) { - const avatarResults = await getAvatars({ - ensNames: validNames, - chain: mainnet - }); - - // Create a mapping of names to avatars - const avatarMap = new Map(); - validNames.forEach((name, idx) => { - avatarMap.set(name, avatarResults[idx]); - }); - - // Map avatars back to the original address order - const mappedAvatars = nameResults.map(name => - name ? avatarMap.get(name) || null : null - ); - - setBatchAvatars(mappedAvatars); - } - } catch (error) { - console.error('Error fetching data:', error); - } finally { - setIsLoadingAvatars(false); - } - }; - - fetchData(); - }, [addresses, apiKey, chain]); if (!address) { return null; } return ( -
    +
    -
    - {/* useNames List */} -
    -

    useNames

    -
    -
      - {addresses.map((addr, index) => ( - - ))} -
    -
    -
    - - {/* getNames List */} -
    -

    getNames

    -
    -
      - {addresses.map((addr, index) => ( - - ))} -
    -
    -
    - - {/* useAvatars List */} -
    -

    useAvatars

    -
    -
      - {addresses.map((addr, index) => ( - - ))} -
    -
    -
    - - {/* getAvatars List */} -
    -

    getAvatars

    -
    -
      - {addresses.map((addr, index) => ( - - ))} -
    -
    -
    +
    +

    + Mainnet Identity +

    + +
    +
    +

    Base Identity

    +
    diff --git a/playground/nextjs-app-router/onchainkit/package.json b/playground/nextjs-app-router/onchainkit/package.json index d9c959209b..484b7f296f 100644 --- a/playground/nextjs-app-router/onchainkit/package.json +++ b/playground/nextjs-app-router/onchainkit/package.json @@ -1,6 +1,6 @@ { "name": "@coinbase/onchainkit", - "version": "0.37.6", + "version": "0.37.5", "type": "module", "repository": "https://github.com/coinbase/onchainkit.git", "license": "MIT", @@ -35,8 +35,6 @@ "react-dom": "^18 || ^19" }, "dependencies": { - "@farcaster/frame-sdk": "^0.0.28", - "@farcaster/frame-wagmi-connector": "^0.0.16", "@tanstack/react-query": "^5", "clsx": "^2.1.1", "graphql": "^14 || ^15 || ^16",