"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@argent/x-shared"),x=require("react"),S=async({feeTokenAddress:e,calls:o,selectedAccount:r,transactionReviewService:i,appDomain:t,accountDeployTransaction:a,isDelayedTransaction:l})=>{const d={type:"INVOKE",calls:c.ensureArray(o)};if(!r||!e)return;const s=a?[a,d]:[d];return{result:await i.simulateAndReview(r,s,e,t,a,l)}},k=async(e,o,r,i)=>{var g,y,F,T,w,A;let t=!1;const a=(g=o.transactions)==null?void 0:g.find(n=>{var B,G;return(G=(B=n==null?void 0:n.simulation)==null?void 0:B.summary)==null?void 0:G.find(q=>q.sent)});if(!a||!((y=a.simulation)!=null&&y.summary))return t;const l=await c.getTokenBalance(r,e,i)??0n,d=a.simulation.summary.filter(n=>n.sent).map(n=>n.token.address),s=(F=o.enrichedFeeEstimation)==null?void 0:F.find(n=>c.isEqualAddress(n.transactions.feeTokenAddress,r)),u=(s==null?void 0:s.transactions.feeTokenAddress)&&d.includes(s.transactions.feeTokenAddress),h=(s==null?void 0:s.type)==="native"&&!(s!=null&&s.transactions.l1Gas.gasConsumed||s!=null&&s.transactions.l2Gas.gasConsumed||s!=null&&s.transactions.l1DataGas.gasConsumed),R=(s==null?void 0:s.type)==="paymaster"&&!((T=s.transactions)!=null&&T.maxFee);if(!u||h&&R)return t;const m=c.estimatedFeesToMaxFeeTotalV2(s),v=(w=a.simulation.summary.find(n=>n.sent&&c.isEqualAddress(n.token.address,r)))==null?void 0:w.value,b=(A=a.simulation.summary.find(n=>!n.sent&&c.isEqualAddress(n.token.address,r)))==null?void 0:A.value;if(!m||!v)return t;const C=BigInt(v)-BigInt(b||0);if(!l)return t;const f=m+C;return l>=f||(t=!0),t},N=()=>x.useCallback(async({feeTokenAddress:o,calls:r,selectedAccount:i,transactionReviewService:t,appDomain:a,accountDeployPayload:l,provider:d,isDelayedTransaction:s})=>{if(!i)return;const u=await S({feeTokenAddress:o,calls:r,selectedAccount:i,transactionReviewService:t,appDomain:a,accountDeployTransaction:p(l),isDelayedTransaction:s});if(!u||!u.result||!o)return;const h=await k(i.address,u.result,o,d);return{...u.result,isSendingMoreThanBalanceAndGas:h}},[]),p=e=>e?{type:"DEPLOY_ACCOUNT",calldata:e.calldata,classHash:c.hexSchema.parse(e.class_hash),salt:c.hexSchema.parse(e.salt),signature:[]}:void 0;exports.buildAccountDeployTransaction=p;exports.checkGasFeeBalance=k;exports.getReviewForTransactions=S;exports.useTransactionReviewV2webFetcher=N;
