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