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