import{useEffect as B,useState as m}from"react";import{Box as h,Flex as y,Image as E,Modal as L,ModalBody as N,ModalCloseButton as $,ModalContent as z,ModalHeader as H,ModalOverlay as W,Skeleton as C,Text as x}from"@chakra-ui/react";import{useWeb3React as k}from"@web3-react/core";import{useMemo as v}from"react";import{isAddress as F}from"@ethersproject/address";import{AddressZero as R}from"@ethersproject/constants";import{Contract as U}from"@ethersproject/contracts";function I(t,o){return t.getSigner(o).connectUnchecked()}function T(t,o){return o?I(t,o):t}function p(t,o,i,e){if(!F(t)||t===R)throw Error(`Invalid 'address' parameter '${t}'.`);return new U(t,o,T(i,e))}function g(t,o,i=!0){let{provider:e,account:l,chainId:a}=k();return v(()=>{if(!t||!o||!e||!a)return null;let n;if(typeof t=="string"?n=t:n=t[a],!n)return null;try{return p(n,o,e,i&&l?l:void 0)}catch(u){return console.error("Failed to get contract",u),null}},[t,o,e,a,i,l])}import _ from"axios";import{jsx as r,jsxs as f}from"react/jsx-runtime";var D=[{inputs:[{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"tokenURI",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"}],b=t=>t?t.split("/")[t.split("/").length-1]:"",K=({isOpen:t,onClose:o,contractAddress:i,mintedTokens:e})=>{let[l,a]=m(null),[n,u]=m(!0),[w,d]=m(!1),s=g(i,D);return B(()=>{t&&e&&s&&(async()=>{try{if(d(!1),e.length<=0)return u(!1);u(!0);let c=await s.tokenURI(e[e.length-1]);if(c){let M=b(c),{data:S}=await _.get(`https://bandit.infura-ipfs.io/ipfs/${M}`);a(S)}}catch(c){d(!0),console.log(c)}finally{u(!1)}})()},[e,s,t]),f(L,{blockScrollOnMount:!1,isOpen:t,onClose:o,isCentered:!0,children:[r(W,{}),f(z,{children:[r(H,{}),r($,{}),r(N,{children:f(y,{direction:"column",align:"center",mb:4,children:[r(h,{borderRadius:8,p:2,w:"180px",borderColor:"input",border:"1px solid",children:f(y,{direction:"column",align:"center",children:[r(C,{isLoaded:!n,startColor:"muted",endColor:"input",children:r(h,{h:40,w:40,bg:"muted",children:r(E,{h:"full",w:"full",borderRadius:8,objectFit:"cover",src:`https://bandit.infura-ipfs.io/ipfs/${b(l?.image)}`})})}),r(C,{isLoaded:!n,mt:2,startColor:"muted",endColor:"input",children:r(x,{fontSize:14,fontWeight:600,children:l?.name})})]})}),w&&r(x,{fontSize:14,color:"red",mt:2,children:"Something went wrong! Failed to load your NFT."})]})})]})]})},et=K;export{et as default};
