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