var $t=Object.create;var v=Object.defineProperty;var kt=Object.getOwnPropertyDescriptor;var Nt=Object.getOwnPropertyNames;var _t=Object.getPrototypeOf,Kt=Object.prototype.hasOwnProperty;var Dt=(t,e)=>{for(var o in e)v(t,o,{get:e[o],enumerable:!0})},W=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Nt(e))!Kt.call(t,n)&&n!==o&&v(t,n,{get:()=>e[n],enumerable:!(r=kt(e,n))||r.enumerable});return t};var w=(t,e,o)=>(o=t!=null?$t(_t(t)):{},W(e||!t||!t.__esModule?v(o,"default",{value:t,enumerable:!0}):o,t)),Rt=t=>W(v({},"__esModule",{value:!0}),t);var u=(t,e,o)=>new Promise((r,n)=>{var d=c=>{try{m(o.next(c))}catch(f){n(f)}},a=c=>{try{m(o.throw(c))}catch(f){n(f)}},m=c=>c.done?r(c.value):Promise.resolve(c.value).then(d,a);m((o=o.apply(t,e)).next())});var Wt={};Dt(Wt,{default:()=>Ot});module.exports=Rt(Wt);var l=require("react"),L=w(require("dayjs"),1);var H=require("@web3-react/core"),J=require("react");var G=require("@ethersproject/address"),q=require("@ethersproject/constants"),j=require("@ethersproject/contracts");function Tt(t,e){return t.getSigner(e).connectUnchecked()}function Mt(t,e){return e?Tt(t,e):t}function z(t,e,o,r){if(!(0,G.isAddress)(t)||t===q.AddressZero)throw Error(`Invalid 'address' parameter '${t}'.`);return new j.Contract(t,e,Mt(o,r))}function Z(t,e,o=!0){let{provider:r,account:n,chainId:d}=(0,H.useWeb3React)();return(0,J.useMemo)(()=>{if(!t||!e||!r||!d)return null;let a;if(typeof t=="string"?a=t:a=t[d],!a)return null;try{return z(a,e,r,o&&n?n:void 0)}catch(m){return console.error("Failed to get contract",m),null}},[t,e,r,d,o,n])}var Ct=require("@web3-react/core"),Et=require("@chakra-ui/react");var T=require("react"),Bt=require("react/jsx-runtime"),te=(0,T.createContext)(void 0),Q="production";var E=Q==="development"?"https://qa-api-v2.bandit.network/sdk":"https://api-v2.bandit.network/sdk";var M=w(require("axios"),1);var tt=(t,e,o,r=!1)=>u(void 0,null,function*(){try{return(yield M.default.post(`${E}/collection/mint/${t}`,o,{headers:{"X-API-KEY":e}})).data}catch(n){if(console.log(n),r)throw n}}),et=(t,e,o)=>u(void 0,null,function*(){try{return(yield M.default.post(`${E}/collection/${t}/mints/error`,o,{headers:{"X-API-KEY":e}})).data}catch(r){console.log(r)}});var St=w(require("bignumber.js"),1);var ot=w(require("bignumber.js"),1),Lt=new ot.default(10),rt=Lt.pow(18);var st=require("react");var b=require("react");var Yt=w(require("axios"),1);var nt=require("react/jsx-runtime");var Xt=require("react/jsx-runtime"),at=(0,b.createContext)(void 0);var P=()=>(0,st.useContext)(at);var x=require("react");var ct=require("@ethersproject/bytes"),it=require("@ethersproject/strings");var ut=(t,e,o)=>u(void 0,null,function*(){var r,n;if((r=t.provider)!=null&&r.wc){let d=(0,ct.hexlify)((0,it.toUtf8Bytes)(o));return yield(n=t.provider)==null?void 0:n.wc.signPersonalMessage([d,e])}return t.getSigner(e).signMessage(o)});var lt="CONNECTOR_ID",S="SIGNATURE";var mt=require("tweetnacl-util"),ft=require("@solana/wallet-adapter-react"),gt=w(require("bs58"),1);var A=require("react"),Ut=t=>{let e=(0,A.useRef)();return(0,A.useEffect)(()=>{e.current=t},[t]),e.current},dt=Ut;var ht=require("@web3-react/core"),yt=require("@chakra-ui/react"),wt=require("react-redux");var pt=w(require("axios"),1);var B=(t,e)=>u(void 0,null,function*(){try{return(yield pt.default.post(`${E}/users/getNonce`,{walletAddress:t},{headers:{"X-API-KEY":e}})).data}catch(o){throw new Error(o)}});var Vt=()=>{let t=(0,ft.useWallet)(),e=(0,yt.useToast)(),[o,r]=(0,x.useState)(null),[n,d]=(0,x.useState)(null),{account:a,provider:m}=(0,ht.useWeb3React)(),{accessKey:c}=P(),f=(0,wt.useSelector)(i=>i.user.selectedWallet),$=dt(a);return(0,x.useEffect)(()=>{let i=localStorage.getItem(S);r(i),d(f)},[a,t.connected,f]),(0,x.useEffect)(()=>{let i=localStorage.getItem(lt);!a&&!i&&(localStorage.removeItem(S),r(null))},[a]),(0,x.useEffect)(()=>{a&&a!==$&&(localStorage.removeItem(S),r(null))},[a]),[o,n==="Phantom"?()=>u(void 0,null,function*(){var i,g;if(o)return o;try{let{nonce:I}=yield B((i=t==null?void 0:t.publicKey)==null?void 0:i.toBase58(),c),C=t&&`Verify your account: ${(g=t==null?void 0:t.publicKey)==null?void 0:g.toBase58()}
Nonce: ${I}`,k=(0,mt.decodeUTF8)(C),N=t&&(yield t==null?void 0:t.signMessage(k)),y=gt.encode(N);return localStorage.setItem(S,y),r(y),y}catch(I){throw I}}):()=>u(void 0,null,function*(){if(o)return o;try{let{nonce:i}=yield B(a,c),g=yield ut(m,a,`Verify your account: ${a}
Nonce: ${i}`);return localStorage.setItem(S,g),r(g),g}catch(i){throw i}})]},xt=Vt;var Ft=({dynamicConfig:t,contractAddress:e,mintPrice:o,chainId:r,collectionId:n,mintPriceUnit:d})=>{let[a,m]=(0,l.useState)(1),[c,f]=(0,l.useState)(null),[$,Y]=(0,l.useState)(!1),[X,U]=(0,l.useState)({counter:null}),[i,g]=(0,l.useState)(!1),[I,C]=(0,l.useState)("start"),[k,N]=(0,l.useState)(null),{account:y}=(0,Ct.useWeb3React)(),{accessKey:_}=P(),[It,bt]=xt(),V=(0,Et.useToast)(),F=Z(e,t&&t.abi?t.abi:[]);(0,l.useEffect)(()=>{if(Object.keys(t).length){let s=t.mints.filter(h=>h.endless?!0:!L.default.unix(h.endDate).isBefore((0,L.default)()));s.length?f(s[0]):Y(!0)}},[t]),(0,l.useEffect)(()=>{if(c){let s=c.inputs.find(h=>h.category.toLowerCase()==="counter");U({counter:s})}},[c]);let vt=(0,l.useCallback)(s=>{f(t.mints[s])},[t]),Pt=(0,l.useCallback)(()=>u(void 0,null,function*(){try{g(!0),C("pending");let s=It;s||(s=yield bt());let{method:h,inputs:K,payable:At}=c,D=K.map(p=>{if(p.category.toLowerCase()==="input"){if(p.type.toLowerCase()==="address"||p.type.toLowerCase()==="text")return p.defaultValue;if(p.type.toLowerCase()==="user_address")return y}else if(p.category.toLowerCase()==="counter")return a});At&&(D=[...D,{value:new St.default(o).multipliedBy(a).multipliedBy(rt).toFixed()}]);let R=yield F[h](...D);N(R.hash);let O=(yield R.wait()).events.filter(p=>p.topics[0]==="0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef").map(p=>parseInt(Number(p.topics[3])));yield tt(n,_,{walletAddress:y,transactionHash:R.hash,chainId:r,counterValue:a,price:o,priceUnit:d,tokens:O.length>0?O:Array.from(Array(a).keys()),signature:s}),C("completed")}catch(s){console.log(s),s.reason?V({title:"Failed to mint",description:s.reason,status:"error",duration:5e3}):V({title:"Failed to mint",description:s.message,status:"error",duration:5e3});let h=s!=null&&s.reason?s==null?void 0:s.reason:s==null?void 0:s.message,K={errorLog:JSON.stringify({account:y,error:h})};h.includes("user rejected transaction")?C("start"):(C("error"),et(n,_,K))}finally{g(!1)}}),[F,y,a,c,o,r,n,_]);return{selectedStage:c,changeSelectedStage:vt,displayConfig:X,counterValue:a,setCounterValue:m,initiateMint:Pt,loading:i,mintStatus:I,mintedTx:k,stagesCompleted:$}},Ot=Ft;
