From c0647999061529cc821f3ddbef00402655bbea63 Mon Sep 17 00:00:00 2001 From: Shubham Gupta Date: Sat, 25 May 2024 22:22:19 +0530 Subject: [PATCH] Remove unwanted files and fix tests --- .../src/contexts/Account/AccountContext.ts | 30 --- .../src/contexts/Account/AccountProvider.tsx | 172 ------------------ packages/app/src/contexts/Account/index.ts | 2 - .../GoogleAuth/GoogleAuthProvider.tsx | 92 ++++------ packages/app/src/helpers/types/index.ts | 0 packages/app/src/helpers/types/loginStatus.ts | 8 - packages/app/src/hooks/useAccount.ts | 8 - packages/app/src/pages/MainPage.tsx | 6 +- 8 files changed, 34 insertions(+), 284 deletions(-) delete mode 100644 packages/app/src/contexts/Account/AccountContext.ts delete mode 100644 packages/app/src/contexts/Account/AccountProvider.tsx delete mode 100644 packages/app/src/contexts/Account/index.ts delete mode 100644 packages/app/src/helpers/types/index.ts delete mode 100644 packages/app/src/helpers/types/loginStatus.ts delete mode 100644 packages/app/src/hooks/useAccount.ts diff --git a/packages/app/src/contexts/Account/AccountContext.ts b/packages/app/src/contexts/Account/AccountContext.ts deleted file mode 100644 index 9e02379..0000000 --- a/packages/app/src/contexts/Account/AccountContext.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { createContext } from 'react'; - - -interface AccountValues { - isLoggedIn: boolean; - loggedInEthereumAddress: string | null; - loginStatus: string | null; - authenticatedLogout: (() => void) | null; - authenticatedLogin: (() => void) | null; - accountDisplay: string | null; - network: string | null; - connectStatus: string | null; - exportAuthenticatedWallet: (() => void) | null; -}; - -const defaultValues: AccountValues = { - isLoggedIn: false, - loggedInEthereumAddress: null, - loginStatus: null, - authenticatedLogout: null, - authenticatedLogin: null, - accountDisplay: null, - network: null, - connectStatus: null, - exportAuthenticatedWallet: null -}; - -const AccountContext = createContext(defaultValues); - -export default AccountContext; diff --git a/packages/app/src/contexts/Account/AccountProvider.tsx b/packages/app/src/contexts/Account/AccountProvider.tsx deleted file mode 100644 index cee6044..0000000 --- a/packages/app/src/contexts/Account/AccountProvider.tsx +++ /dev/null @@ -1,172 +0,0 @@ -import { useEffect, useState, ReactNode } from 'react'; -import { useAccount, useConnect, useDisconnect, useNetwork } from 'wagmi'; -import { useWallets } from '@privy-io/react-auth'; -import { usePrivyWagmi } from '@privy-io/wagmi-connector'; -import { usePrivy } from '@privy-io/react-auth'; - -import AccountContext from './AccountContext'; -import { esl } from '../../constants'; -import { formatAddress } from '../../helpers/addressFormat'; -import { LoginStatus, LoginStatusType } from '../../helpers/types/loginStatus'; - -interface ProvidersProps { - children: ReactNode; -} - -const AccountProvider = ({ children }: ProvidersProps) => { - const { address } = useAccount(); - const { chain } = useNetwork(); - const { disconnect } = useDisconnect(); - const { status: connectStatus } = useConnect(); - - const { wallets } = useWallets(); - const { wallet: activeWallet, setActiveWallet } = usePrivyWagmi(); - const { - authenticated, - logout: authenticatedLogout, - user, - login: authenticatedLogin, - exportWallet: exportAuthenticatedWallet - } = usePrivy(); - - /* - * State - */ - - const [isLoggedIn, setIsLoggedIn] = useState(false); - const [loginStatus, setLoginStatus] = useState(LoginStatus.LOGGED_OUT); - const [loggedInEthereumAddress, setLoggedInEthereumAddress] = useState(null); - const [accountDisplay, setAccountDisplay] = useState(null); - const [network, setNetwork] = useState(null); - - /* - * Hooks - */ - - useEffect(() => { - esl && console.log('activeWallet_1'); - esl && console.log('checking wallets: ', wallets); - esl && console.log('checking activeWallet: ', activeWallet); - - if (wallets[0] && !activeWallet) { - esl && console.log('activeWallet_2'); - setActiveWallet(wallets[0]); - } - }, [activeWallet, wallets, setActiveWallet]); - - useEffect(() => { - esl && console.log('loginStatus_1'); - esl && console.log('user: ', user); - - if (authenticated && user?.wallet?.connectorType) { - const connectorType = user.wallet.connectorType; - if (connectorType === 'embedded') { - esl && console.log('loginStatus_2'); - - setLoginStatus(LoginStatus.AUTHENTICATED); - } else if ( - connectorType === 'injected' || - connectorType === 'coinbase_wallet' || - connectorType === 'wallet_connect' || - connectorType === 'wallet_connect_v2' - ) { - esl && console.log('loginStatus_3'); - - setLoginStatus(LoginStatus.EOA); - } else { - esl && console.log('loginStatus_4'); - - setLoginStatus(LoginStatus.LOGGED_OUT); - } - } else { - esl && console.log('loginStatus_5'); - - setLoginStatus(LoginStatus.LOGGED_OUT); - } - }, [authenticated, user]); - - useEffect(() => { - esl && console.log('isLoggedIn_1'); - esl && console.log('checking loginStatus: ', loginStatus); - esl && console.log('user: ', user); - esl && console.log('address: ', address); - - switch (loginStatus) { - case LoginStatus.AUTHENTICATED: - if (address && user) { - esl && console.log('isLoggedIn_2'); - - if (user.email && user.email.address) { - setAccountDisplay(user.email.address); - } else if (user.google && user.google.email) { - setAccountDisplay(user.google.email); - } else if (user.twitter && user.twitter.username) { - setAccountDisplay(user.twitter.username); - } else if (user.farcaster && user.farcaster.displayName) { - setAccountDisplay(user.farcaster.displayName); - } else { - setAccountDisplay('Account'); - } - - setIsLoggedIn(true); - setLoggedInEthereumAddress(address); - } - break; - - case LoginStatus.EOA: - if (address) { - esl && console.log('isLoggedIn_3'); - - const formattedAddress = formatAddress(address); - - setAccountDisplay(formattedAddress); - setIsLoggedIn(true); - setLoggedInEthereumAddress(address); - } - break; - - case LoginStatus.LOGGED_OUT: - default: - esl && console.log('isLoggedIn_4'); - - setAccountDisplay(null); - setIsLoggedIn(false); - setLoggedInEthereumAddress(null); - } - }, [user, address, loginStatus, disconnect]); - - useEffect(() => { - esl && console.log('networkRaw_1'); - esl && console.log('checking chain: ', chain); - - if (chain) { - esl && console.log('networkRaw_2'); - - setNetwork(chain.network); - } else { - esl && console.log('networkRaw_3'); - - setNetwork(null); - } - }, [chain]); - - return ( - - {children} - - ); -}; - -export default AccountProvider; diff --git a/packages/app/src/contexts/Account/index.ts b/packages/app/src/contexts/Account/index.ts deleted file mode 100644 index 91841ae..0000000 --- a/packages/app/src/contexts/Account/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as AccountContext } from './AccountContext' -export { default as AccountProvider } from './AccountProvider' diff --git a/packages/app/src/contexts/GoogleAuth/GoogleAuthProvider.tsx b/packages/app/src/contexts/GoogleAuth/GoogleAuthProvider.tsx index e0941d2..c6377db 100644 --- a/packages/app/src/contexts/GoogleAuth/GoogleAuthProvider.tsx +++ b/packages/app/src/contexts/GoogleAuth/GoogleAuthProvider.tsx @@ -1,16 +1,15 @@ -import React, { useEffect, useState, ReactNode } from 'react' +import React, { useEffect, useState, ReactNode } from "react"; import { hasGrantedAllScopesGoogle, useGoogleLogin, googleLogout, -} from '@react-oauth/google'; +} from "@react-oauth/google"; // import GoogleAuthContext from './GoogleAuthContext' -import { fetchProfile } from '../../hooks/useGmailClient'; -import useAccount from '../../hooks/useAccount'; -import { esl } from '../../constants'; -import GoogleAuthContext from './GoogleAuthContext'; - +import { fetchProfile } from "../../hooks/useGmailClient"; +import useAccount from "../../hooks/useAccount"; +import { esl } from "../../constants"; +import GoogleAuthContext from "./GoogleAuthContext"; interface ProvidersProps { children: ReactNode; @@ -21,72 +20,44 @@ const GoogleAuthProvider = ({ children }: ProvidersProps) => { * Contexts */ - const { loggedInEthereumAddress } = useAccount() - /* * State Keys */ - const getGoogleAuthTokenKey = () => { - return `googleAuthToken_${loggedInEthereumAddress}`; - } - /* * State */ - const [googleAuthToken, setGoogleAuthToken] = useState( - () => { - const cachedToken = localStorage.getItem(getGoogleAuthTokenKey()); - return cachedToken ? JSON.parse(cachedToken) : null; - } - ); + const [googleAuthToken, setGoogleAuthToken] = useState(); const [isGoogleAuthed, setIsGoogleAuthed] = useState(false); const [isScopesApproved, setIsScopesApproved] = useState(false); const [loggedInGmail, setLoggedInGmail] = useState(null); - /* - * Hooks - */ - useEffect(() => { - esl && console.log('logoOutGoogleAuth'); - esl && console.log('checking loggedInEthereumAddress', loggedInEthereumAddress); - - if (!loggedInEthereumAddress) { - esl && console.log('logoOutGoogleAuth_1'); - - googleLogOut(); - } - - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [loggedInEthereumAddress]); - - useEffect(() => { - esl && console.log('googleAuthScopes_1'); - esl && console.log('checking googleAuthToken', googleAuthToken); + esl && console.log("googleAuthScopes_1"); + esl && console.log("checking googleAuthToken", googleAuthToken); if (googleAuthToken) { - esl && console.log('googleAuthScopes_2'); + esl && console.log("googleAuthScopes_2"); const allScope = hasGrantedAllScopesGoogle( googleAuthToken, - 'email', - 'profile', - 'https://www.googleapis.com/auth/gmail.readonly', + "email", + "profile", + "https://www.googleapis.com/auth/gmail.readonly" ); - + setIsScopesApproved(allScope); } }, [googleAuthToken]); useEffect(() => { - esl && console.log('googleProfile_1'); - esl && console.log('checking googleAuthToken', googleAuthToken); + esl && console.log("googleProfile_1"); + esl && console.log("checking googleAuthToken", googleAuthToken); if (googleAuthToken) { - esl && console.log('googleProfile_2'); + esl && console.log("googleProfile_2"); const fetchData = async () => { try { @@ -95,15 +66,15 @@ const GoogleAuthProvider = ({ children }: ProvidersProps) => { if (email) { setLoggedInGmail(email); - localStorage.setItem('loggedInEmail', email); + localStorage.setItem("loggedInEmail", email); } } catch (error) { - console.error('Error in fetching profile data:', error); + console.error("Error in fetching profile data:", error); } }; - + fetchData(); - }; + } }, [googleAuthToken]); /* @@ -111,13 +82,16 @@ const GoogleAuthProvider = ({ children }: ProvidersProps) => { */ const googleLogIn = useGoogleLogin({ - onSuccess: tokenResponse => { + onSuccess: (tokenResponse) => { setGoogleAuthToken(tokenResponse); setIsGoogleAuthed(true); - localStorage.setItem(getGoogleAuthTokenKey(), JSON.stringify(tokenResponse)); + localStorage.setItem( + getGoogleAuthTokenKey(), + JSON.stringify(tokenResponse) + ); }, - scope: 'email profile https://www.googleapis.com/auth/gmail.readonly', + scope: "email profile https://www.googleapis.com/auth/gmail.readonly", }); const googleLogOut = () => { @@ -125,13 +99,13 @@ const GoogleAuthProvider = ({ children }: ProvidersProps) => { setGoogleAuthToken(null); localStorage.removeItem(getGoogleAuthTokenKey()); - + setIsGoogleAuthed(false); - localStorage.removeItem('isGoogleAuthed'); - + localStorage.removeItem("isGoogleAuthed"); + setLoggedInGmail(null); - localStorage.removeItem('loggedInGmail'); - + localStorage.removeItem("loggedInGmail"); + googleLogout(); }; @@ -151,4 +125,4 @@ const GoogleAuthProvider = ({ children }: ProvidersProps) => { ); }; -export default GoogleAuthProvider +export default GoogleAuthProvider; diff --git a/packages/app/src/helpers/types/index.ts b/packages/app/src/helpers/types/index.ts deleted file mode 100644 index e69de29..0000000 diff --git a/packages/app/src/helpers/types/loginStatus.ts b/packages/app/src/helpers/types/loginStatus.ts deleted file mode 100644 index affed4e..0000000 --- a/packages/app/src/helpers/types/loginStatus.ts +++ /dev/null @@ -1,8 +0,0 @@ -export const LoginStatus = { - LOGGED_OUT: 'logged_out', - AUTHENTICATED: 'authenticated', - EOA: 'eoa' - }; - - export type LoginStatusType = typeof LoginStatus[keyof typeof LoginStatus]; - \ No newline at end of file diff --git a/packages/app/src/hooks/useAccount.ts b/packages/app/src/hooks/useAccount.ts deleted file mode 100644 index b744222..0000000 --- a/packages/app/src/hooks/useAccount.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { useContext } from 'react' -import { AccountContext } from '../contexts/Account' - -const useAccount = () => { - return { ...useContext(AccountContext) } -} - -export default useAccount diff --git a/packages/app/src/pages/MainPage.tsx b/packages/app/src/pages/MainPage.tsx index fa31636..c668a73 100644 --- a/packages/app/src/pages/MainPage.tsx +++ b/packages/app/src/pages/MainPage.tsx @@ -5,10 +5,6 @@ import styled from "styled-components"; import _ from "lodash"; import { useAccount, useContractWrite, usePrepareContractWrite } from "wagmi"; import { rawEmailToBuffer } from "@zk-email/helpers/dist/input-helpers"; -import { - verifyDKIMSignature, - DKIMVerificationResult, -} from "@zk-email/helpers/dist/dkim"; import { downloadProofFiles, generateProof, @@ -226,7 +222,7 @@ export const MainPage: React.FC<{}> = (props) => { } }; - useEffect(() => { + useUpdateEffect(() => { const downloadZKey = async () => { console.time("zk-dl");