import{d as b,e as E,h as k}from"./wallets-C7O8bt0K.js";import"./thirdweb-Co3M1EyP.js";import"./store-CraP4F4Y.js";import"./ui-BJj_Hssx.js";import"./vendor-64qtqz3S.js";import"./index-BNXDN8h1.js";import"./index-DSskmJfT.js";import"./index-DnKfU2ei.js";import"./index-nibyPLVP.js";import"./ethereum-Csz0KDPf.js";async function K(i){var r,p;const{wallet:t,walletConnectClient:e,event:a,chains:n,onConnect:m}=i,d=t.getAccount();if(!d)throw new Error("No account connected to provided wallet");const o=(p=(r=a.verifyContext)==null?void 0:r.verified)==null?void 0:p.origin;o&&await A({origin:o,walletConnectClient:e});const s=await W({account:d,chains:n,sessionProposal:a,walletConnectClient:e});await b(s),t.subscribe("disconnect",()=>{E({session:s,walletConnectClient:e})}),m==null||m(s)}async function A({walletConnectClient:i,origin:t}){const e=await k();for(const a of e)a.origin===t&&await E({session:a,walletConnectClient:i})}async function W({account:i,walletConnectClient:t,sessionProposal:e,chains:a}){var o,s,r,p,w,f,v,l,u,g,N,h,S,y,$,C,q,x;if(!((o=e.params.requiredNamespaces)!=null&&o.eip155)&&!((s=e.params.optionalNamespaces)!=null&&s.eip155))throw new Error("No EIP155 namespace found in Wallet Connect session proposal");const n={chains:[...Array.from(new Set([...((w=(p=(r=e.params.requiredNamespaces)==null?void 0:r.eip155)==null?void 0:p.chains)==null?void 0:w.map(c=>`${c}:${i.address}`))??[],...((l=(v=(f=e.params.optionalNamespaces)==null?void 0:f.eip155)==null?void 0:v.chains)==null?void 0:l.map(c=>`${c}:${i.address}`))??[],...(a==null?void 0:a.map(c=>`eip155:${c.id}:${i.address}`))??[]]))],events:[...((g=(u=e.params.requiredNamespaces)==null?void 0:u.eip155)==null?void 0:g.events)??[],...((h=(N=e.params.optionalNamespaces)==null?void 0:N.eip155)==null?void 0:h.events)??[]],methods:[...((y=(S=e.params.requiredNamespaces)==null?void 0:S.eip155)==null?void 0:y.methods)??[],...((C=($=e.params.optionalNamespaces)==null?void 0:$.eip155)==null?void 0:C.methods)??[]]},d=await(await t.approve({id:e.id,namespaces:{eip155:{accounts:n.chains,events:n.events,methods:n.methods}}})).acknowledged();return{origin:((x=(q=e.verifyContext)==null?void 0:q.verified)==null?void 0:x.origin)||"Unknown origin",topic:d.topic}}export{W as acceptSessionProposal,A as disconnectExistingSessions,K as onSessionProposal};
