UNPKG

@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.54 kB
import{a as I}from"./chunk-OZLDW2QC.js";import{a}from"./chunk-BAHR77W6.js";import{a as h}from"./chunk-7B4MYFHH.js";import{a as y}from"./chunk-72ZXSL3L.js";import{a as f}from"./chunk-MEPB323Y.js";import{f as d}from"./chunk-DKQLHRWP.js";d();import{useEffect as Y,useMemo as Z,useState as n}from"react";import _ from"bignumber.js";var re=({tolerance:i,activeRoute:e,firstToken:t,firstAmount:c,secondToken:s,secondAmount:r,swapActionType:o})=>{var u,g,w,S;let[D,A]=n(),[x,E]=n(),[O,U]=n(),[M,b]=n(),[B,C]=n(),{tokenInId:m,tokenOutId:H,exchangeRate:l,switchTokensDirection:N}=I({activeRoute:e}),V=Z(()=>f(e==null?void 0:e.transactions),[e==null?void 0:e.transactions]),$=a(l||""),j=a((g=(u=t==null?void 0:t.token)==null?void 0:u.price)!=null?g:""),q=a((S=(w=s==null?void 0:s.token)==null?void 0:w.price)!=null?S:""),z=m===(t==null?void 0:t.value)?q:j,G=new _($||"0").multipliedBy(z||"0").toString(10);return Y(()=>{if(!e)return;let{swapType:J,pairs:F}=e,K=y({tolerance:i,secondAmount:r,secondTokenDecimals:s==null?void 0:s.token.decimals,isFixedOutput:J===1,swapActionType:o}),P=[];F.forEach(T=>{let{totalFee:p,burn:W,lpHolders:X}=h(T);!(F.length===1)&&p&&P.push(`${p}%`),C({totalFee:p,burn:W,lpHolders:X})});let L=c?e.pricesImpact:void 0,Q=c?e.fees:void 0;A(K),E(Q),b(L),U(P)},[i,e,t,c,s,r,o]),{exchangeRate:l,feeDetails:B,feeAmounts:x,pricesImpact:M,feePercentages:O,tokenInId:m,tokenOutId:H,switchTokensDirection:N,totalTransactionsFee:V,minimumAmountReceived:D,exchangeRateUsdValue:G}};export{re as a}; //# sourceMappingURL=chunk-HLWTG374.js.map