import { useCallback, useContext, useEffect, useState } from 'react'; import { Row, Col, Alert, Toast, Card, Button } from 'react-bootstrap'; import { Project } from '../../../core/project'; import { ClientContext } from '../../../contexts/clientProvider'; import PathImage from '../../bootstrap/PathImage'; import Assets from '../../bootstrap/Assets'; import { cutLongString } from '../../../utils/helpers'; export default function Overview({ project = { deployedProject: {}, } as any, selectComponent, selectTab, }: { project: Project; selectComponent: (component: string) => void; selectTab: (tab: string, props?: any) => void; }) { const client = useContext(ClientContext); const [totalMints, setTotalMints] = useState(0); const [totalMintsUpdated, setTotalMintsUpdated] = useState(new Date()); const [totalSupply, setTotalSupply] = useState(0); const [tokenPrice, setTokenPrice] = useState('0.0'); const [totalPaths, setTotalPaths] = useState(8); //draw 16 paths const [web3Error, setWeb3Error] = useState(null); const [showPaths, setShowPaths] = useState(false); const [showAssets, setShowAssets] = useState(false); const getTotalMints = useCallback(async () => { if (!client.loaded) return; if (!project) return; const totalMints = await project.totalMints(); setTotalMints(parseInt(totalMints.toString())); setTotalMintsUpdated(new Date()); }, [project, client]); const getTotalSupply = useCallback(async () => { if (!project) return; if (!client.loaded) return; const supply = await project.maxSupply(); setTotalSupply(parseInt(supply.toString())); }, [project, client]); const getTokenPrice = useCallback(async () => { if (!project) return; if (!client.loaded) return; const price = await project.getTokenPrice(); setTokenPrice(price.toString()); }, [project, client]); useEffect(() => { setWeb3Error(null); setTokenPrice('0.0'); setTotalPaths(8); setTotalMints(0); setTotalSupply(0); getTotalMints().catch((e) => { console.error(e); setWeb3Error(e); }); getTotalSupply().catch((e) => { console.error(e); setWeb3Error(e); }); getTokenPrice().catch((e) => { console.error(e); setWeb3Error(e); }); }, [getTotalMints, getTotalSupply, getTokenPrice]); let assetSections = project?.getAssetSections() || {}; return ( <>

Overview

Last updated {new Date(Date.now()).toString()}

Mints last updated at{' '} {totalMintsUpdated.toLocaleTimeString()}

{totalMints}

Supply

🗃️

{cutLongString( totalSupply.toString(), 8 )}

Paths

👁️

{ project?.deployedProject?.paths ?.length }

Price

🤑

{tokenPrice}

Assets

🎨

{ Object.values( project?.deployedProject ?.assets || {} )?.length }

Gems

💎

{ Object.values( project?.deployedProject ?.gems || {} )?.length }

Paths{' '} {project?.deployedProject?.paths?.length} New Path ➕


{showPaths ? ( <> {project?.deployedProject?.paths .slice(0, totalPaths) .map((path, index) => ( <>
{path.name}{' '} Rarity{' '} {path?.rarity || Math.ceil( Object.values( project ?.deployedProject ?.paths ).length / 100 )} % PathId {index}
{totalPaths < project.deployedProject.paths.length && index === totalPaths - 1 ? ( ) : null} ))}
) : ( )}

Assets{' '} { Object.values( project?.deployedProject?.assets || {} ).length } New Asset ➕


{Object.values(project?.deployedProject?.assets || {}).length !== 0 ? ( ) : ( You have no assets defined in this project. )}
); }