"use strict";var t=require("react"),e=require("./errors-CBapWvRs.js");let r="0x0000000000000000000000000000000000000000";let a="https://api.relay.link",s="https://api.testnets.relay.link";async function n({transactionHash:t,isTestnet:e}){let r=await fetch((e?s:a)+"/requests/v2?hash="+t),n=await r.json();if(!r.ok){if("message"in n&&"string"==typeof n.message)throw Error(n.message);throw Error("Error fetching request from relay")}return n.requests.at(0)?.status??"pending"}class o extends e.PrivyClientError{constructor(t,r){super("We were unable to complete the bridging transaction. Funds will be refunded on your wallet.",void 0,e.PrivyErrorCode.TRANSACTION_FAILURE),this.relayLink=r?`https://testnets.relay.link/transaction/${t}`:`https://relay.link/transaction/${t}`}}exports.RELAY_SOLANA_MAINNET_CHAIN_ID=792703809,exports.RELAY_SOLANA_NATIVE_CURRENCY_ID="11111111111111111111111111111111",exports.RELAY_SOLANA_USDC_TOKEN_ID="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",exports.RelayRequestError=o,exports.getAllIncompleteEvmTransactionStepsFromQuote=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}))),exports.getQuote=async({input:t,isTestnet:e})=>{let r=await fetch((e?s:a)+"/quote",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json();if(!(r.ok||"string"==typeof n.message&&n.message.startsWith("Invalid address")))throw console.error("Relay error:",n),Error(n.message??"Error fetching quote from relay");return n},exports.toEvmTransactionRequestInfoFromQuote=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}},exports.toGetQuoteInput=({appId:t,originCurrency:e,destinationCurrency:a,...s})=>({tradeType:"EXPECTED_OUTPUT",originCurrency:e??r,destinationCurrency:a??r,referrer:`privy|${t}`,...s}),exports.useBridgingStatusPolling=function({transactionHash:e,isTestnet:r,bridgingStatus:a,setBridgingStatus:s,onSuccess:i,onFailure:u}){t.useEffect((()=>{if(e&&a){if(["delayed","waiting","pending"].includes(a)){let t=setInterval((async()=>{try{let t=await n({transactionHash:e,isTestnet:r});s(t)}catch(t){console.error(t)}}),1e3);return()=>clearInterval(t)}"success"===a?i({transactionHash:e}):["refund","failure"].includes(a)&&u({error:new o(e,r)})}}),[a,e,r])};
//# sourceMappingURL=reservoir-CfS214MF.js.map
