UNPKG

@sofaws/dapp-core

Version:

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

3 lines (2 loc) 2.88 kB
import{a as j}from"./chunk-3BUO2NEZ.js";import{a as U}from"./chunk-BQ7HF5HX.js";import{a as V}from"./chunk-XO5YBSXO.js";import{a as $}from"./chunk-GMH2UR4D.js";import{a as z}from"./chunk-G57K6QI4.js";import{b as x}from"./chunk-3OBZU2S7.js";import{c as D,d as L}from"./chunk-ZUW3EYNS.js";import{f as W}from"./chunk-5D7CBKRZ.js";import{a as G}from"./chunk-PFI6RQVA.js";import{a as k}from"./chunk-X5TGO2UY.js";import{a as cn}from"./chunk-SIAIYQNL.js";import{c as O}from"./chunk-6J24ICLK.js";import{h as w}from"./chunk-USYQ5ZLE.js";import{e as P,j as _,k as m}from"./chunk-JXBPRUT3.js";import{l as b,s as an}from"./chunk-ZR7YL3KO.js";import{a as y}from"./chunk-MV7THB7B.js";import{a as M,b as d,c as N,d as C,e as v}from"./chunk-C32UB6VS.js";import{k as en}from"./chunk-P6M5SGWP.js";import{j as S,m as A}from"./chunk-HBP5N4FR.js";A();an();import{useEffect as ln,useRef as B}from"react";import{ExtensionProvider as F}from"@elrondnetwork/erdjs-extension-provider";cn();en();var wn=()=>{let c=D(),I=B("/"),{provider:r}=z(),X=x(r),T=B(!1),Z=$(),q=L(W),{transactionsToSign:e,error:H,setError:J,hasTransactions:g,onAbort:p,clearTransactionStatusMessage:E}=j();U(p);function K(n){var s,t;let a=r instanceof F;c(P()),c(w(n)),c(O(y)),a&&(E(),(t=(s=F.getInstance())==null?void 0:s.cancelAction)==null||t.call(s))}let f=(n,a)=>{let s=n.includes(d);if(K(a),s){c(_(d));return}J(n)},Q=(n,a,s="")=>{let t={[b]:a},u=`${window.location.origin}${s}`,i=k({callbackUrl:u,urlParams:t});r.signTransactions(n,{callbackUrl:encodeURIComponent(i)})},Y=()=>S(void 0,null,function*(){var R;if(T.current)return;let{sessionId:n,transactions:a,callbackRoute:s,customTransactionInformation:t}=e,{redirectAfterSign:u}=t,i=s||window.location.pathname,sn=window.location.pathname.includes(i),tn=u&&!sn;try{if(!(yield(R=r==null?void 0:r.init)==null?void 0:R.call(r)))return}catch(o){let l=(o==null?void 0:o.message)||o||C;console.error(l),f(l);return}try{T.current=!0;let o=yield r.signTransactions(a);if(T.current=!1,!V(o))return;let on=Object.values(o).map(rn=>G(rn)),h={sessionId:n,transactions:on,status:"signed"};tn&&(h.redirectRoute=i),c(m(h))}catch(o){T.current=!1;let l=(o==null?void 0:o.message)||o||N;console.error(l),c(m({sessionId:n,status:"cancelled"})),f(l.includes("cancel")?d:l,n)}}),nn=()=>S(void 0,null,function*(){if(!e)return;E();let{sessionId:n,transactions:a,callbackRoute:s}=e;if(!r){console.error(v);return}I.current=s||window.location.pathname;try{let t=X==="wallet",u=yield Z(a);if(t)return Q(u,n,s);Y()}catch(t){let i=(t==null?void 0:t.message)||M;console.error(i),f(i,n),c(m({sessionId:n,status:"cancelled"})),console.error(i,t)}});return ln(()=>{g&&nn()},[e,g]),{error:H,canceledTransactionsMessage:q,onAbort:p,hasTransactions:g,callbackRoute:I.current,sessionId:e==null?void 0:e.sessionId,transactions:e==null?void 0:e.transactions}};export{wn as a}; //# sourceMappingURL=chunk-JUAZHO55.js.map