import{o as e}from"./rolldown-runtime.js";import{n as t,t as n}from"./jsx-runtime.js";import{M as r,Qt as i,Vt as a,dn as o,j as s}from"./useActiveWallet-CEs8euQ3.js";import{k as c}from"./context-Cdw68BC2.js";import{g as l}from"./_esm.js";import{D as u,I as d}from"./index-CKYEOQWW.js";import{a as f}from"./index-CnFVexq_.js";import{o as p}from"./get-entropy-details-for-user-Bq7nAeEf.js";import{t as m}from"./modal-context-DHfp-mFQ.js";import{l as h,u as g}from"./ModalHeader-BS54PZSj.js";import{t as _}from"./InfoBanner-DkQEPd77.js";import{n as v,t as y}from"./QrCode-BVnyWVuE.js";import{r as b}from"./Layouts-BlFm53ED.js";import{t as x}from"./FundWalletMethodHeader-Doi39iuD.js";import"./analytics-mkkvFRju.js";import{t as S}from"./getChainName-DjpPdUSc.js";import{n as C}from"./transaction-CnfuREWo.js";import{t as w}from"./getErc20Balance-DHgWH7_1.js";import{t as T}from"./Subtitle-CV-2yKE4.js";import{t as E}from"./Title-BnzYV3Is.js";import{t as D}from"./WalletInfoCard-BQqwW2nb.js";import{t as O}from"./getUsdcMintAddress-DFI1hv05.js";import{t as k}from"./useWalletBalance-D47dI-xh.js";var A=n(),j=e(t(),1);v(),s();var M={component:()=>{let{wallets:e}=p(),{connectors:t}=a(),n=t.filter(f).flatMap((e=>e.wallets)),{data:s,setModalData:u,navigate:v,lastScreen:M}=m(),{rpcConfig:P,appId:F,createAnalyticsEvent:I,closePrivyModal:L}=a(),R=c(),[z,B]=(0,j.useState)(void 0),[V,H]=(0,j.useState)(!1),U=s?.funding,{reloadBalance:W}=k({rpcConfig:P,appId:F,address:U.chainType===`ethereum`?U.address:void 0,chain:U.chainType===`ethereum`?U.chain:void 0}),G=U.chainType===`solana`,K=G?U.isUSDC?`USDC`:`SOL`:U.erc20Address?U.erc20ContractInfo?.symbol:U.chain.nativeCurrency.symbol,q=G?n.find((({address:e})=>e===U.address)):e.find((({address:e})=>r(e)===r(U.address)));if(!U)return u({errorModalData:{error:Error(`Couldn't find funding config`),previousScreen:M||`FundingMethodSelectionScreen`},funding:s?.funding,solanaFundingData:s?.solanaFundingData,sendTransaction:s?.sendTransaction}),v(`ErrorScreen`),(0,A.jsx)(A.Fragment,{});(0,j.useEffect)((()=>{let e=G?async function(){if(U.chainType!==`solana`)return;let e=R.solanaRpcs[U.chain];e?(U.isUSDC?async function({rpc:e,address:t,mintAddress:n}){let r=(await e.getTokenAccountsByOwner(t,{mint:n},{encoding:`jsonParsed`,commitment:`confirmed`}).send()).value[0]?.account;return r?BigInt(r.data.parsed.info.tokenAmount.amount):0n}({rpc:e.rpc,address:U.address,mintAddress:O(U.chain)}):d({rpc:e.rpc,address:U.address})).then((e=>{let t=BigInt(e);z&&t>z&&(H(!0),I({eventName:`sdk_fiat_on_ramp_completed_with_status`,payload:{provider:`manual`,status:`success`,chainType:`solana`,address:q?.address,value:U.isUSDC?l(t-z,6):l(t-z,9),token:U.isUSDC?`USDC`:`SOL`}})),B(t)})):console.warn(`Unable to load solana rpc, skipping balance`)}:async function(){U.chainType===`ethereum`&&(async()=>{if(!U.erc20Address)return await W()??BigInt(0);{let{balance:e}=await w({chain:U.chain,address:U.address,erc20Address:U.erc20Address,rpcConfig:P,appId:F});return e}})().then((e=>{z&&e>z&&(H(!0),I({eventName:`sdk_fiat_on_ramp_completed_with_status`,payload:{provider:`manual`,status:`success`,chainType:`ethereum`,address:q?.address,chainId:U.chain.id,value:l(e-z,U.erc20ContractInfo?.decimals??18),token:U.erc20ContractInfo?.symbol??U.erc20Address??`ETH`}})),B(e)})).catch((()=>B(void 0)))},t=setInterval(e,2e3);return e(),()=>clearInterval(t)}),[z]);let J=(0,j.useMemo)((()=>z==null?``:U.isUSDC?i({amount:z,decimals:6}):G?C(z,3,!0,!0):U.erc20ContractInfo?.decimals==null?o({wei:z}):i({amount:z,decimals:U.erc20ContractInfo.decimals})),[z,G,U]),Y=U.chainType===`ethereum`?U.chain.name:S(U.chain),X=(0,j.useMemo)((()=>U.uiConfig?.receiveFundsTitle===``?null:(0,A.jsx)(E,{children:U.uiConfig?.receiveFundsTitle??`Receive ${U.amount} ${K??``}`.trim()})),[U.uiConfig?.receiveFundsTitle,U.amount,K]),Z=(0,j.useMemo)((()=>U.uiConfig?.receiveFundsSubtitle===``?null:(0,A.jsx)(T,{children:U.uiConfig?.receiveFundsSubtitle??`Scan this code or copy your wallet address to receive funds on ${Y}.`})),[U.uiConfig?.receiveFundsSubtitle,Y]),Q=U.chainType===`solana`&&U.isUSDC&&O(U.chain)?`?spl-token=${O(U.chain)}`:``;return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(x,{}),X,Z,(0,A.jsxs)(b,{style:{gap:`1rem`,margin:X||Z?`1rem 0`:`0`},children:[(0,A.jsx)(y,{url:`${U.chainType}:${U.address}${Q}`,size:200,squareLogoElement:N}),(0,A.jsxs)(_,{theme:R.appearance.palette.colorScheme,children:[`Make sure to send funds on `,Y,`.`]}),(0,A.jsx)(D,{title:`Your wallet`,errMsg:void 0,showCopyButton:!0,balance:`${J} ${K}`,address:U.address}),V&&(0,A.jsx)(h,{onClick:()=>L({shouldCallAuthOnSuccess:!1,isSuccess:!0}),children:`Continue`})]}),(0,A.jsx)(g,{})]})}},N=({...e})=>(0,A.jsx)(u,{color:`black`,...e});export{M as ManualTransferScreen,M as default};