import"react";import y from"axios";import{createContext as f,useMemo as X}from"react";import{jsx as R}from"react/jsx-runtime";var N=f(void 0),p="production";var u=p==="development"?"https://qa-api-v2.bandit.network/sdk":"https://api-v2.bandit.network/sdk";var c=async(e,t)=>{try{return(await y.get(`${u}/users/${e}`,{headers:{"X-API-KEY":t}})).data}catch(o){throw new Error(o)}};import{useDispatch as I,useSelector as U}from"react-redux";import{useEffect as x,useState as A}from"react";import{AppConfig as S,UserSession as g}from"@stacks/connect";var P=()=>{let[e,t]=A(""),o=new S(["store_write","publish_data"]),a=new g({appConfig:o}),n=()=>{a.signUserOut(),t("")};return x(()=>{if(a)try{let r=a.loadUserData();t(r.profile.stxAddress.testnet)}catch{}},[a]),{stacksAddress:e,userSession:a,disconnectStacks:n}},h=P;import{useWeb3React as b}from"@web3-react/core";import{useWallet as v}from"@solana/wallet-adapter-react";import{createSlice as k}from"@reduxjs/toolkit";var K={selectedWallet:void 0,selectedSolanaWallet:void 0,accessKey:null,details:{}},w=k({name:"user",initialState:K,reducers:{updateSelectedWallet(e,{payload:{wallet:t}}){e.selectedWallet=t},updateSolanaSelectedWallet(e,{payload:{wallet:t}}){e.selectedSolanaWallet=t},updateAccessKey(e,{payload:{accessKey:t}}){e.accessKey=t},updateUserDetails(e,{payload:{details:t}}){e.details=t}}}),{updateSelectedWallet:j,updateSolanaSelectedWallet:tt,updateAccessKey:et,updateUserDetails:d}=w.actions,ot=w.reducer;var E=()=>{let{selectedWallet:e,accessKey:t,details:o={}}=U(s=>s.user),{stacksAddress:a}=h(),{account:n}=b(),{publicKey:r,disconnect:$}=v(),i=I();return{user:o,fetchUser:async()=>{try{let s=r?r.toBase58():"",l=e==="stacks"?a:e==="Phantom"?s:n;if(o?.walletAddress?.toLowerCase()===l?.toLowerCase())return;let m=await c(l,t);i(d({details:m}))}catch(s){console.log(s)}},refreshUser:async()=>{try{if(!o.walletAddress)return;let s=await c(o.walletAddress,t);i(d({details:s}))}catch(s){console.log(s)}}}},ut=E;export{ut as default};
