import{ad as I,K as x,a9 as y,au as C,as as S,b7 as T,aB as B}from"./api-Jrm0STwN.js";import{aB as E,aC as F,W as N,X as k,w as D,D as O}from"./notifications-DcCGONtY.js";class R extends I{constructor(a){super(`Call bundle failed with status: ${a.statusCode}`,{name:"BundleFailedError"}),Object.defineProperty(this,"result",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.result=a}}const W="0x5792579257925792579257925792579257925792579257925792579257925792",j=x(0,{size:32});async function M(r,a){async function o(e){if(e.endsWith(W.slice(2))){const d=S(T(e,-64,-32)),l=T(e,0,-64).slice(2).match(/.{1,64}/g),n=await Promise.all(l.map(t=>j.slice(2)!==t?r.request({method:"eth_getTransactionReceipt",params:[`0x${t}`]},{dedupe:!0}):void 0)),s=n.some(t=>t===null)?100:n.every(t=>t?.status==="0x1")?200:n.every(t=>t?.status==="0x0")?500:600;return{atomic:!1,chainId:y(d),receipts:n.filter(Boolean),status:s,version:"2.0.0"}}return r.request({method:"wallet_getCallsStatus",params:[e]})}const{atomic:f=!1,chainId:c,receipts:m,version:p="2.0.0",...u}=await o(a.id),[h,w]=(()=>{const e=u.status;return e>=100&&e<200?["pending",e]:e>=200&&e<300?["success",e]:e>=300&&e<700?["failure",e]:e==="CONFIRMED"?["success",200]:e==="PENDING"?["pending",100]:[void 0,e]})();return{...u,atomic:f,chainId:c?y(c):void 0,receipts:m?.map(e=>({...e,blockNumber:C(e.blockNumber),gasUsed:C(e.gasUsed),status:E[e.status]}))??[],statusCode:w,status:h,version:p}}async function q(r,a){const{id:o,pollingInterval:f=r.pollingInterval,status:c=({statusCode:s})=>s===200||s>=300,retryCount:m=4,retryDelay:p=({count:s})=>~~(1<<s)*200,timeout:u=6e4,throwOnFailure:h=!1}=a,w=B(["waitForCallsStatus",r.uid,o]),{promise:e,resolve:b,reject:d}=F();let l;const n=N(w,{resolve:b,reject:d},s=>{const t=k(async()=>{const v=i=>{clearTimeout(l),t(),i(),n()};try{const i=await D(async()=>{const g=await O(r,M,"getCallsStatus")({id:o});if(h&&g.status==="failure")throw new R(g);return g},{retryCount:m,delay:p});if(!c(i))return;v(()=>s.resolve(i))}catch(i){v(()=>s.reject(i))}},{interval:f,emitOnBegin:!0});return t});return l=u?setTimeout(()=>{n(),clearTimeout(l),d(new P({id:o}))},u):void 0,await e}class P extends I{constructor({id:a}){super(`Timed out while waiting for call bundle with id "${a}" to be confirmed.`,{name:"WaitForCallsStatusTimeoutError"})}}export{q as w};
