UNPKG

@sofaws/dapp-core

Version:

A library to hold the main logic for a dapp on the Elrond Network

3 lines (2 loc) 1.69 kB
import{b as f}from"./chunk-3SYOVVPU.js";import{a as h}from"./chunk-4VDFQTIQ.js";import{a as i,b as B}from"./chunk-RYMWXK25.js";import{a as A}from"./chunk-ZU6LXEUO.js";import{a as S}from"./chunk-VTMJ7INI.js";import{m as b}from"./chunk-HBP5N4FR.js";b();A();import u,{useEffect as C,useMemo as O,useRef as g}from"react";import _ from"classnames";B();var m="toastProgress",j=({id:s,children:p,progress:r,done:x,expiresIn:I=10*60,className:N="dapp-progress"})=>{let y=O(()=>{let e=r?r.endTime-r.startTime:0,n=i.session.getItem(m),d=Math.floor(Date.now()/1e3),o=r?(r.endTime-d)*100/e:0;return{currentRemaining:n&&s in n?n[s]:o,totalSeconds:e}},[]),{totalSeconds:F,currentRemaining:w}=y,t=g(null),a=g(),c=g(w);C(()=>{if(r!=null)return x?M():D(),()=>{clearInterval(a.current)}},[r,x]);function E(){let e=i.session.getItem(m);!Boolean(e==null?void 0:e[s])||(delete e[s],v(e))}function T(e){let n=i.session.getItem(m)||{};n[s]=e,v(n)}function v(e){i.session.setItem({key:m,data:e,expires:S(I)})}function M(){a.current=setInterval(()=>{if(t.current==null)return;let n=c.current-1;n<=0?(clearInterval(a.current),E(),l(0)):(T(n),l(n))},5)}function D(){let n=F/90,d=parseFloat(n.toFixed(2))*1e3;a.current=setInterval(()=>{if(t.current==null)return;let o=c.current,P=o>100-90?1:h(o),R=o-P;T(R),l(R)},d)}function l(e){c.current=e,W()}function W(){if(t.current==null)return;let e=c.current;t.current.style.width=`${e}%`,t.current.ariaValueNow=e}return r?u.createElement("div",{className:_(f.progress,N)},u.createElement("div",{ref:t,role:"progressbar","aria-valuemin":0,"aria-valuemax":100,className:f.bar}),p):u.createElement(u.Fragment,null,p)};export{j as a}; //# sourceMappingURL=chunk-UHEIDR6A.js.map