From 6ef2591fc8546049a2c6f7b235f286e461bac4c9 Mon Sep 17 00:00:00 2001 From: Punarv Pawade Date: Thu, 22 Feb 2024 19:32:52 +0530 Subject: [PATCH] header: fix message sign --- webapp/src/components/Header.tsx | 91 ++++++++++++++++---------------- webapp/src/index.tsx | 2 +- 2 files changed, 47 insertions(+), 46 deletions(-) diff --git a/webapp/src/components/Header.tsx b/webapp/src/components/Header.tsx index 041548c..5d3620d 100644 --- a/webapp/src/components/Header.tsx +++ b/webapp/src/components/Header.tsx @@ -43,25 +43,25 @@ const Header = () => { const getSignMessage = async () => { if (localStorage.getItem("token") === "") { - console.log("clearing localstorage") + console.log("clearing localstorage"); if (timeoutId !== null) { clearTimeout(timeoutId); } - if (account?.address){ - const response = await getChallengeId(account?.address); - setMessage(response.data.eula); - setChallengeId(response.data.challangeId); - if (response.data.isAuthorized == true) { - authContext?.setIsAuthorized(true); - } else { - authContext?.setIsAuthorized(false); - } - } + // if (account?.address) { + // const response = await getChallengeId(account?.address); + // setMessage(response.data.eula); + // setChallengeId(response.data.challangeId); + // if (response.data.isAuthorized == true) { + // authContext?.setIsAuthorized(true); + // } else { + // authContext?.setIsAuthorized(false); + // } + // } timeoutId = setTimeout(() => { signOut(); }, 500); } else { - wallets[0].connect() + wallets[0].connect(); } }; @@ -85,7 +85,6 @@ const Header = () => { }; const connectPetra = async () => { connect(wallets[0].name); - }; const disconnectPetra = () => { @@ -93,21 +92,28 @@ const Header = () => { }; const petraSign = async () => { - const payload = { - message: message, - nonce: challengeId, - }; try { + const Challengeresponse = await getChallengeId(account?.address); + + const payload = { + message: Challengeresponse.data.eula, + nonce: Challengeresponse.data.challangeId, + }; + const signres = await petraSignMesssage(payload); console.log("response", signres); - const response = await getToken(`0x${signres?.signature}`, challengeId, account?.publicKey); + const response = await getToken( + `0x${signres?.signature}`, + Challengeresponse.data.challangeId, + account?.publicKey + ); if (response.data.token) { sessionStorage.setItem("token", response.data.token); localStorage.setItem("token", response.data.token); authContext?.setIsSignedIn(true); } - + authContext?.setIsAuthorized(true); authContext?.setIsSignedIn(true); } catch (error: any) { console.log("error", error); @@ -129,13 +135,11 @@ const Header = () => {