@sofaws/dapp-core
Version:
A library to hold the main logic for a dapp on the Elrond Network
3 lines (2 loc) • 3.71 kB
JavaScript
import{a as X}from"./chunk-BFPRB6ZU.js";import{b as Y}from"./chunk-UZ2ARPKR.js";import{a as v}from"./chunk-534JQDGS.js";import{a as L}from"./chunk-EL2MAJQB.js";import{a as Q}from"./chunk-PH57BHSD.js";import{a as P}from"./chunk-UXKRFUDC.js";import{a as d,c as K}from"./chunk-LG3EKWP7.js";import{c as G,d as J}from"./chunk-3OBZU2S7.js";import{c as B,d as o}from"./chunk-ZUW3EYNS.js";import{a as q}from"./chunk-ULAJMRI3.js";import{g as $}from"./chunk-V2DQWH6R.js";import{b as N,c as O,d as V,e as _,f as j}from"./chunk-YMKD43L4.js";import{a as H,g as T}from"./chunk-44WWQAQY.js";import{a as he}from"./chunk-SIAIYQNL.js";import{d as U}from"./chunk-7RF3KWYA.js";import{c as h,g as F,j as p,k as M}from"./chunk-IZ52XEZC.js";import{f as R,g as z}from"./chunk-GK2OH76G.js";import{b as D,c as we}from"./chunk-3PPQ3FCK.js";import{k as me}from"./chunk-P6M5SGWP.js";import{a as m,b as w,d as W,j as i,m as E}from"./chunk-HBP5N4FR.js";E();import{useEffect as u,useState as pe}from"react";import{ExtensionProvider as Le}from"@elrondnetwork/erdjs-extension-provider";import{HWProvider as Pe}from"@elrondnetwork/erdjs-hw-provider";we();he();me();function Ne(){let A=o($),S=o(V),g=o(N),Z=o(j),c=o(H),y=o(T),a=o(_),s=o(O),[l,ee]=pe(),n=B(),{callbackRoute:k,logoutRoute:C}=S||{callbackRoute:"",logoutRoute:""},[te]=X({callbackRoute:k,logoutRoute:C}),[ne]=Y({callbackRoute:k,logoutRoute:C});u(()=>{oe()},[A]),u(()=>{ge()},[g]),u(()=>{ie()},[c,s]),u(()=>{re()},[y,s,l]);function oe(){return i(this,null,function*(){try{let e=yield q();e&&n(U(e.erd_chain_id))}catch(e){console.error("failed refreshing chainId ",e)}})}function re(){y==null&&a!=null&&l&&n(F({index:a.index,address:c,hasContractDataEnabled:l.dataEnabled,version:l.version}))}function ie(){return i(this,null,function*(){if(n(p(!0)),c&&s)try{let e=yield P(c);e&&n(h(w(m({},e),{address:c,nonce:e.nonce.valueOf()})))}catch(e){n(M("Failed getting account")),console.error("Failed getting account ",e)}n(p(!1))})}function ae(){return i(this,null,function*(){let e=G(A.walletAddress);if(d(e),Z!=null){try{let t=yield L();if(t){n(D({address:t,loginMethod:"wallet"}));let r=yield P(t);r&&n(h(w(m({},r),{nonce:Q(r)})))}ce()}catch(t){console.error("Failed authenticating wallet user ",t)}n(z(null))}})}function ce(){var x;let e={};if((x=window==null?void 0:window.location)!=null&&x.search){let fe=new URLSearchParams(window.location.search);e=Object.fromEntries(fe)}let I=e,{signature:t,loginToken:r,address:b}=I,f=W(I,["signature","loginToken","address"]);t&&n(R(t)),se(f)}function se(e){let t=new URLSearchParams(e).toString(),{pathname:r}=window.location,b=t?`?${t}`:"",f=r?`${r}${b}`:"./";setTimeout(()=>{window.history.replaceState({},document==null?void 0:document.title,f)})}function le(){return i(this,null,function*(){let e=new Pe,t=e.isInitialized();if(t||(t=yield e.init()),!t&&s){console.warn("Could not initialise ledger app"),v();return}return(a==null?void 0:a.index)!=null&&(e.addressIndex=a.index),e})}function de(){return i(this,null,function*(){try{let e=yield le();if(!e)return;let t=yield J(e);d(e),ee(t)}catch(e){console.error("Could not initialise ledger app",e),v()}})}function ue(){return i(this,null,function*(){try{let e=yield L(),t=Le.getInstance().setAddress(e);(yield t.init())?d(t):console.error("Could not initialise extension, make sure Elrond wallet extension is installed.")}catch(e){console.error("Unable to login to ExtensionProvider",e)}})}function ge(){if(g!=null)switch(g){case"ledger":{de();break}case"walletconnect":{te(!1);break}case"walletconnectv2":{ne(!1);break}case"extension":{ue();break}case"extra":{K();break}case"wallet":case"":{ae();break}default:return}}return null}export{Ne as a};
//# sourceMappingURL=chunk-EPRM37YS.js.map