import{o as e}from"./rolldown-runtime.js";import{n as t}from"./jsx-runtime.js";import{Vt as n}from"./useActiveWallet-CEs8euQ3.js";import{F as r,O as i,f as a,u as o}from"./context-Cdw68BC2.js";import{t as s}from"./dist2.js";import{t as c}from"./modal-context-DHfp-mFQ.js";import"./analytics-mkkvFRju.js";var l=e(t(),1),u=`moonpay`;function d(e){return parseFloat(e)}function f(e,t=!1){let[d,f]=(0,l.useState)(null),{createAnalyticsEvent:p}=n(),{data:m,navigate:h,setModalData:g}=c(),_=m?.funding,v=(0,l.useRef)(0);return(0,l.useEffect)((()=>{let n=setInterval((async()=>{if(e)try{let[c]=await async function(e,t){return s(`${t?o:a}/transactions/ext/${e}`,{query:{apiKey:t?r:i}})}(e,t),l=c.status===`waitingAuthorization`&&c.paymentMethod===`credit_debit_card`?`pending`:c.status;if([`failed`,`completed`,`awaitingAuthorization`].includes(l)&&(p({eventName:`sdk_fiat_on_ramp_completed_with_status`,payload:{status:l,provider:u,paymentMethod:c.paymentMethod,cardPaymentType:c.cardPaymentType,currency:c.currency?.code,baseCurrencyAmount:c.baseCurrencyAmount,quoteCurrencyAmount:c.quoteCurrencyAmount,feeAmount:c.feeAmount,extraFeeAmount:c.extraFeeAmount,networkFeeAmount:c.networkFeeAmount,isSandbox:t}}),clearInterval(n)),l===`failed`||l===`serviceFailure`)return g({funding:{..._,errorMessage:`Something went wrong adding funds from Moonpay. Please try again or use another method to fund your wallet.`},solanaFundingData:m?.solanaFundingData}),void h(`FundingMethodSelectionScreen`);f(l)}catch(e){e.response?.status!==404&&(v.current+=1),v.current>=3&&(p({eventName:`sdk_fiat_on_ramp_completed_with_status`,payload:{status:`serviceFailure`,provider:u}}),clearInterval(n),g({funding:{..._,errorMessage:`Something went wrong adding funds from Moonpay. Please try again or use another method to fund your wallet.`},solanaFundingData:m?.solanaFundingData}),h(`FundingMethodSelectionScreen`))}}),3e3);return()=>clearInterval(n)}),[e,v]),d}export{f as n,d as t};