@sofaws/dapp-core
Version:
A library to hold the main logic for a dapp on the Elrond Network
3 lines (2 loc) • 1.53 kB
JavaScript
import{a as I}from"./chunk-Y4H5RT5M.js";import{a as T}from"./chunk-LG3EKWP7.js";import{c as w}from"./chunk-ZUW3EYNS.js";import{a as G}from"./chunk-SIAIYQNL.js";import{a as F}from"./chunk-LWOALGQV.js";import{a as u}from"./chunk-G7CLUFEM.js";import{e as y}from"./chunk-GK2OH76G.js";import{b as L,c as D}from"./chunk-3PPQ3FCK.js";import{g as f,h as A}from"./chunk-C32UB6VS.js";import{k as U}from"./chunk-P6M5SGWP.js";import{a as d,j as m,m as l}from"./chunk-HBP5N4FR.js";l();A();import{useState as E}from"react";import{ExtensionProvider as M}from"@elrondnetwork/erdjs-extension-provider";D();G();U();F();var W=({callbackRoute:o,token:i,onLoginRedirect:h})=>{let[a,x]=E(""),[S,e]=E(!1),c=w(),p=I();function v(){return m(this,null,function*(){if(p)throw new Error(f);e(!0);let n=M.getInstance();try{if(!(yield n.init())){console.warn("Something went wrong trying to redirect to wallet login..");return}let P=encodeURIComponent(`${window.location.origin}${o!=null?o:window.location.pathname}`),O=d({callbackUrl:P},i&&{token:i});yield n.login(O),T(n);let{signature:s,address:g}=n.account;if(!g){e(!1),console.warn("Login cancelled.");return}s&&c(y({loginToken:String(i),signature:s})),c(L({address:g,loginMethod:"extension"})),u({callbackRoute:o,onLoginRedirect:h,options:{signature:s,address:g}})}catch(t){console.error("error loging in",t),x("error logging in"+t.message)}finally{e(!1)}})}let r=Boolean(a);return[v,{loginFailed:r,error:a,isLoading:S&&!r,isLoggedIn:p&&!r}]};export{W as a};
//# sourceMappingURL=chunk-CWHVVTE3.js.map