Skip to content

Commit

Permalink
header: fix message sign
Browse files Browse the repository at this point in the history
  • Loading branch information
inciner8r committed Feb 22, 2024
1 parent d0194a7 commit 6ef2591
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 46 deletions.
91 changes: 46 additions & 45 deletions webapp/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};

Expand All @@ -85,29 +85,35 @@ const Header = () => {
};
const connectPetra = async () => {
connect(wallets[0].name);

};

const disconnectPetra = () => {
disconnect();
};

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);
Expand All @@ -129,13 +135,11 @@ const Header = () => {
<ul className="menu menu-horizontal px-1">
<div className="flex space-x-2">
<li className="relative inline-block text-left">
<div className="absolute left-0 z-10 mt-2 origin-top-right rounded-md bg-none shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
<div className="-m-4" role="none">

</div>
</div>
<div className="absolute left-0 z-10 mt-2 origin-top-right rounded-md bg-none shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
<div className="-m-4" role="none"></div>
</div>
</li>
{!(connected) && (
{!connected && (
<li>
<button
onClick={() => connectPetra()}
Expand All @@ -146,26 +150,23 @@ const Header = () => {
</button>
</li>
)}
{(connected) && !(authContext?.isSignedIn) && (
<li>
<button
onClick={petraSign}
className="border text-blue-200 border-blue hover:bg-blue-300 hover:border-black hover:text-black font-bold transition focus:ring focus:ring-blue-500 focus:ring-opacity-80"
>
Sign In
</button>
</li>
)}
{connected && (
<li>
<div

className="border text-blue-200 border-blue hover:bg-blue-300 hover:border-black hover:text-black font-bold transition focus:ring focus:ring-blue-500 focus:ring-opacity-80"
>
Account: {account?.address.slice(0,8)}...
</div>
</li>
)}
{connected && !authContext?.isSignedIn && (
<li>
<button
onClick={petraSign}
className="border text-blue-200 border-blue hover:bg-blue-300 hover:border-black hover:text-black font-bold transition focus:ring focus:ring-blue-500 focus:ring-opacity-80"
>
Sign In
</button>
</li>
)}
{connected && (
<li>
<div className="border text-blue-200 border-blue hover:bg-blue-300 hover:border-black hover:text-black font-bold transition focus:ring focus:ring-blue-500 focus:ring-opacity-80">
Account: {account?.address.slice(0, 8)}...
</div>
</li>
)}
<li>
<button
onClick={navigateDashboard}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const { chains, provider, webSocketProvider } = configureChains(
const { connectors } = getDefaultWallets({
appName: "Sotreus",
chains,
projectId: process.env.WALLET_CONNECT_PROJECT_ID
projectId: process.env.WALLET_CONNECT_PROJECT_ID,
});

const wagmiClient = createClient({
Expand Down

0 comments on commit 6ef2591

Please sign in to comment.