var i=(e,t,o)=>new Promise((a,c)=>{var n=s=>{try{d(o.next(s))}catch(l){c(l)}},m=s=>{try{d(o.throw(s))}catch(l){c(l)}},d=s=>s.done?a(s.value):Promise.resolve(s.value).then(n,m);d((o=o.apply(e,t)).next())});import"react";import P from"axios";import{createContext as k,useMemo as R}from"react";import{jsx as T}from"react/jsx-runtime";var B=k(void 0),f="production";var y=f==="development"?"https://qa-api-v2.bandit.network/sdk":"https://api-v2.bandit.network/sdk";var h=(e,t)=>i(void 0,null,function*(){try{return(yield P.get(`${y}/users/${e}`,{headers:{"X-API-KEY":t}})).data}catch(o){throw new Error(o)}});import{useDispatch as $,useSelector as C}from"react-redux";import{useEffect as g,useState as K}from"react";import{AppConfig as b,UserSession as v}from"@stacks/connect";var I=()=>{let[e,t]=K(""),o=new b(["store_write","publish_data"]),a=new v({appConfig:o}),c=()=>{a.signUserOut(),t("")};return g(()=>{if(a)try{let n=a.loadUserData();t(n.profile.stxAddress.testnet)}catch(n){}},[a]),{stacksAddress:e,userSession:a,disconnectStacks:c}},x=I;import{useWeb3React as D}from"@web3-react/core";import{useWallet as W}from"@solana/wallet-adapter-react";import{createSlice as U}from"@reduxjs/toolkit";var E={selectedWallet:void 0,selectedSolanaWallet:void 0,accessKey:null,details:{}},S=U({name:"user",initialState:E,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:at,updateSolanaSelectedWallet:st,updateAccessKey:rt,updateUserDetails:w}=S.actions,nt=S.reducer;var Y=()=>{let{selectedWallet:e,accessKey:t,details:o={}}=C(r=>r.user),{stacksAddress:a}=x(),{account:c}=D(),{publicKey:n,disconnect:m}=W(),d=$();return{user:o,fetchUser:()=>i(void 0,null,function*(){var r;try{let u=n?n.toBase58():"",p=e==="stacks"?a:e==="Phantom"?u:c;if(((r=o==null?void 0:o.walletAddress)==null?void 0:r.toLowerCase())===(p==null?void 0:p.toLowerCase()))return;let A=yield h(p,t);d(w({details:A}))}catch(u){console.log(u)}}),refreshUser:()=>i(void 0,null,function*(){try{if(!o.walletAddress)return;let r=yield h(o.walletAddress,t);d(w({details:r}))}catch(r){console.log(r)}})}},ft=Y;export{ft as default};
