import{jsxs as e,jsx as t,Fragment as n}from"react/jsx-runtime";import{useState as a,useMemo as s,useCallback as i,useEffect as o}from"react";import{createPublicClient as r,http as p,toHex as l,decodeFunctionData as u,decodeAbiParameters as m,formatEther as c}from"viem";import{getJsonRpcEndpointFromChain as d,formatTokenAmount as y,ProviderErrors as f}from"@privy-io/js-sdk-core";import{A as b}from"./Address-BOC18tYY.mjs";import{u as T,r as h}from"./context-BKnOUECq.mjs";import{P as g,d as v,z as I}from"./wallet-connect-58EobR5U.mjs";import{u as k}from"./internal-context-dfitw7Ot.mjs";import{u as j}from"./modal-context-DBwfUxD-.mjs";import{u as E}from"./privy-context-Bi6vqCPc.mjs";import{u as M}from"./useGetTokenPrice-ENX-6s3C.mjs";import{u as C}from"./useWalletBalance-Bnyl87EB.mjs";import{g as w}from"./getErc20TokenInfo-BKTIPvdP.mjs";import{f as x}from"./formatErc20TokenAmount-BuPk9xcy.mjs";import{g as F,a as _,p as N}from"./ethers-VpbQV-TA.mjs";import{g as A}from"./getPublicClient-D4yNgeGy.mjs";import{ErrorScreenView as S}from"./ErrorScreen-CBWkrb3m.mjs";import{styled as O}from"styled-components";import{M as R,B as D,P}from"./ModalHeader-DffkxvO4.mjs";import{D as $}from"./JsonTree-aPaJmPx7.mjs";import{T as B,S as q}from"./TransactionErrorView-DeK4ya42.mjs";import{R as L}from"./Layouts-BlFm53ED.mjs";import{S as W}from"./ScreenHeader-CHmc4-Lu.mjs";import{G as U}from"./useActiveWallet-BEfvREjE.mjs";import{T as V}from"./TransactionDetails-BIrREalL.mjs";import{E as G}from"./transfer-6YztDh-t.mjs";import{d as H}from"./toViemAccount-4iGGrW4w.mjs";import"lucide-react";import"tinycolor2";import"./errors-Dd6zfYtp.mjs";import"ofetch";import"eventemitter3";import"@privy-io/are-addresses-equal";import"./useGetSolPrice-x7gfUIHJ.mjs";import"viem/chains";import"./index-C5jxD-zy.mjs";import"./PrivyPluginContext-DA-yS5vO.mjs";import"zustand";import"mipd";import"react-device-detect";import"viem/utils";import"./pkce-BinverJO.mjs";import"jose";import"./paths-BH8W4zMc.mjs";import"@scure/base";import"./usePrivy-BhL-ltvm.mjs";import"./use-unlink-wallet-oAguM2-k.mjs";import"./get-entropy-details-for-user-BIWg0YxF.mjs";import"./user-D5cqJNp9.mjs";import"@privy-io/popup";import"./events-context-BJ75xIIf.mjs";import"@headlessui/react";import"./index-BtwxknTg.mjs";import"@privy-io/urls";import"./getEmbeddedConnectedWallet-Ba6LFHzY.mjs";import"@privy-io/ethereum";import"./frame-DtizlaLu.mjs";import"@privy-io/routes";import"./use-deposit-address-BwThybOQ.mjs";import"x402/client";import"@privy-io/api-base";import"./use-sign-with-user-signer-CQI6hUH7.mjs";import"./reservoir-DKpzKPcU.mjs";import"./ScreenLayout-Caq5mGD8.mjs";import"./Screen-D8KNyGVj.mjs";import"./index-Dq_xe9dz.mjs";import"@coinbase/wallet-sdk";import"@walletconnect/ethereum-provider";import"js-cookie";import"viem/accounts";import"@heroicons/react/24/outline/ArrowLeftIcon";import"@heroicons/react/24/outline/ArrowRightIcon";import"@heroicons/react/24/outline/QuestionMarkCircleIcon";import"@heroicons/react/24/outline/XMarkIcon";import"@heroicons/react/24/outline";import"./Value-tcJV9e0L.mjs";import"./LoadingSkeleton-U6-3yFwI.mjs";import"./Row-C9vrS4Zi.mjs";import"./ErrorMessage-D8VaAP5m.mjs";import"./LabelXs-oqZNqbm_.mjs";import"./Subtitle-CV-2yKE4.mjs";import"./Title-BnzYV3Is.mjs";import"./WalletInfoCard-BVXOg6V2.mjs";import"./shared-FM0rljBt.mjs";import"./Checkbox-BhNoOKjX.mjs";import"./ErrorBanner-CQERa7bL.mjs";import"@heroicons/react/24/outline/ExclamationCircleIcon";import"./WarningBanner-D5LqDt95.mjs";import"@heroicons/react/24/outline/ExclamationTriangleIcon";import"@heroicons/react/24/outline/ClipboardDocumentCheckIcon";import"@heroicons/react/24/outline/ClipboardDocumentIcon";import"./WalletLink-B5NUjxf-.mjs";import"./getFormattedUsdFromLamports-B6EqSEho.mjs";import"./transaction-CnfuREWo.mjs";import"@heroicons/react/24/outline/ChevronDownIcon";let z=[{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"}],J=O.div`
  display: flex;
  flex-direction: column;
  min-height: 72px;
`;var Q=({onBack:n,details:a})=>/*#__PURE__*/e(J,{children:[/*#__PURE__*/t(R,{backFn:n}),/*#__PURE__*/t($,{data:a}),/*#__PURE__*/t(D,{})]});let X=({gasUsed:e,effectiveGasPrice:t})=>{if(e&&t)try{return l(e*t)}catch(e){return}};const Y=({txn:a,receipt:s,transactionInfo:i,onClose:o,tokenPrice:r,tokenSymbol:p,receiptHeader:l,receiptDescription:u})=>/*#__PURE__*/e(n,{children:[/*#__PURE__*/t(R,{onClose:o}),/*#__PURE__*/t(W,{title:l??"Transaction complete!",description:u??"You're all set."}),/*#__PURE__*/t(V,{tokenPrice:r,from:s.from,to:s.to,gas:X(s),txn:a,transactionInfo:i,tokenSymbol:p}),/*#__PURE__*/t(U,{}),/*#__PURE__*/t(K,{loading:!1,onClick:o,children:"All Done"}),/*#__PURE__*/t(L,{}),/*#__PURE__*/t(D,{})]});let K=O(P)`
  && {
    margin-top: 24px;
  }
  transition:
    color 350ms ease,
    background-color 350ms ease;
`;const Z=[{constant:!1,inputs:[{name:"_salt",type:"bytes32"},{name:"_initializer",type:"bytes"}],name:"deployAccount",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"}],ee=[{name:"from",type:"address"},{name:"param2",type:"address"},{name:"param3",type:"bytes"},{name:"param4",type:"tuple",components:[]},{type:"tuple",components:[{name:"param5",type:"address"},{name:"param6",type:"uint256"},{name:"param7",type:"uint256"},{name:"encodedInitData",type:"bytes"}]}],te=[{constant:!1,inputs:[{name:"spender",type:"address"},{name:"value",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"}],ne=[{inputs:[{name:"to",type:"address"},{name:"amount",type:"uint256"},{name:"memo",type:"bytes32"}],name:"transferWithMemo",outputs:[{name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}],ae=[{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"mint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"mint",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"}],name:"mint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"}],name:"mint",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"},{internalType:"uint256",name:"quantity",type:"uint256"},{internalType:"bytes",name:"data",type:"bytes"}],name:"mint",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"},{internalType:"uint256",name:"quantity",type:"uint256"},{internalType:"bytes",name:"data",type:"bytes"}],name:"mint",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256[]",name:"tokenIds",type:"uint256[]"},{internalType:"uint256[]",name:"quantities",type:"uint256[]"},{internalType:"bytes",name:"data",type:"bytes"}],name:"mintBatch",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256[]",name:"tokenIds",type:"uint256[]"},{internalType:"uint256[]",name:"quantities",type:"uint256[]"},{internalType:"bytes",name:"data",type:"bytes"}],name:"mintBatch",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"uint256",name:"quantity",type:"uint256"}],name:"mint",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"quantity",type:"uint256"}],name:"mint",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"}],name:"safeMint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"}],name:"safeMint",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"string",name:"uri",type:"string"}],name:"safeMint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"string",name:"uri",type:"string"}],name:"safeMint",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"safeMint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"safeMint",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"},{internalType:"string",name:"uri",type:"string"}],name:"safeMint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"},{internalType:"string",name:"uri",type:"string"}],name:"safeMint",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"batchMint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"batchMint",outputs:[],stateMutability:"payable",type:"function"}],se=[{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_tokenId",type:"uint256"}],name:"safeTransferFrom",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"}],ie=[{constant:!1,inputs:[{name:"_operator",type:"address"},{name:"_approved",type:"bool"}],name:"setApprovalForAll",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"}],oe=[{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_tokenId",type:"uint256"}],name:"transferFrom",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"}],re=[{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_tokenIds",type:"uint256[]"},{name:"_amounts",type:"uint256[]"},{name:"_data",type:"bytes"}],name:"safeBatchTransferFrom",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"}],pe=[{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_tokenId",type:"uint256"},{name:"_amount",type:"uint256"},{name:"_data",type:"bytes"}],name:"safeTransferFrom",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"}],le=(e,t)=>{let n=ue(te,e);if(n)return{action:"approve",functionName:"approve",isErc20Ish:!0,isNFTIsh:!1,spender:n.args[0],amount:n.args[1]};let a=ue(G,e);if(a)return{action:"transfer",functionName:"transfer",isErc20Ish:!0,isNFTIsh:!1,transferTo:a.args[0],amount:a.args[1]};let s=ue(ne,e);if(s)return{action:"transfer",functionName:"transferWithMemo",isErc20Ish:!0,isNFTIsh:!1,transferTo:s.args[0],amount:s.args[1]};if(!t)return{action:"transaction",functionName:"",isErc20Ish:!1,isNFTIsh:!1};let i=ue(Z,e);if(i&&"string"==typeof i.args[1]){let e=me(i.args[1]);if(e&&e[4].encodedInitData)return le(e[4].encodedInitData,t)}let o=ue(ie,e);if(o)return{action:"approve",functionName:"setApprovalForAll",isNFTIsh:!0,isErc20Ish:!1,operator:o.args[0],approved:o.args[1]};let r=ue(oe,e);if(r)return{action:"transfer",functionName:"transferFrom",isNFTIsh:!0,isErc20Ish:!1,transferFrom:r.args[0],transferTo:r.args[1],tokenId:r.args[2]};let p=ue(se,e);if(p)return{action:"transfer",functionName:"safeTransferFrom",isNFTIsh:!0,isErc20Ish:!1,transferFrom:p.args[0],transferTo:p.args[1],tokenId:p.args[2]};let l=ue(pe,e);if(l)return{action:"transfer",functionName:"safeTransferFrom",isNFTIsh:!0,isErc20Ish:!1,transferFrom:l.args[0],transferTo:l.args[1],tokenId:l.args[2],amount:l.args[3]};let u=ue(re,e);if(u)return{action:"batch transfer",functionName:"safeBatchTransferFrom",isNFTIsh:!0,isErc20Ish:!1,transferFrom:u.args[0],transferTo:u.args[1],tokenIds:u.args[2],amounts:u.args[3]};let m=ue(ae,e);return m?{action:"mint",functionName:m.functionName,isNFTIsh:!0,isErc20Ish:!1,args:m.args}:{action:"transaction",isErc20Ish:!1,isNFTIsh:!1}};let ue=(e,t)=>{try{let n=u({abi:e,data:t});return{functionName:n.functionName,args:n.args||[]}}catch(e){return null}},me=e=>{try{if("string"==typeof e)return m(ee,`0x${e.slice(10)}`)}catch(e){return null}},ce=e=>`${parseFloat(e).toFixed(2)}`;function de(e,t){let n=[],a=new Map;if(e)for(let t of e)if(t.in[0]){let e;e="ERC721"===t.asset.type||"approve_for_all"===t.in[0].value?{id:`nft:${t.asset.name}`,nftName:t.asset.name,nftCount:t.in.length}:{id:`token:${t.asset.type}:${t.asset.symbol}:${t.asset.name}`,iconUrl:t.asset.logo_url,value:t.in[0].value,symbol:t.asset.symbol,usdValue:t.in[0].usd_price?ce(t.in[0].usd_price):void 0,decimals:t.asset.decimals},n.push(e)}else if(t.out[0]?.value){let e;e="ERC721"===t.asset.type||"approve_for_all"===t.out[0].value?{id:`nft:${t.asset.name}`,nftName:t.asset.name}:{id:`token:${t.asset.type}:${t.asset.symbol}:${t.asset.name}`,iconUrl:t.asset.logo_url,value:t.out[0].value,symbol:t.asset.symbol,usdValue:t.out[0].usd_price?ce(t.out[0].usd_price):void 0,decimals:t.asset.decimals},a.has(e.id)||a.set(e.id,e)}for(let e of t)for(let t of Object.keys(e.spenders)){let n;n="ERC721"===e.asset.type||"approve_for_all"===e.spenders[t]?.value?{id:`nft:${e.asset.name}`,nftName:e.asset.name}:{id:`token:${e.asset.type}:${e.asset.symbol}:${e.asset.name}`,iconUrl:e.asset.logo_url,value:e.spenders[t]?.value,symbol:e.asset.symbol,usdValue:e.spenders[t]?.usd_price?ce(e.spenders[t]?.usd_price):void 0,decimals:e.asset.decimals},a.has(n.id)||a.set(n.id,n)}return{assetsIn:n,assetsOut:Array.from(a.values())}}const ye=(e,t,n,s)=>{let[i,r]=a(null),{walletProxy:p}=k();return o((()=>{i&&r(null),(async()=>{if(!p||!t)return null;let a=[],i=!0,o=await H(e,n,t,s).catch((t=>(t.message&&t.message.includes("Insufficient balance for transaction")||t.message&&t.message.includes("Insufficient funds for gas * price + value")||t.details&&t.details.includes("insufficient funds")||t.details&&t.details.includes("gas required exceeds allowance")?i=!1:a.push(t),e)));return{tx:o,totalGasEstimate:o.gas,hasFunds:i,errors:a}})().then(r)}),[e]),i};let fe=new g(new I("There was an issue preparing your transaction",f.E32603_DEFAULT_INTERNAL_ERROR.eipCode)),be=(e,t)=>e?.sendTransaction?"transactionRequest"in e.sendTransaction?e.sendTransaction.transactionRequest:e.sendTransaction.transactionRequests[t]:void 0;const Te={component:()=>{let{data:l,onUserCloseViaDialogOrKeybindRef:u,setModalData:m,navigate:O}=j(),{client:R,rpcConfig:D,chains:P,closePrivyModal:$,walletProxy:L,showFiatPrices:W}=k(),{user:U}=E(),V=T(),[G,H]=a(0),[J,X]=a(0),[K,Z]=a(be(l,G)),[ee,te]=a(null),[ne,ae]=a(),[se,ie]=a(!1),[oe,re]=a(null),[pe,ue]=a(null),[me,ce]=a(null),[Te,he]=a(void 0),[ge,ve]=a(void 0),[Ie,ke]=a(!1),[je,Ee]=a(!1),[Me,Ce]=a([]),[we,xe]=a([]),[Fe,_e]=a("uninitiated"),[Ne,Ae]=a(void 0);if(!K||!l?.sendTransaction||!l?.sendTransaction)/*#__PURE__*/return t(S,{error:Error("Invalid transaction request"),allowlistConfig:V.allowlistConfig,onRetry:()=>{l?.sendTransaction?.onFailure(fe),$({shouldCallAuthOnSuccess:!1})}});let{transactingWalletAddress:Se}=l.sendTransaction,Oe=s((()=>P.find((e=>Number(e.id)===Number(K.chainId)))),[K.chainId]),Re=Oe?.nativeCurrency.symbol??"ETH",De=s((()=>le(K.data,!!V.embeddedWallets.extendedCalldataDecoding)),[K.data]),{action:Pe,isErc20Ish:$e,isNFTIsh:Be,functionName:qe}=De,{toAddress:Le,tokenAddress:We}=s((()=>({toAddress:De.isErc20Ish?De.transferTo:K.to??void 0,tokenAddress:De.isErc20Ish?K.to:void 0})),[De]);o((()=>{K.to&&Oe&&$e&&w({address:K.to,chain:Oe,rpcConfig:V.rpcConfig,privyAppId:V.id}).then(te).catch(console.error)}),[K.to,Oe]);let{tokenPrice:Ue,isTokenPriceLoading:Ve}=M(K.chainId),{balance:Ge}=C({rpcConfig:V.rpcConfig,appId:V.id,address:Se,chain:Oe}),He=function({rpcConfig:e,appId:t,address:n,chain:l,tokenInfo:u}){let{chains:m}=k(),[c,f]=a(null),[b,T]=a(!1),h=s((()=>{let n=l||m[0];if(n)return r({chain:l,transport:p(d(n,e,t))})}),[l,e,t]),g=i((async()=>{if(n&&h&&u.address)try{return T(!0),await h.readContract({address:u.address,abi:z,functionName:"balanceOf",args:[n]})}catch(e){console.error(e)}finally{T(!1)}}),[h,n,u?.address,l]);return o((()=>{g().then((e=>null!=e&&f(e)))}),[g]),{balance:c,isLoading:b&&null==c,formattedBalance:y({amount:c??BigInt(0),decimals:u.decimals})}}({rpcConfig:V.rpcConfig,appId:V.id,address:Se,tokenInfo:{address:We||"",decimals:ee?.decimals??18},chain:Oe}),ze=s((()=>A(Number(K.chainId),P,D,{appId:V.id})),[K.chainId,D]),Je=ye(K,Se,ze,l?.sendTransaction?.prepareTransactionRequest);o((()=>{Z(be(l,G))}),[G]),o((()=>{l.sendTransaction?.getIsSponsored?l.sendTransaction.getIsSponsored().then(ae).catch(console.error):ae(!1)}),[l.sendTransaction.getIsSponsored]);let Qe=()=>{if(!se)return oe?l?.sendTransaction?.onSuccess({hash:oe}):me||Je?.errors[0]?l?.sendTransaction?.onFailure(me??Je?.errors[0]??fe):l?.sendTransaction?.onFailure(new g(new I("The user rejected the request",f.E4001_USER_REJECTED_REQUEST.eipCode))),$({shouldCallAuthOnSuccess:!1})};u.current=Qe;let Xe=!!(l.funding&&l.funding.supportedOptions.length>0),Ye=F(BigInt(Je?.totalGasEstimate??0n),Re),Ke=W&&Ue?_(BigInt(Je?.totalGasEstimate??0n),Ue):void 0,Ze=F(Ge??0n,Re,void 0,!0),et=W&&Ue?_(Ge??0n,Ue):void 0,tt=ee&&!He.isLoading&&$e&&"approve"!==Pe?`${He.formattedBalance} ${ee.symbol}`:void 0,nt=l.sendTransaction?.uiOptions?.transactionInfo?.title;nt||(nt="approve"===Pe?$e?"Confirm address":"Confirm action":`Approve ${Pe}`);let at=s((()=>{if(l.sendTransaction?.uiOptions?.description)return l.sendTransaction?.uiOptions?.description;if("approve"===Pe&&"setApprovalForAll"===qe&&De.approved){let a=/*#__PURE__*/t(b,{address:De.operator||"",url:Oe?.blockExplorers?.default?.url});/*#__PURE__*/return e(n,{children:[V.name," would like your permission for ",a," to transfer tokens on your behalf."]})}if("approve"===Pe&&"setApprovalForAll"===qe&&!De.approved){let a=/*#__PURE__*/t(b,{address:De.operator||"",url:Oe?.blockExplorers?.default?.url});/*#__PURE__*/return e(n,{children:[V.name," would like your permission to revoke permissions of ",a," from transferring tokens on your behalf."]})}return $e&&"approve"===Pe||$e&&"approve"===Pe?`${V.name} would like your permission for ${v(De.spender)} to spend tokens on your behalf.`:`${V.name} wants your permission to approve the following transaction.`}),[V.name,$e,De,l.sendTransaction?.uiOptions.description,qe]),st=l.sendTransaction?.uiOptions?.transactionInfo?.contractInfo?.imgUrl?/*#__PURE__*/t("img",{src:l.sendTransaction.uiOptions.transactionInfo.contractInfo.imgUrl,alt:l.sendTransaction.uiOptions.transactionInfo.contractInfo.imgAltText}):null,it=!(!Je||Je.errors[0]||Je.hasFunds||!1!==ne),ot=it&&Xe,rt=ot?"Add funds":l.sendTransaction?.uiOptions?.buttonText||(G<J?"Continue":"Approve"),pt=e=>{if(!e)throw Error("Transaction scan failed");if("Success"===e.validation.status&&("Benign"===e.validation.result_type?ve("safe"):"Warning"===e.validation.result_type?ve("warn"):"Malicious"===e.validation.result_type&&(ve("error"),Ee(!0))),"Success"!==e.simulation.status)throw Error("Simulation failed");{he(e.simulation.params);let{assetsIn:t,assetsOut:n}=de(e.simulation.assets_diffs,e.simulation.exposures);if(0===n.length&&0===t.length)throw Error("No tokens found");Ce(n),xe(t)}};if(o((()=>{l.sendTransaction?.scanTransaction&&V.embeddedWallets.transactionScanning.enabled&&"uninitiated"===Fe&&(_e("in progress"),l.sendTransaction.scanTransaction().then((e=>{pt(e),_e("completed")})).catch((()=>_e("failed"))))}),[!!l.sendTransaction?.scanTransaction]),o((()=>{l.sendTransaction?.scanTransaction&&"failed"!==Fe||((e,t,n)=>{if(X((e=>e?.sendTransaction?"transactionRequest"in e.sendTransaction?0:e.sendTransaction.transactionRequests.length-1:0)(l)),t.isErc20Ish&&t.amount&&n){let e=x({amount:t.amount,decimals:n.decimals});Ae(e),Ce([{value:e,symbol:n?.symbol,decimals:n?.decimals}])}else if(e.value){let t=BigInt(e.value),n=Ue?_(t,Ue):void 0;Ce(W&&n?[{value:n}]:[{value:N(t),symbol:Re,decimals:18,usdValue:n}])}else Ce(W?[{value:"$0"}]:[{value:"0",symbol:Re,decimals:18}])})(Je?.tx??K,De,ee)}),[K,Je?.tx,De,ee,Fe]),pe/*#__PURE__*/)return t(Y,{txn:Je?.tx??K,onClose:Qe,receipt:pe,transactionInfo:l.sendTransaction?.uiOptions.transactionInfo,tokenPrice:Ue,tokenSymbol:Re,receiptHeader:l.sendTransaction?.uiOptions.successHeader,receiptDescription:l.sendTransaction?.uiOptions.successDescription});if(me)/*#__PURE__*/return t(B,{transactionError:me,transactionHash:oe??void 0,chainType:"ethereum",chainId:Je?.tx.chainId??K.chainId,onClose:Qe,onRetry:({resetNonce:e})=>{ce(null);let t={...Je?.tx??K};e&&(t.nonce=void 0),Z(t)}});let lt=0!==J&&"number"==typeof G&&0!==G?()=>{H(G-1)}:void 0;return Ie&&Te?/*#__PURE__*/t(Q,{details:Te,onBack:()=>ke(!1)}):/*#__PURE__*/t(q,{transactionIndex:G,onBack:lt,maxIndex:J,disabled:it&&!Xe||je,isSubmitting:se,submitError:me,isPreparing:!Je,isTokenPriceLoading:Ve,isTokenContractInfoLoading:!Be&&!ee,prepareError:Je?.errors[0],symbol:ee?.symbol,chain:Oe,img:st,title:nt,subtitle:at,txValue:K.value,fee:Ke??Ye,isSponsored:ne,from:Se??"",to:Le,tokenAddress:We??void 0,network:V.chains.find((e=>e.id===K.chainId))?.name??"",transactionDetails:{...De,formattedAmount:Ne},cta:rt,missingFunds:it,action:Pe,balance:tt??et??Ze,onClose:Qe,onClick:ot?async()=>{if(!Se)return;if(!Xe)throw Error("Funding wallet is not enabled");let e="FundingMethodSelectionScreen";m({...l,funding:{...l.funding,methodScreen:e,chainType:"ethereum",amount:c(BigInt(Je?.tx.value??0)+BigInt(Je?.totalGasEstimate?.toString()??0)),chain:Oe},solanaFundingData:l?.solanaFundingData}),O(e)}:async()=>{if(G<J)H(G+1);else{ie(!0);try{let e=await R.getAccessToken();if(se||!e||!L||!U)return;let t=await l.sendTransaction.onConfirm({transactionRequest:Je?.tx??K});if(re(t),l.sendTransaction?.signOnly)return await new Promise((e=>setTimeout(e,h))),l?.sendTransaction?.onSuccess({hash:t}),$({shouldCallAuthOnSuccess:!1});let n=await ze.waitForTransactionReceipt({hash:t});if("reverted"===n.status)throw Error("Transaction failed");ue(n)}catch(e){console.warn({transaction:Je?.tx??K,error:e}),ce(e)}finally{ie(!1)}}},validation:ge,hasScanDetails:!!Te,setIsScanDetailsOpen:ke,preventMaliciousTransaction:je,setPreventMaliciousTransaction:Ee,tokensSent:Me,tokensReceived:we,isScanning:"in progress"===Fe,isCancellable:l.sendTransaction?.uiOptions?.isCancellable??!1,functionName:qe})}};export{Te as SendTransactionScreen,Te as default};
//# sourceMappingURL=index-CkCwxPG2.mjs.map
