import{o as e}from"./rolldown-runtime.js";import{n as t}from"./jsx-runtime.js";import{Tt as n,Vt as r,nr as i}from"./useActiveWallet-CEs8euQ3.js";var a=e(t(),1),o=class extends Error{constructor(){super(`Back navigation`),this.name=`BackNavigationError`}},s=n((()=>null)),c=e=>{s.getState()!==null&&s.setState(e)};async function l(e,t){let n=await e.fetchPrivyRoute(i,{}),r={config:{status:`ready`,data:{currencies:n.currencies,chains:n.chains}}};t?.aborted||c(r)}function u(){let e=s(),{closePrivyModal:t,privy:n}=r(),i=e?.params??null,o=e?.config??{status:`loading`},u=(0,a.useCallback)((e=>{c({modalState:e})}),[]),d=(0,a.useCallback)((async()=>{let t=e?.controller;if(i&&t&&!t.signal.aborted){c({config:{status:`loading`}});try{await l(n,t.signal)}catch(e){if(t.signal.aborted)return;throw c({config:{status:`error`,error:e instanceof Error?e:Error(`Failed to load deposit config`)}}),e}}}),[i,n,e?.controller]),f=(0,a.useCallback)((()=>{if(!e)return;let{modalState:n}=e;n.step===`complete`?e.onComplete():n.step===`failed`?e.onError(Error(`DEPOSIT_FAILED`)):n.step===`error`?e.onError(Error(n.code)):n.step===`refunded`?e.onError(Error(`DEPOSIT_REFUNDED`)):e.onError(Error(`USER_EXITED`)),t({shouldCallAuthOnSuccess:!1})}),[e,t]);return{modalState:e?.modalState??{step:`intro`},setModalState:u,config:o,retryConfig:d,params:i,close:f,onBack:e?.onBack}}function d(e){let{modalState:t,config:n,params:r,...i}=u();if(function(e,t){if(e.step!==t)throw Error(`UNEXPECTED_STATE`)}(t,e),!r||n.status!==`ready`)throw Error(`UNEXPECTED_STATE`);return{state:t,configData:n.data,params:r,...i}}export{u as i,d as n,o as r,s as t};