Skip to content

Commit

Permalink
Merge pull request #8 from Bitbaza-Org/login_bug
Browse files Browse the repository at this point in the history
🐛Bug Fix: Login UI,state and handelling bug
  • Loading branch information
SAHU-01 authored Apr 15, 2024
2 parents 94052cd + 7a58560 commit 7b5402b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
18 changes: 10 additions & 8 deletions src/Login/LoginComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useEffect, useState, useContext } from "react";
import { Web3AuthNoModal } from "@web3auth/no-modal";
import { CHAIN_NAMESPACES, IProvider, WALLET_ADAPTERS, WEB3AUTH_NETWORK } from "@web3auth/base";
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
Expand All @@ -7,8 +7,10 @@ import "./login.css";
import RPC from "./web3RPC"; // for using web3.js

const clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ"; // get from https://dashboard.web3auth.io

function LoginComponent() {
interface LoginComponentProps {
onLogin: () => void; // Add a type for the onLogin prop
}
function LoginComponent({onLogin}:LoginComponentProps) {
const [web3auth, setWeb3auth] = useState<Web3AuthNoModal | null>(null);
const [provider, setProvider] = useState<IProvider | null>(null);
const [loggedIn, setLoggedIn] = useState<boolean>(false); // Modify here
Expand Down Expand Up @@ -44,10 +46,7 @@ function LoginComponent() {

await web3auth.init();
setProvider(web3auth.provider);
if (web3auth.connected) {
localStorage.setItem("userLoggedIn","true")
setLoggedIn(true);
}

} catch (error) {
console.error(error);
}
Expand All @@ -67,6 +66,9 @@ function LoginComponent() {
loginProvider: "google",
});
setProvider(web3authProvider);
setLoggedIn(true); // Set loggedIn to true after successful login
localStorage.setItem("userLoggedIn", "true");
onLogin();
};

const authenticateUser = async () => {
Expand Down Expand Up @@ -226,7 +228,7 @@ function LoginComponent() {

</h1>

<div className="grid">{loggedIn ? loggedInView : unloggedInView}</div>
<div className="grid">{!loggedIn ? unloggedInView : null}</div>

</div>
);
Expand Down
10 changes: 7 additions & 3 deletions src/common/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useContext } from 'react';
import {
Box,
ChakraProvider,
Expand Down Expand Up @@ -38,10 +38,14 @@ const App: React.FC = () => {
}
}, []);

const handleLogout = () => {
const handleLogout = async () => {
localStorage.setItem('userLoggedIn', 'false');
localStorage.removeItem('openlogin_store')
setLoggedIn(false);
};
const handleLogin = () => {
setLoggedIn(true);
};
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
setSelectedFile(file || null);
Expand Down Expand Up @@ -105,7 +109,7 @@ const App: React.FC = () => {
</Tabs>

) : (
<LoginComponent />
<LoginComponent onLogin={handleLogin}/>
)}
</Box>
</ChakraProvider>
Expand Down
4 changes: 3 additions & 1 deletion src/common/CredentialsComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const CredentialsComponent = () => {
useContext(ModalContext);
const { setShowCredentialsModal, addMessage, currentFunctionArguments } =
useChatStore((state) => state);
const [isLoading, setIsLoading] = useState(false);

const handlePasswordChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setPassword(e.target.value);
Expand All @@ -20,6 +21,7 @@ const CredentialsComponent = () => {
};

const handleSubmit = async () => {
setIsLoading(true);
if (password.trim() !== '' && privateKey.trim() !== '') {
const res = await taikoNodeEnvironmentSetup({
host: currentFunctionArguments.host,
Expand Down Expand Up @@ -53,7 +55,7 @@ const CredentialsComponent = () => {
onChange={handlePrivateKeyChange}
mb={6}
/>
<Button colorScheme="blue" onClick={handleSubmit} w="full" maxW="sm" mb={6}>
<Button colorScheme="blue" onClick={handleSubmit} w="full" maxW="sm" mb={6} isLoading={isLoading} loadingText="Setting environment...">
Submit
</Button>
</Flex>
Expand Down
4 changes: 3 additions & 1 deletion src/common/UpdatePasswordComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ChatMessage } from '../state/chat';
const UpdatePasswordComponent = () => {
const { currentPassword, setCurrentPassword, newPassword, setNewPassword } =
useContext(ModalContext);
const [isLoading, setIsLoading] = useState(false);

const { setShowUpdatePasswordModal, addMessage, currentFunctionArguments } =
useChatStore((state) => state);
Expand All @@ -22,6 +23,7 @@ const UpdatePasswordComponent = () => {
};

const handleSubmit = async () => {
setIsLoading(true);
if (currentPassword.trim() !== '' && newPassword.trim() !== '') {
const res = await changeNodePassword({
host: currentFunctionArguments.host,
Expand Down Expand Up @@ -57,7 +59,7 @@ const UpdatePasswordComponent = () => {
onChange={handleNewPasswordChange}
mb={6}
/>
<Button colorScheme="blue" onClick={handleSubmit} mb={4}>
<Button colorScheme="blue" onClick={handleSubmit} mb={4} isLoading={isLoading} loadingText="Updating password ...">
Update Password
</Button>
</Flex>
Expand Down

0 comments on commit 7b5402b

Please sign in to comment.