@multiversx/sdk-dapp-swap
Version:
A library to hold the main logic for swapping between tokens on the MultiversX blockchain
3 lines (2 loc) • 1.86 kB
JavaScript
import{a as P}from"./chunk-GPR5POLQ.js";import{a as f}from"./chunk-OL6W5D2R.js";import{a as F}from"./chunk-FVUKQCTR.js";import{a as I}from"./chunk-YKA56OWE.js";import{a as T}from"./chunk-LQ6TEEMX.js";import{a as d}from"./chunk-NO6S3H3V.js";import{a as w}from"./chunk-ZVPH66VY.js";import{b as u}from"./chunk-QXTSQDB3.js";import{f as c}from"./chunk-5W737WN4.js";c();import{useEffect as R,useMemo as v,useState as t}from"react";import g from"bignumber.js";var ue=({tolerance:r,activeRoute:e,swapActionType:m})=>{let[y,S]=t(),[U,D]=t(),[k,A]=t(),[O,V]=t(),[h,E]=t(),[b,x]=t(),[M,N]=t(),{tokenInId:B,tokenOutId:C,exchangeRate:H,rateDirection:L,switchTokensDirection:Z}=P({activeRoute:e}),j=v(()=>I(e==null?void 0:e.transactions),[e==null?void 0:e.transactions]);return R(()=>{var i,l;if(!e)return;let{pairs:q,swapType:z,smartSwap:n,amountOut:a,tokenOutID:G,tokenOutPriceUSD:J}=e,p=f({activeRoute:e}),s=p.map(({tokens:o})=>o).flat().find(({identifier:o})=>o===G),K=w({tolerance:r,swapActionType:m,isFixedOutput:z===1,secondTokenDecimals:s==null?void 0:s.decimals,secondAmount:(i=n==null?void 0:n.amountOut)!=null?i:a}),Q=new g(u({showLastNonZeroDecimal:!0,decimals:s==null?void 0:s.decimals,input:(l=n==null?void 0:n.amountOut)!=null?l:a})).times(J).toString(10);q.forEach(o=>{let{totalFee:Y,burn:_,lpHolders:$}=T(o);V({totalFee:Y,burn:_,lpHolders:$})});let W=e!=null&&e.amountIn?d({activeRoute:e}):void 0,X=e!=null&&e.amountIn?F({activeRoute:e}):void 0;D(n?{feeAmount:n.feeAmount,feePercentage:new g(n.feePercentage).times(100).toNumber()}:void 0),A(p),S(W),E(Q),N(K),x(X)},[r,e,m]),{tokenInId:B,feeDetails:O,tokenOutId:C,tokenRoutes:k,priceImpact:y,platformFee:U,exchangeRate:H,rateDirection:L,receivedUsdValue:h,totalFeesUsdValue:b,totalTransactionsFee:j,minimumAmountReceived:M,switchTokensDirection:Z}};export{ue as a};
//# sourceMappingURL=chunk-H7MFHN27.js.map