Skip to content

Commit

Permalink
cleanup, fix dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
inciner8r committed Mar 3, 2024
1 parent 0bf3be6 commit 39df8ac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 59 deletions.
46 changes: 1 addition & 45 deletions webapp/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import { useWallet } from "@aptos-labs/wallet-adapter-react";
const Header = () => {
const navigate = useNavigate();
const authContext = useContext(AuthContext);
// const useraddress = useAccount();
const [message, setMessage] = useState<string>("");
const [challengeId, setChallengeId] = useState<string>("");
const [signature, setSignature] = useState<string | undefined>();

const {
connect,
Expand All @@ -28,44 +24,13 @@ const Header = () => {
await navigate("/dashboard");
};

const navigateServer = async () => {
await navigate("/server");
};

useEffect(() => {
const storedToken = localStorage.getItem("token");
if (storedToken) {
if (storedToken && connected) {
authContext?.setIsSignedIn(true);
}

let timeoutId: string | number | NodeJS.Timeout | null = null;
// console.log("tok", localStorage.getItem("token"));
// const getSignMessage = async () => {
// if (localStorage.getItem("token") !== null) {
// 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);
// // }
// // }
// timeoutId = setTimeout(() => {
// signOut();
// }, 500);
// } else {
// console.log("ojk");
// wallets[0].connect();
// }
// };

// getSignMessage();

return () => {
if (timeoutId !== null) {
Expand All @@ -74,15 +39,6 @@ const Header = () => {
};
}, [authContext?.isSignedIn, account?.address, connected]);

const signOut = () => {
sessionStorage.removeItem("token");
localStorage.removeItem("token");
localStorage.removeItem("AptosWalletName");
setMessage("");
setSignature("");
setChallengeId("");
authContext?.setIsSignedIn(false);
};
const connectPetra = async () => {
connect(wallets[0].name);
};
Expand Down
20 changes: 9 additions & 11 deletions webapp/src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useContext, useEffect, useState } from "react";
import { ClientContainer } from "../components/Dashboard/clientContainer";
import { Client } from "../components/Dashboard/types";
import { getClients } from "../modules/api";
import { useAccount } from "wagmi";

import Header from "../components/Header";
import Footer from "../components/Footer";
Expand Down Expand Up @@ -34,7 +33,6 @@ const Dashboard: React.FC = () => {

const [clients, setClients] = useState<Client[]>([]);
const [isLoading, setIsLoading] = useState(true);
const { address, isConnecting, isDisconnected } = useAccount();
const [clientOpen, setClientOpen] = useState<boolean>(true);

useEffect(() => {
Expand All @@ -44,7 +42,7 @@ const Dashboard: React.FC = () => {
setClients(clientData.clients);
setIsLoading(false);
}
if (localStorage.getItem("token")) {
if (localStorage.getItem("token")) {
fetchClients();
}
}, []);
Expand All @@ -58,21 +56,21 @@ const Dashboard: React.FC = () => {
// return <NotConnected />;
// }

if (isLoading || isConnecting) {
if (isLoading) {
return <DashboardLoader />;
}

// if (!authContext?.isAuthorized) {
// return <NotAuthorized />;
// }

// if (!authContext?.isSignedIn) {
// return (
// <div>
// <NotSigned component="Dashboard" />
// </div>
// );
// }
if (!authContext?.isSignedIn) {
return (
<div>
<NotSigned component="Dashboard" />
</div>
);
}

return (
<div>
Expand Down
4 changes: 1 addition & 3 deletions webapp/src/pages/Server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Header from "../components/Header";
import Footer from "../components/Footer";
import { saveAs } from "file-saver";
import ServerEdit from "../components/Server/ServerEdit";
import { useAccount } from "wagmi";
import NotSigned from "../components/NotSigned";
import { AuthContext } from "../context/AuthContext";
import NotAuthorized from "../components/NotAuthorized";
Expand All @@ -32,7 +31,6 @@ const ServerPage: React.FC = () => {
const [serverInfo, setServerInfo] = useState<any>(null);
const [serverConfig, setServerConfig] = useState<any>(null);
const [isLoading, setIsLoading] = useState(true);
const { address, isConnecting, isDisconnected } = useAccount();
const authContext = useContext(AuthContext);

const {
Expand Down Expand Up @@ -73,7 +71,7 @@ const ServerPage: React.FC = () => {
fetchData();
}, []);

if (isLoading || isConnecting) {
if (isLoading) {
return <CustomLoader />;
}

Expand Down

0 comments on commit 39df8ac

Please sign in to comment.