var m=(r,n,e)=>new Promise((o,i)=>{var u=t=>{try{a(e.next(t))}catch(d){i(d)}},p=t=>{try{a(e.throw(t))}catch(d){i(d)}},a=t=>t.done?o(t.value):Promise.resolve(t.value).then(u,p);a((e=e.apply(r,n)).next())});import{useToast as y}from"@chakra-ui/react";import{Metaplex as w,walletAdapterIdentity as x}from"@metaplex-foundation/js";import{useWallet as A}from"@solana/wallet-adapter-react";import{clusterApiUrl as M,Connection as k,PublicKey as f}from"@solana/web3.js";import{useCallback as h,useEffect as _,useState as b}from"react";var v=(r,n,e)=>r==="devnet"||r===9091?{rpc:"https://kora-disz8d-fast-devnet.helius-rpc.com/",bundlrAddress:"https://devnet.bundlr.network",bundlrProviderUrl:"https://kora-disz8d-fast-devnet.helius-rpc.com/",explorer:`https://solscan.io/${e}/${n}?cluster=devnet`}:r==="mainnet-beta"||r===9090?{rpc:"https://mainnet.helius-rpc.com/?api-key=68e9930e-3fe1-4025-ae8b-e9aa39550aa8/",bundlrAddress:"https://node1.bundlr.network",bundlrProviderUrl:"https://mainnet.helius-rpc.com/?api-key=68e9930e-3fe1-4025-ae8b-e9aa39550aa8/",explorer:`https://solscan.io/${e}/${n}`}:{rpc:"http://127.0.0.1:8899",bundlrAddress:"https://devnet.bundlr.network",bundlrProviderUrl:M("devnet"),explorer:`https://solscan.io/${e}/${n}?cluster=custom`},$=r=>{let n=A(),e=y(),[o,i]=b(null),[u,p]=b();_(()=>{if([9090,9091].includes(r)){let s=r===9091?"devnet":"mainnet-beta",c=new k(v(s).rpc);p(c),i(w.make(c).use(x(n)))}},[n]);let a=h(s=>s==="candyMachine",[]),t=h(s=>m(void 0,null,function*(){let c=new f(s);try{return yield o.candyMachines().findByAddress({address:c})}catch(l){throw console.log(l),e({title:"invalid cm",description:"provided id is neither cm v2 or v3.",status:"error",duration:6e3}),l}}),[o,e]),d=h(s=>m(void 0,null,function*(){let c=new f(s);try{return yield o.candyMachinesV2().findByAddress({address:c})}catch(l){return t(s)}}),[t,o]);return{metaplex:o,getCandyMachine:d,isV3:a,getUrls:v,connection:u}},g=$;export{g as default,v as getUrls};
