diff --git a/webapp/src/components/Header.tsx b/webapp/src/components/Header.tsx index 905769f..5cafa58 100644 --- a/webapp/src/components/Header.tsx +++ b/webapp/src/components/Header.tsx @@ -13,6 +13,8 @@ const Header = () => { const [Pubkey, setPubkey] = useState(""); const [message, setMessage] = useState(""); const [challengeId, setChallengeId] = useState(""); + const [show, setShow] = useState(false); + const [signed, setSigned] = useState(false); const [signature, setSignature] = useState(); const { signMessageAsync } = useSignMessage(); const { isConnected, address } = useAccount(); @@ -41,19 +43,22 @@ const Header = () => { const storedToken = localStorage.getItem("token"); if (storedToken) { authContext?.setIsSignedIn(true); + setShow(true) + setSigned(true) } let timeoutId: string | number | NodeJS.Timeout | null = null; const getSignMessage = async () => { - if (address == undefined) { - if (timeoutId !== null) { - clearTimeout(timeoutId); - } - - timeoutId = setTimeout(() => { - signOut(); - }, 500); - } else if (!authContext?.isSignedIn) { + // if (address == undefined) { + // if (timeoutId !== null) { + // clearTimeout(timeoutId); + // } + + // timeoutId = setTimeout(() => { + // signOut(); + // }, 500); + // } else + if (!authContext?.isSignedIn) { if (timeoutId !== null) { clearTimeout(timeoutId); } @@ -76,7 +81,7 @@ const Header = () => { clearTimeout(timeoutId); } }; - }, [authContext?.isSignedIn, address]); + }, [authContext?.isSignedIn]); // const signMessageFunc = async () => { // const signature = await signMessageAsync({ message }); @@ -110,29 +115,21 @@ const Header = () => { // }); connect(wallets[0].name); }; - const disconnectPetra = () => { - disconnect(); - }; const petraSign = async () => { const payload = { message: "Hello from Aptos Wallet Adapter", nonce: "random_string", }; - try { const res = await petraSignMesssage(payload); console.log("response", res); - const response = await getToken(signature, challengeId, Pubkey); - if (response.data.token) { + + const response = await getToken(signature, challengeId, Pubkey); //store the token in the session storage - sessionStorage.setItem("token", response.data.token); + console.log("set tokens", response.data.token) localStorage.setItem("token", response.data.token); authContext?.setIsSignedIn(true); - } - } catch (error: any) { - console.log("error", error); - } }; return (
@@ -155,34 +152,35 @@ const Header = () => {
- {(!address || authContext?.isSignedIn) && ( + {!show && (!address || authContext?.isSignedIn) && (
  • )} - {!(isConnected && authContext?.isSignedIn) && ( + {show && !(isConnected && authContext?.isSignedIn) && !signed && (
  • )} - {(authContext?.isSignedIn) && ( + {show && (
  • - Details + Account: {account?.address.slice(0,8)}...
  • )}