import{d as h}from"./index-CTmS80s7.js";import{S as C,d as y}from"./sdk-DZg3RS7_.js";import{e,c as S,B as A,E as p,P as c,i as l,w as g,f as I,b as x}from"./index-CKWbC5RE.js";import"./index-0uv1nYe7.js";import"./ripemd160-C3LwxVio.js";import"./sha256-Dhuv4FAU.js";function E(v={}){const{shimDisconnect:d=!1}=v;let n,a;return S(s=>{const u=new A([]),o=new C,r=async()=>{if(l()){if(!n){const t=await g(()=>o.safe.getInfo(),{timeout:10});if(!t)throw new Error("Could not load Safe information");n=new h.SafeAppProvider(t,o)}return n}};return{id:e.id,name:e.name,type:e.type,async connect(t){const f=await r();if(!f)throw new c;const m=await this.getAccounts(),w=await this.getChainId();return u.next(x.fromNullable(s.chains.find(i=>i.id===w)).map(i=>[i]).orDefault([])),a||(a=this.onDisconnect.bind(this),f.on("disconnect",a)),d&&await s.storage?.removeItem("safe.disconnected"),{accounts:t?.withCapabilities?m.map(i=>({address:i,capabilities:{}})):m,chainId:w}},async disconnect(){const t=await r();if(!t)throw new c;a&&(t.removeListener("disconnect",a),a=void 0),d&&await s.storage?.setItem("safe.disconnected",!0)},async getAccounts(){const t=await r();if(!t)throw new c;return(await t.request({method:"eth_accounts"})).map(I)},async getProvider(){if(l()){if(!n){const t=await g(()=>o.safe.getInfo(),{timeout:10});if(!t)throw new Error("Could not load Safe information");n=new h.SafeAppProvider(t,o)}return n}},async getChainId(){const t=await r();if(!t)throw new c;return Number(t.chainId)},async isAuthorized(){try{return d&&await s.storage?.getItem("safe.disconnected")?!1:!!(await this.getAccounts()).length}catch{return!1}},onAccountsChanged(){},onChainChanged(){},onDisconnect(){s.emitter.emit("disconnect")},$filteredChains:u,getTxStatus(t){return p(()=>o.txs.getBySafeTxHash(t)).mapLeft(()=>new Error("Could not get transaction status"))},txStatus:y.TransactionStatus,sendTransactions(t){return p(()=>o.txs.send(t)).mapLeft(()=>new Error("Could not send transactions"))}}})}const L=()=>({groupName:"Safe Wallet",wallets:[()=>({id:e.id,name:e.name,iconUrl:"",iconBackground:"#fff",chainGroup:{id:e.id,title:e.name,iconUrl:""},createConnector:()=>E({shimDisconnect:!0})})]});export{L as safeConnector};
