import{o as e}from"./rolldown-runtime.js";import{n as t}from"./jsx-runtime.js";import{_t as n,xt as r}from"./useActiveWallet-CEs8euQ3.js";var i=e(t(),1),a=792703809,o=`11111111111111111111111111111111`,s=`EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v`,c=`0x0000000000000000000000000000000000000000`,l=({appId:e,originCurrency:t,destinationCurrency:n,...r})=>({tradeType:`EXPECTED_OUTPUT`,originCurrency:t??c,destinationCurrency:n??c,referrer:`privy|${e}`,...r}),u=`https://api.relay.link`,d=`https://api.testnets.relay.link`,f=async({input:e,isTestnet:t})=>{let n=await fetch((t?d:u)+`/quote`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)}),r=await n.json();if(!(n.ok||typeof r.message==`string`&&r.message.startsWith(`Invalid address`)))throw console.error(`Relay error:`,r),Error(r.message??`Error fetching quote from relay`);return r},p=e=>{let t=e.steps[0]?.items?.[0];if(t)return{from:t.data.from,to:t.data.to,value:Number(t.data.value),chainId:Number(t.data.chainId),data:t.data.data}},m=e=>e.steps.flatMap((e=>e.items?.filter((e=>e.status===`incomplete`))??[])).map((e=>({from:e.data.from,to:e.data.to,value:Number(e.data.value),chainId:Number(e.data.chainId),data:e.data.data})));async function h({transactionHash:e,isTestnet:t}){let n=await fetch((t?d:u)+`/requests/v2?hash=`+e),r=await n.json();if(!n.ok)throw`message`in r&&typeof r.message==`string`?Error(r.message):Error(`Error fetching request from relay`);return r.requests.at(0)?.status??`pending`}function g({transactionHash:e,isTestnet:t,bridgingStatus:n,setBridgingStatus:r,onSuccess:a,onFailure:o}){(0,i.useEffect)((()=>{if(e&&n){if([`delayed`,`waiting`,`pending`].includes(n)){let n=setInterval((async()=>{try{r(await h({transactionHash:e,isTestnet:t}))}catch(e){console.error(e)}}),1e3);return()=>clearInterval(n)}n===`success`?a({transactionHash:e}):[`refund`,`failure`].includes(n)&&o({error:new _(e,t)})}}),[n,e,t])}var _=class extends r{constructor(e,t){super(`We were unable to complete the bridging transaction. Funds will be refunded on your wallet.`,void 0,n.TRANSACTION_FAILURE),this.relayLink=t?`https://testnets.relay.link/transaction/${e}`:`https://relay.link/transaction/${e}`}};export{s as a,o as c,_ as i,p as l,g as n,l as o,f as r,a as s,m as t};