import{ofetch as e}from"ofetch";import{useState as t,useRef as n,useEffect as a}from"react";import{M as r,w as o,x as u,y as i}from"./context-BKnOUECq.mjs";import{u as s}from"./internal-context-dfitw7Ot.mjs";import{u as d}from"./modal-context-DBwfUxD-.mjs";import{O as c}from"./analytics-mkkvFRju.mjs";const m="moonpay";function l(e){return parseFloat(e)}function y(l,y=!1){let[f,p]=t(null),{createAnalyticsEvent:g}=s(),{data:h,navigate:v,setModalData:A}=d(),F=h?.funding,w=n(0);return a((()=>{let t=setInterval((async()=>{if(l)try{let[n]=await async function(t,n){return e(`${n?r:o}/transactions/ext/${t}`,{query:{apiKey:n?u:i}})}(l,y),a="waitingAuthorization"===n.status&&"credit_debit_card"===n.paymentMethod?"pending":n.status;if(["failed","completed","awaitingAuthorization"].includes(a)&&(g({eventName:c,payload:{status:a,provider:m,paymentMethod:n.paymentMethod,cardPaymentType:n.cardPaymentType,currency:n.currency?.code,baseCurrencyAmount:n.baseCurrencyAmount,quoteCurrencyAmount:n.quoteCurrencyAmount,feeAmount:n.feeAmount,extraFeeAmount:n.extraFeeAmount,networkFeeAmount:n.networkFeeAmount,isSandbox:y}}),clearInterval(t)),"failed"===a||"serviceFailure"===a)return A({funding:{...F,errorMessage:"Something went wrong adding funds from Moonpay. Please try again or use another method to fund your wallet."},solanaFundingData:h?.solanaFundingData}),void v("FundingMethodSelectionScreen");p(a)}catch(e){404!==e.response?.status&&(w.current+=1),w.current>=3&&(g({eventName:c,payload:{status:"serviceFailure",provider:m}}),clearInterval(t),A({funding:{...F,errorMessage:"Something went wrong adding funds from Moonpay. Please try again or use another method to fund your wallet."},solanaFundingData:h?.solanaFundingData}),v("FundingMethodSelectionScreen"))}}),3e3);return()=>clearInterval(t)}),[l,w]),f}export{l as a,y as u};
//# sourceMappingURL=index-DuSdaxpe.mjs.map
