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