var c=(t,n,e)=>new Promise((a,i)=>{var p=s=>{try{m(e.next(s))}catch(u){i(u)}},o=s=>{try{m(e.throw(s))}catch(u){i(u)}},m=s=>s.done?a(s.value):Promise.resolve(s.value).then(p,o);m((e=e.apply(t,n)).next())});import{useEffect as x,useState as E}from"react";import{hexlify as R}from"@ethersproject/bytes";import{toUtf8Bytes as _}from"@ethersproject/strings";var y=(t,n,e)=>c(void 0,null,function*(){var a,i;if((a=t.provider)!=null&&a.wc){let p=R(_(e));return yield(i=t.provider)==null?void 0:i.wc.signPersonalMessage([p,n])}return t.getSigner(n).signMessage(e)});var C="CONNECTOR_ID",d="SIGNATURE";import{decodeUTF8 as U}from"tweetnacl-util";import{useWallet as V}from"@solana/wallet-adapter-react";import*as P from"bs58";import{useEffect as D,useRef as K}from"react";var T=t=>{let n=K();return D(()=>{n.current=t},[t]),n.current},I=T;import{useWeb3React as X}from"@web3-react/core";import{useToast as W}from"@chakra-ui/react";import{useSelector as F}from"react-redux";import B from"axios";import{createContext as O,useMemo as st}from"react";import{jsx as ut}from"react/jsx-runtime";var ct=O(void 0),v="production";var h=v==="development"?"https://qa-api-v2.bandit.network/sdk":"https://api-v2.bandit.network/sdk";var w=(t,n)=>c(void 0,null,function*(){try{return(yield B.post(`${h}/users/getNonce`,{walletAddress:t},{headers:{"X-API-KEY":n}})).data}catch(e){throw new Error(e)}});import{useContext as Y}from"react";import{createContext as M,useCallback as Kt,useEffect as Tt,useState as Ot}from"react";import Ct from"axios";import{jsx as Et,jsxs as Pt}from"react/jsx-runtime";import{jsx as Ut}from"react/jsx-runtime";var b=M(void 0);var S=()=>Y(b);var L=()=>{let t=V(),n=W(),[e,a]=E(null),[i,p]=E(null),{account:o,provider:m}=X(),{accessKey:s}=S(),u=F(r=>r.user.selectedWallet),k=I(o);return x(()=>{let r=localStorage.getItem(d);a(r),p(u)},[o,t.connected,u]),x(()=>{let r=localStorage.getItem(C);!o&&!r&&(localStorage.removeItem(d),a(null))},[o]),x(()=>{o&&o!==k&&(localStorage.removeItem(d),a(null))},[o]),[e,i==="Phantom"?()=>c(void 0,null,function*(){var r,l;if(e)return e;try{let{nonce:g}=yield w((r=t==null?void 0:t.publicKey)==null?void 0:r.toBase58(),s),A=t&&`Verify your account: ${(l=t==null?void 0:t.publicKey)==null?void 0:l.toBase58()}
Nonce: ${g}`,N=U(A),$=t&&(yield t==null?void 0:t.signMessage(N)),f=P.encode($);return localStorage.setItem(d,f),a(f),f}catch(g){throw g}}):()=>c(void 0,null,function*(){if(e)return e;try{let{nonce:r}=yield w(o,s),l=yield y(m,o,`Verify your account: ${o}
Nonce: ${r}`);return localStorage.setItem(d,l),a(l),l}catch(r){throw r}})]},ae=L;export{ae as default};
