-
Notifications
You must be signed in to change notification settings - Fork 464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: redesign welcome page #2593
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
23b2a1f
feat: redesign welcome page
schmanu e82432b
test: WalletLogin test, adjust button height
schmanu 3f81598
tests: fix useSyncSafeCreationStep.test.ts
schmanu b337400
tests: MPCLogin test
schmanu 81ddddb
fix: test name
schmanu b3e8295
fix: minHeight of WalletLogin button
schmanu 351ae0c
fix: icon color, social login check
schmanu 3d0f363
fix: review issues (1)
schmanu 796bd35
fix: review issues (2)
schmanu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { MPCWalletState } from '@/hooks/wallets/mpc/useMPCWallet' | ||
import { Box, Button, SvgIcon, Typography } from '@mui/material' | ||
import { useContext, useEffect, useState } from 'react' | ||
import { MpcWalletContext } from './MPCWalletProvider' | ||
import { PasswordRecovery } from './PasswordRecovery' | ||
import GoogleLogo from '@/public/images/welcome/logo-google.svg' | ||
|
||
import css from './styles.module.css' | ||
import useWallet from '@/hooks/wallets/useWallet' | ||
|
||
const MPCLogin = ({ onLogin }: { onLogin?: () => void }) => { | ||
const { loginPending, triggerLogin, userInfo, walletState, recoverFactorWithPassword } = useContext(MpcWalletContext) | ||
|
||
const wallet = useWallet() | ||
|
||
const [loginTriggered, setLoginTriggered] = useState(false) | ||
|
||
const login = async () => { | ||
setLoginTriggered(true) | ||
await triggerLogin() | ||
} | ||
|
||
// If login was triggered through the Button we immediately continue if logged in | ||
useEffect(() => { | ||
if (loginTriggered && wallet && onLogin) { | ||
onLogin() | ||
} | ||
}, [loginTriggered, onLogin, wallet]) | ||
|
||
return ( | ||
<> | ||
{wallet && userInfo.email ? ( | ||
<> | ||
<Button | ||
variant="outlined" | ||
sx={{ padding: '8px 16px' }} | ||
schmanu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
onClick={onLogin} | ||
size="small" | ||
disabled={loginPending} | ||
fullWidth | ||
> | ||
<Box | ||
width="100%" | ||
justifyContent="space-between" | ||
display="flex" | ||
flexDirection="row" | ||
alignItems="center" | ||
gap={1} | ||
> | ||
<img | ||
src={userInfo.profileImage} | ||
className={css.profileImg} | ||
alt="Profile Image" | ||
referrerPolicy="no-referrer" | ||
/> | ||
<div className={css.profileData}> | ||
<Typography variant="subtitle2" fontWeight={700}> | ||
Continue as {userInfo.name} | ||
</Typography> | ||
<Typography variant="body2">{userInfo.email}</Typography> | ||
</div> | ||
<SvgIcon component={GoogleLogo} inheritViewBox fontSize="medium" /> | ||
</Box> | ||
</Button> | ||
</> | ||
) : ( | ||
<Button variant="outlined" onClick={login} size="small" disabled={loginPending} fullWidth> | ||
<Box display="flex" flexDirection="row" alignItems="center" gap={1}> | ||
<SvgIcon component={GoogleLogo} inheritViewBox fontSize="medium" /> Continue with Google | ||
</Box> | ||
</Button> | ||
)} | ||
|
||
{walletState === MPCWalletState.MANUAL_RECOVERY && ( | ||
<PasswordRecovery recoverFactorWithPassword={recoverFactorWithPassword} /> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
export default MPCLogin |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/components/common/ConnectWallet/__tests__/MPCLogin.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { act, render, waitFor } from '@/tests/test-utils' | ||
import * as useWallet from '@/hooks/wallets/useWallet' | ||
import * as useMPCWallet from '@/hooks/wallets/mpc/useMPCWallet' | ||
import MPCLogin from '../MPCLogin' | ||
import { hexZeroPad } from '@ethersproject/bytes' | ||
import { type EIP1193Provider } from '@web3-onboard/common' | ||
import { ONBOARD_MPC_MODULE_LABEL } from '@/services/mpc/module' | ||
import { MpcWalletProvider } from '../MPCWalletProvider' | ||
|
||
describe('MPCLogin', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
it('should render continue with connected account', async () => { | ||
const mockOnLogin = jest.fn() | ||
const walletAddress = hexZeroPad('0x1', 20) | ||
jest.spyOn(useWallet, 'default').mockReturnValue({ | ||
address: walletAddress, | ||
chainId: '5', | ||
label: ONBOARD_MPC_MODULE_LABEL, | ||
provider: {} as unknown as EIP1193Provider, | ||
}) | ||
jest.spyOn(useMPCWallet, 'useMPCWallet').mockReturnValue({ | ||
userInfo: { | ||
email: '[email protected]', | ||
name: 'Test Testermann', | ||
profileImage: 'test.png', | ||
}, | ||
triggerLogin: jest.fn(), | ||
walletState: useMPCWallet.MPCWalletState.READY, | ||
} as unknown as useMPCWallet.MPCWalletHook) | ||
|
||
const result = render( | ||
<MpcWalletProvider> | ||
<MPCLogin onLogin={mockOnLogin} /> | ||
</MpcWalletProvider>, | ||
) | ||
|
||
await waitFor(() => { | ||
expect(result.findByText('Continue as Test Testermann')).resolves.toBeDefined() | ||
}) | ||
|
||
// We do not automatically invoke the callback as the user did not actively connect | ||
expect(mockOnLogin).not.toHaveBeenCalled() | ||
|
||
const button = await result.findByRole('button') | ||
button.click() | ||
|
||
expect(mockOnLogin).toHaveBeenCalled() | ||
}) | ||
|
||
it('should render google login button and invoke the callback on connection if no wallet is connected', async () => { | ||
const mockOnLogin = jest.fn() | ||
const walletAddress = hexZeroPad('0x1', 20) | ||
const mockUseWallet = jest.spyOn(useWallet, 'default').mockReturnValue(null) | ||
const mockTriggerLogin = jest.fn() | ||
const mockUseMPCWallet = jest.spyOn(useMPCWallet, 'useMPCWallet').mockReturnValue({ | ||
userInfo: { | ||
email: undefined, | ||
name: undefined, | ||
profileImage: undefined, | ||
}, | ||
triggerLogin: mockTriggerLogin, | ||
walletState: useMPCWallet.MPCWalletState.NOT_INITIALIZED, | ||
} as unknown as useMPCWallet.MPCWalletHook) | ||
|
||
const result = render( | ||
<MpcWalletProvider> | ||
<MPCLogin onLogin={mockOnLogin} /> | ||
</MpcWalletProvider>, | ||
) | ||
|
||
await waitFor(() => { | ||
expect(result.findByText('Continue with Google')).resolves.toBeDefined() | ||
}) | ||
|
||
// We do not automatically invoke the callback as the user did not actively connect | ||
expect(mockOnLogin).not.toHaveBeenCalled() | ||
|
||
await act(async () => { | ||
// Click the button and mock a successful login | ||
const button = await result.findByRole('button') | ||
button.click() | ||
mockUseMPCWallet.mockReset().mockReturnValue({ | ||
userInfo: { | ||
email: '[email protected]', | ||
name: 'Test Testermann', | ||
profileImage: 'test.png', | ||
}, | ||
triggerLogin: jest.fn(), | ||
walletState: useMPCWallet.MPCWalletState.READY, | ||
} as unknown as useMPCWallet.MPCWalletHook) | ||
|
||
mockUseWallet.mockReset().mockReturnValue({ | ||
address: walletAddress, | ||
chainId: '5', | ||
label: ONBOARD_MPC_MODULE_LABEL, | ||
provider: {} as unknown as EIP1193Provider, | ||
}) | ||
}) | ||
|
||
await waitFor(() => { | ||
expect(mockOnLogin).toHaveBeenCalled() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call
onLogin
insidelogin
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so.
When
triggerLogin
resolves, it might result in aMANUAL_RECOVERY
state, which will pop up the Password recovery modal.So we have to react to a side effect here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here: Calling the callback after triggerLogin / recoverPassword resolves causes the useSyncSafeCreationStep to immediately redirect us back.