import { useEffect, useState } from 'react'; import { Button, Card, Col, ListGroup, Row } from 'react-bootstrap'; import Token from '../../Token'; import { Project } from '../../../core/project'; import Loading from '../../bootstrap/Loading'; import { cutLongString } from '../../../utils/helpers'; import Assets from '../../bootstrap/Assets'; import { Dictionary } from 'infinitymint/dist/app/helpers'; import { InfinityMintProjectAsset } from 'infinitymint/dist/app/interfaces'; import { load } from '../../../main'; import path from 'path'; export default function Preview({ project = { deployedProject: {}, } as any, defaultPathId = null, defaultAssets = null, defaultSeed = null, selectComponent, selectTab, }: { project: Project; defaultPathId?: number; defaultAssets?: Dictionary; defaultSeed?: number; selectComponent: (component: string) => void; selectTab: (tab: string, props?: any) => void; }) { const [pathId, setPathId] = useState(defaultPathId); const [assets, setAssets] = useState>(defaultAssets); const [seed, setSeed] = useState( defaultSeed || Math.floor(Math.random() * 64) ); const [loading, setLoading] = useState(true); useEffect(() => { if (!project) return; let assetSections = project?.getAssetSections() || {}; setLoading(true); setAssets({ ...new Array(Object.keys(assetSections).length) } as any); setLoading(false); }, [project]); useEffect(() => { setLoading(true); if (defaultPathId !== null && defaultPathId !== undefined) setPathId(defaultPathId); setLoading(false); }, [defaultPathId]); let assetSections = project?.getAssetSections() || {}; return ( <>

Preview{' '} Mint ➕

Preview how a token might look on the blockchain using this utility.

{loading ? ( ) : (
{project.deployedProject.paths.map( (path) => { return ( { setPathId(path.pathId); }} variant={ path.pathId === pathId ? 'success' : 'secondary' } style={{ cursor: 'pointer', }} > {cutLongString(path.name)} { selectTab( 'ViewPath', { path: path, project: project, } ); }} > ✏️ Rarity{' '} {path.rarity || ( (1 / Object.values( project ?.deployedProject ?.paths || [] ).length) * 100 ).toFixed(2)} % PathId {path.pathId} ); } )}
)}
{loading ? ( ) : ( <> {pathId !== null && pathId !== undefined ? ( <> asset?.assetId || 0 ), seed: seed, }} />
) : ( <>

Select a path to preview


)} )}
asset?.assetId || 0 )} hidden={ Object.values(project?.deployedProject?.assets || {}) .length === 0 } onAssetSelected={(asset, unselect = false) => { let sectionIndex = Object.keys(assetSections).indexOf( asset.section ); let newAssets = { ...(assets || {}) }; if (!unselect) newAssets[sectionIndex] = asset; else newAssets[sectionIndex] = null; if ( Object.values(newAssets).filter((val) => val).length === 0 ) setAssets(null); else setAssets(newAssets); }} >
); }