@multiversx/sdk-dapp-swap
Version:
A library to hold the main logic for swapping between tokens on the MultiversX blockchain
9 lines (8 loc) • 756 B
JavaScript
import{b as s}from"./chunk-4XMIBGR3.js";import{a as r,f as o}from"./chunk-5W737WN4.js";o();import{useEffect as P,useState as m}from"react";import{gql as b,useSubscription as f}from"@apollo/client";var S=b`
subscription swapPackageTokensPriceUpdated {
tokensPriceUpdated {
updates
}
}
`,x=()=>{let[c,n]=m({}),{client:p}=s(),{data:e}=f(S,{client:p});return P(()=>{!(e!=null&&e.tokensPriceUpdated)||n(u=>{let i=r({},u);try{e==null||e.tokensPriceUpdated.updates.forEach(t=>{let a=t[0],d=t[1];i[a]={price:d,timestamp:Date.now()}});for(let t in i)Date.now()-i[t].timestamp>1e4&&delete i[t]}catch(t){console.error("Failed to update prices: ",t)}return i})},[e]),{priceSubscriptions:c}};export{x as a};
//# sourceMappingURL=chunk-RWMDQQQ6.js.map