var St=Object.create;var b=Object.defineProperty;var xt=Object.getOwnPropertyDescriptor;var Ct=Object.getOwnPropertyNames;var At=Object.getPrototypeOf,kt=Object.prototype.hasOwnProperty;var Et=(t,e)=>{for(var s in e)b(t,s,{get:e[s],enumerable:!0})},O=(t,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ct(e))!kt.call(t,n)&&n!==s&&b(t,n,{get:()=>e[n],enumerable:!(o=xt(e,n))||o.enumerable});return t};var I=(t,e,s)=>(s=t!=null?St(At(t)):{},O(e||!t||!t.__esModule?b(s,"default",{value:t,enumerable:!0}):s,t)),bt=t=>O(b({},"__esModule",{value:!0}),t);var Dt={};Et(Dt,{default:()=>Rt});module.exports=bt(Dt);var A=require("react");var oe=require("react");var W=I(require("axios"),1);var U=require("react"),It=require("react/jsx-runtime"),Bt=(0,U.createContext)(void 0),B="production";var f=B==="development"?"https://qa-api-v2.bandit.network/sdk":"https://api-v2.bandit.network/sdk";var N=async(t,e)=>{try{return(await W.default.get(`${f}/users/${t}`,{headers:{"X-API-KEY":e}})).data}catch(s){throw new Error(s)}};var R=async(t,e)=>{try{return(await W.default.post(`${f}/users/getNonce`,{walletAddress:t},{headers:{"X-API-KEY":e}})).data}catch(s){throw new Error(s)}};var $=require("react-redux");var v=require("react"),P=require("@stacks/connect"),vt=()=>{let[t,e]=(0,v.useState)(""),s=new P.AppConfig(["store_write","publish_data"]),o=new P.UserSession({appConfig:s}),n=()=>{o.signUserOut(),e("")};return(0,v.useEffect)(()=>{if(o)try{let i=o.loadUserData();e(i.profile.stxAddress.testnet)}catch{}},[o]),{stacksAddress:t,userSession:o,disconnectStacks:n}},V=vt;var G=require("@web3-react/core"),q=require("@solana/wallet-adapter-react");var F=require("@reduxjs/toolkit"),Pt={selectedWallet:void 0,selectedSolanaWallet:void 0,accessKey:null,details:{}},L=(0,F.createSlice)({name:"user",initialState:Pt,reducers:{updateSelectedWallet(t,{payload:{wallet:e}}){t.selectedWallet=e},updateSolanaSelectedWallet(t,{payload:{wallet:e}}){t.selectedSolanaWallet=e},updateAccessKey(t,{payload:{accessKey:e}}){t.accessKey=e},updateUserDetails(t,{payload:{details:e}}){t.details=e}}}),{updateSelectedWallet:Zt,updateSolanaSelectedWallet:jt,updateAccessKey:te,updateUserDetails:D}=L.actions,ee=L.reducer;var $t=()=>{let{selectedWallet:t,accessKey:e,details:s={}}=(0,$.useSelector)(l=>l.user),{stacksAddress:o}=V(),{account:n}=(0,G.useWeb3React)(),{publicKey:i,disconnect:c}=(0,q.useWallet)(),d=(0,$.useDispatch)();return{user:s,fetchUser:async()=>{try{let l=i?i.toBase58():"",S=t==="stacks"?o:t==="Phantom"?l:n;if(s?.walletAddress?.toLowerCase()===S?.toLowerCase())return;let k=await N(S,e);d(D({details:k}))}catch(l){console.log(l)}},refreshUser:async()=>{try{if(!s.walletAddress)return;let l=await N(s.walletAddress,e);d(D({details:l}))}catch(l){console.log(l)}}}},z=$t;var _=I(require("axios"),1);var H=async(t,e,s)=>{try{return(await _.default.post(`${f}/collection/contest/${t}/verifyContest`,e,{headers:{"X-API-KEY":s}})).data}catch(o){throw new Error(o)}},J=async(t,e,s)=>{try{return(await _.default.get(`${f}/users/${t}/contest/${e}/getTaskStatus`,{headers:{"X-API-KEY":s}})).data}catch(o){throw new Error(o)}};var Y=require("react-redux"),mt=require("@chakra-ui/react");var g=require("react");var Q=require("@ethersproject/bytes"),Z=require("@ethersproject/strings"),j=async(t,e,s)=>{if(t.provider?.wc){let o=(0,Q.hexlify)((0,Z.toUtf8Bytes)(s));return await t.provider?.wc.signPersonalMessage([o,e])}return t.getSigner(e).signMessage(s)};var tt="CONNECTOR_ID",w="SIGNATURE";var nt=require("tweetnacl-util"),ct=require("@solana/wallet-adapter-react"),it=I(require("bs58"),1);var K=require("react"),Kt=t=>{let e=(0,K.useRef)();return(0,K.useEffect)(()=>{e.current=t},[t]),e.current},et=Kt;var lt=require("@web3-react/core"),dt=require("@chakra-ui/react"),ut=require("react-redux");var rt=require("react");var C=require("react");var Tt=I(require("axios"),1);var st=require("react/jsx-runtime");var Ut=require("react/jsx-runtime"),ot=(0,C.createContext)(void 0);var at=()=>(0,rt.useContext)(ot);var Wt=()=>{let t=(0,ct.useWallet)(),e=(0,dt.useToast)(),[s,o]=(0,g.useState)(null),[n,i]=(0,g.useState)(null),{account:c,provider:d}=(0,lt.useWeb3React)(),{accessKey:h}=at(),y=(0,ut.useSelector)(a=>a.user.selectedWallet),l=et(c);return(0,g.useEffect)(()=>{let a=localStorage.getItem(w);o(a),i(y)},[c,t.connected,y]),(0,g.useEffect)(()=>{let a=localStorage.getItem(tt);!c&&!a&&(localStorage.removeItem(w),o(null))},[c]),(0,g.useEffect)(()=>{c&&c!==l&&(localStorage.removeItem(w),o(null))},[c]),[s,n==="Phantom"?async()=>{if(s)return s;try{let{data:a}=await R(t?.publicKey?.toBase58(),h),u=t&&`Verify your account: ${t?.publicKey?.toBase58()}
Nonce: ${a}`,T=(0,nt.decodeUTF8)(u),M=t&&await t?.signMessage(T),x=it.encode(M);return localStorage.setItem(w,x),o(x),x}catch(a){throw a}}:async()=>{if(s)return s;try{let{data:a}=await R(c,h),u=await j(d,c,`Verify your account: ${c}
Nonce: ${a}`);return localStorage.setItem(w,u),o(u),u}catch(a){throw a}}]},pt=Wt;var ft=require("@solana/wallet-adapter-react"),gt=require("@web3-react/core"),Nt=({collectionId:t,contestMetaData:e=[],isCollectionContest:s,chainId:o,refresh:n=!1})=>{let[i,c]=(0,A.useState)({}),{user:d}=z(),h=(0,Y.useSelector)(r=>r.user.accessKey),y=(0,Y.useSelector)(r=>r.user.selectedWallet),[l,S]=pt(),k=(0,ft.useWallet)(),{account:X}=(0,gt.useWeb3React)(),a=(0,mt.useToast)();(0,A.useEffect)(()=>{t&&s&&d?.walletAddress&&u()},[t,d?.walletAddress,n]),(0,A.useEffect)(()=>{d?.walletAddress||c({})},[d?.walletAddress,n]);let u=async()=>{try{let r=await J(d?.walletAddress,t,h),m={};r.forEach(p=>{m={...m,[p.moduleId]:p}}),c(m)}catch(r){console.log(r)}},T=async(r,m)=>{try{let p=l;p||(p=await S()),await H(t,{moduleId:r,task:m,walletAddress:y==="Phantom"?k?.publicKey?.toBase58():X,signature:p},h),await u(),a({title:"Verification success",description:"",status:"success"})}catch(p){a({title:"Verification Failed",description:"",status:"error"}),console.log(p)}},x=e.filter(r=>i[r.id]?.tasksCompleted?.length===r?.tasks?.length&&i[r.id]?.isClaimed).length===e.length,E=e.filter(r=>i[r.id]?.tasksCompleted?.length===r?.tasks?.length&&!i[r.id]?.isClaimed),ht=E.length>0,wt=E?E.reduce((r,m)=>r+m.rewardData?.count,0):0,yt=E.map(r=>r.id);return{contestCompleted:x,isEligibleToMint:ht,tokensEligibleToClaim:wt,eligibleModules:yt,claimedTokens:0,availableTokens:11,modulesStatus:i,verifyModuleTask:T,user:d,getUserCompletedTasks:u,chainId:o}},Rt=Nt;
