"use strict";var e=require("ofetch"),t=require("react"),n=require("./context-rs-ygOK2.js"),a=require("./internal-context-CdsQ3LEl.js"),r=require("./modal-context-BgeioxwT.js"),o=require("./analytics-C6C_4JmG.js");const u="moonpay";exports.amountToMoonpayAmount=function(e){return parseFloat(e)},exports.usePollMoonpayTransactionStatus=function(i,s=!1){let[c,d]=t.useState(null),{createAnalyticsEvent:l}=a.usePrivyInternal(),{data:y,navigate:m,setModalData:A}=r.usePrivyModal(),f=y?.funding,g=t.useRef(0);return t.useEffect((()=>{let t=setInterval((async()=>{if(i)try{let[a]=await async function(t,a){return e.ofetch(`${a?n.MOONPAY_API_URL_SANDBOX:n.MOONPAY_API_URL}/transactions/ext/${t}`,{query:{apiKey:a?n.MOONPAY_PUBLIC_KEY_SANDBOX:n.MOONPAY_PUBLIC_KEY}})}(i,s),r="waitingAuthorization"===a.status&&"credit_debit_card"===a.paymentMethod?"pending":a.status;if(["failed","completed","awaitingAuthorization"].includes(r)&&(l({eventName:o.ON_RAMP_COMPLETE_ANALYTICS_EVENT,payload:{status:r,provider:u,paymentMethod:a.paymentMethod,cardPaymentType:a.cardPaymentType,currency:a.currency?.code,baseCurrencyAmount:a.baseCurrencyAmount,quoteCurrencyAmount:a.quoteCurrencyAmount,feeAmount:a.feeAmount,extraFeeAmount:a.extraFeeAmount,networkFeeAmount:a.networkFeeAmount,isSandbox:s}}),clearInterval(t)),"failed"===r||"serviceFailure"===r)return A({funding:{...f,errorMessage:"Something went wrong adding funds from Moonpay. Please try again or use another method to fund your wallet."},solanaFundingData:y?.solanaFundingData}),void m("FundingMethodSelectionScreen");d(r)}catch(e){404!==e.response?.status&&(g.current+=1),g.current>=3&&(l({eventName:o.ON_RAMP_COMPLETE_ANALYTICS_EVENT,payload:{status:"serviceFailure",provider:u}}),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:y?.solanaFundingData}),m("FundingMethodSelectionScreen"))}}),3e3);return()=>clearInterval(t)}),[i,g]),c};
//# sourceMappingURL=index-DwAz3ZnR.js.map
