diff --git a/ui/src/app/api/getBeasts.ts b/ui/src/app/api/getBeasts.ts new file mode 100644 index 000000000..efd1641ff --- /dev/null +++ b/ui/src/app/api/getBeasts.ts @@ -0,0 +1,53 @@ +import { Network } from "@/app/hooks/useUIStore"; +import { networkConfig } from "@/app/lib/networkConfig"; +import { indexAddress } from "@/app/lib/utils"; + +export const getBeasts = async ( + owner: string, + beastsAddress: string, + network: Network +): Promise => { + const recursiveFetch: any = async ( + beasts: any[], + nextPageKey: string | null + ) => { + let url = `${ + networkConfig[network!].blastUrl + }/builder/getWalletNFTs?contractAddress=${beastsAddress}&walletAddress=${indexAddress( + owner + ).toLowerCase()}&pageSize=100`; + + if (nextPageKey) { + url += `&pageKey=${nextPageKey}`; + } + + try { + const response = await fetch(url, { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }); + + const data = await response.json(); + beasts = beasts.concat( + data?.nfts?.map((beast: any) => { + const tokenId = JSON.parse(beast.tokenId); + return Number(tokenId); + }) + ); + + if (data.nextPageKey) { + return recursiveFetch(beasts, data.nextPageKey); + } + } catch (ex) { + console.log("error fetching beasts", ex); + } + + return beasts; + }; + + let beastsData = await recursiveFetch([], null); + + return beastsData; +}; diff --git a/ui/src/app/components/profile/ProfileDialog.tsx b/ui/src/app/components/profile/ProfileDialog.tsx index 8625c3c14..edacc6e27 100644 --- a/ui/src/app/components/profile/ProfileDialog.tsx +++ b/ui/src/app/components/profile/ProfileDialog.tsx @@ -1,14 +1,18 @@ import { Button } from "@/app/components/buttons/Button"; -import { CartridgeIcon } from "@/app/components/icons/Icons"; +import { CartridgeIcon, GiBruteIcon } from "@/app/components/icons/Icons"; import useAdventurerStore from "@/app/hooks/useAdventurerStore"; import useNetworkAccount from "@/app/hooks/useNetworkAccount"; import { useQueriesStore } from "@/app/hooks/useQueryStore"; import useUIStore from "@/app/hooks/useUIStore"; import { checkCartridgeConnector } from "@/app/lib/connectors"; +import { networkConfig } from "@/app/lib/networkConfig"; import { copyToClipboard, displayAddress, padAddress } from "@/app/lib/utils"; import { NullAdventurer } from "@/app/types"; import CartridgeConnector from "@cartridge/connector"; import { useConnect, useDisconnect } from "@starknet-react/core"; +import Image from "next/image"; +import Eth from "public/icons/eth.svg"; +import Lords from "public/icons/lords.svg"; import { useState } from "react"; import { MdClose } from "react-icons/md"; import { AccountInterface } from "starknet"; @@ -18,12 +22,21 @@ interface ProfileDialogprops { adminAccountAddress: string, account: AccountInterface, ethBalance: bigint, - lordsBalance: bigint + lordsBalance: bigint, + goldenTokenAddress: string, + goldenTokens: number[], + beasts: number[], + blobertsAddress: string, + bloberts: any[], + tournamentEnded: boolean ) => Promise; ethBalance: bigint; lordsBalance: bigint; ethContractAddress: string; lordsContractAddress: string; + goldenTokens: number[]; + beasts: number[]; + blobertsData: any; } export const ProfileDialog = ({ @@ -32,6 +45,9 @@ export const ProfileDialog = ({ lordsBalance, ethContractAddress, lordsContractAddress, + goldenTokens, + beasts, + blobertsData, }: ProfileDialogprops) => { const { setShowProfile, setNetwork } = useUIStore(); const { disconnect } = useDisconnect(); @@ -43,6 +59,7 @@ export const ProfileDialog = ({ const username = useUIStore((state) => state.username); const controllerDelegate = useUIStore((state) => state.controllerDelegate); const handleOffboarded = useUIStore((state) => state.handleOffboarded); + const network = useUIStore((state) => state.network); const { connector } = useConnect(); const handleCopy = () => { @@ -57,6 +74,11 @@ export const ProfileDialog = ({ setTimeout(() => setCopiedDelegate(false), 2000); }; + const tournamentEnded = process.env.NEXT_PUBLIC_TOURNAMENT_ENDED === "true"; + + const goldenTokenAddress = networkConfig[network!].goldenTokenAddress; + const blobertsAddress = networkConfig[network!].tournamentWinnerAddress; + return (
-
+
{checkCartridgeConnector(connector) && ( )} @@ -90,10 +112,44 @@ export const ProfileDialog = ({ {displayAddress(address!)} )} +
+ + +

{(Number(ethBalance) / 10 ** 18).toFixed(4).toString()}

+
+ + +

{(Number(lordsBalance) / 10 ** 18).toFixed(2).toString()}

+
+ + golden-tokens +

{goldenTokens?.length}

+
+ + +

{beasts.length}

+
+ {tournamentEnded && ( + + bloberts +

{blobertsData?.tokens.length}

+
+ )} +
{checkCartridgeConnector(connector) && ( -
+

Withdraw

@@ -121,7 +177,7 @@ export const ProfileDialog = ({ (connector as unknown as CartridgeConnector).openMenu() } > - Change Settings + Set Delegate