import{useToast as v}from"@chakra-ui/react";import{Metaplex as y,walletAdapterIdentity as k}from"@metaplex-foundation/js";import{useWallet as w}from"@solana/wallet-adapter-react";import{clusterApiUrl as x,Connection as A,PublicKey as l}from"@solana/web3.js";import{useCallback as d,useEffect as M,useState as i}from"react";var u=(t,n,r)=>t==="devnet"||t===9091?{rpc:"https://skilled-damp-glade.solana-devnet.discover.quiknode.pro/5eab58b431f2edb5c03a4a04e1cec02848871190/",bundlrAddress:"https://devnet.bundlr.network",bundlrProviderUrl:"https://skilled-damp-glade.solana-devnet.discover.quiknode.pro/5eab58b431f2edb5c03a4a04e1cec02848871190/",explorer:`https://solscan.io/${r}/${n}?cluster=devnet`}:t==="mainnet-beta"||t===9090?{rpc:"https://yolo-smart-sunset.solana-mainnet.quiknode.pro/0b35b5967d53895fd926312245f3c1e7026c1e7c/",bundlrAddress:"https://node1.bundlr.network",bundlrProviderUrl:"https://yolo-smart-sunset.solana-mainnet.quiknode.pro/0b35b5967d53895fd926312245f3c1e7026c1e7c/",explorer:`https://solscan.io/${r}/${n}`}:{rpc:"http://127.0.0.1:8899",bundlrAddress:"https://devnet.bundlr.network",bundlrProviderUrl:x("devnet"),explorer:`https://solscan.io/${r}/${n}?cluster=custom`},_=t=>{let n=w(),r=v(),[o,p]=i(null),[m,b]=i();M(()=>{if([9090,9091].includes(t)){let e=t===9091?"devnet":"mainnet-beta",s=new A(u(e).rpc);b(s),p(y.make(s).use(k(n)))}},[n]);let f=d(e=>e==="candyMachine",[]),a=d(async e=>{let s=new l(e);try{return await o.candyMachines().findByAddress({address:s})}catch(c){throw console.log(c),r({title:"invalid cm",description:"provided id is neither cm v2 or v3.",status:"error",duration:6e3}),c}},[o,r]),h=d(async e=>{let s=new l(e);try{return await o.candyMachinesV2().findByAddress({address:s})}catch{return a(e)}},[a,o]);return{metaplex:o,getCandyMachine:h,isV3:f,getUrls:u,connection:m}},g=_;export{g as default,u as getUrls};
