From c7473acbe78cece9b01f53361bae0c2c65bb8b43 Mon Sep 17 00:00:00 2001 From: Brian Rossetti Date: Tue, 12 Jul 2022 16:43:04 -0600 Subject: [PATCH] adjusting follow up items from conversation with chris --- src/pages/LitProtocolGoogle.jsx | 63 ++++++++++----------------------- src/utils/litProtocol.js | 12 +++++-- 2 files changed, 28 insertions(+), 47 deletions(-) diff --git a/src/pages/LitProtocolGoogle.jsx b/src/pages/LitProtocolGoogle.jsx index 1f8ef855d..699000a43 100644 --- a/src/pages/LitProtocolGoogle.jsx +++ b/src/pages/LitProtocolGoogle.jsx @@ -9,22 +9,20 @@ import TextBox from '../components/TextBox'; import { useInjectedProvider } from '../contexts/InjectedProviderContext'; import { useOverlay } from '../contexts/OverlayContext'; import { + buildLitUrl, checkIfUserExists, deleteShare, deleteStoredAuthSigs, getSharedDaoGoogleDocs, handleLitServerError, handleLoadCurrentUser, - LIT_API_HOST, loadStoredAuthSig, redirectToLitOauthUI, signOutUser, - STANDARD_CONTRACT_TYPE, storeAuthSig, } from '../utils/litProtocol'; -import { capitalize } from '../utils/general'; -import { Bold } from '../components/typography'; +import { debounce } from '../utils/debounce'; const LitProtocolGoogle = ({ isMember, daoMetaData }) => { const { address } = useInjectedProvider(); @@ -89,15 +87,13 @@ const LitProtocolGoogle = ({ isMember, daoMetaData }) => { } }, [daoMetaData?.boosts, authSig, profile]); - const performWithAuthSig = async ( - callback, - { chain } = { chain: 'ethereum' }, - ) => { + const performWithAuthSig = async callback => { let currentAuthSig = authSig; try { let userExists; - currentAuthSig = await await LitJsSdk.checkAndSignAuthMessage({ - chain, + currentAuthSig = await LitJsSdk.checkAndSignAuthMessage({ + // agnostic signature; Lit only needs the wallet address + chain: null, }); storeAuthSig(currentAuthSig, address, daoMetaData?.contractAddress); setAuthSig(currentAuthSig); @@ -108,8 +104,10 @@ const LitProtocolGoogle = ({ isMember, daoMetaData }) => { return; } else { // https://github.com/LIT-Protocol/lit-oauth/blob/51b6efc4c45ee6b0bf0ebfed4f8713c6c045b954/server/oauth/google.js#L104 - warningToast({ title: 'Redirecting you to lit oauth connect UI' }); - await redirectToLitOauthUI(); + warningToast({ + title: 'Redirecting you to lit oauth connect UI for login', + }); + debounce(await redirectToLitOauthUI(daoMetaData, currentAuthSig), 400); } await callback(currentAuthSig); @@ -121,17 +119,12 @@ const LitProtocolGoogle = ({ isMember, daoMetaData }) => { const handleSignAuthMessage = async () => { setLoading(true); try { - await performWithAuthSig( - async authSig => { - setProfile(await handleLoadCurrentUser(authSig)); - setLoading(false); - }, - { - chain: daoMetaData?.network, - }, - ); + await performWithAuthSig(async authSig => { + setProfile(await handleLoadCurrentUser(authSig)); + setLoading(false); + }); } catch (e) { - errorToast(e); + errorToast({ title: e.errorCode }); setLoading(false); } }; @@ -154,38 +147,18 @@ const LitProtocolGoogle = ({ isMember, daoMetaData }) => { isMember && ( - - 1) This link will redirect you to the{' '} - Lit App Portal where you will have to connect to google - via mainnet - - - - - - 2) Reconnect to{' '} - {capitalize(daoMetaData?.network)} - after step 1 and generate an authentication token. - ); - const addNewGoogleDoc = isMember && ( + const addNewGoogleDoc = isMember && authSig && (