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