-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add feature flag for social login (#2770)
* fix: Add feature flag for social login * fix: Show simple Connect button in case feature is disabled * fix: Remove redirects on the welcome page
- Loading branch information
1 parent
8e2d324
commit ea3763b
Showing
12 changed files
with
116 additions
and
48 deletions.
There are no files selected for viewing
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
18 changes: 18 additions & 0 deletions
18
src/components/common/ConnectWallet/__tests__/ConnectionCenter.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,18 @@ | ||
import { ConnectionCenter } from '@/components/common/ConnectWallet/ConnectionCenter' | ||
import { render } from '@/tests/test-utils' | ||
|
||
describe('ConnectionCenter', () => { | ||
it('displays a Connect wallet button if the social login feature is enabled', () => { | ||
const { getByText, queryByText } = render(<ConnectionCenter isSocialLoginEnabled={true} />) | ||
|
||
expect(getByText('Connect wallet')).toBeInTheDocument() | ||
expect(queryByText('Connect')).not.toBeInTheDocument() | ||
}) | ||
|
||
it('displays the ConnectWalletButton if the social login feature is disabled', () => { | ||
const { getByText, queryByText } = render(<ConnectionCenter isSocialLoginEnabled={false} />) | ||
|
||
expect(queryByText('Connect wallet')).not.toBeInTheDocument() | ||
expect(getByText('Connect')).toBeInTheDocument() | ||
}) | ||
}) |
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ import { act, render, waitFor } from '@/tests/test-utils' | |
|
||
import { SocialSigner, _getSupportedChains } from '@/components/common/SocialSigner' | ||
import { ONBOARD_MPC_MODULE_LABEL } from '@/services/mpc/SocialLoginModule' | ||
import { COREKIT_STATUS, type Web3AuthMPCCoreKit } from '@web3auth/mpc-core-kit' | ||
import { COREKIT_STATUS, type UserInfo, type Web3AuthMPCCoreKit } from '@web3auth/mpc-core-kit' | ||
import SocialWalletService from '@/services/mpc/SocialWalletService' | ||
import { TxModalProvider } from '@/components/tx-flow' | ||
import { fireEvent } from '@testing-library/react' | ||
|
@@ -51,7 +51,7 @@ describe('SocialSignerLogin', () => { | |
expect(mockOnLogin).toHaveBeenCalled() | ||
}) | ||
|
||
it('should render google login button and invoke the callback on connection if no wallet is connected on gnosis chain', async () => { | ||
it('should render google login button if no wallet is connected on gnosis chain', async () => { | ||
const mockOnLogin = jest.fn() | ||
|
||
const result = render( | ||
|
@@ -70,18 +70,30 @@ describe('SocialSignerLogin', () => { | |
expect(result.findByText('Continue with Google')).resolves.toBeDefined() | ||
expect(await result.findByRole('button')).toBeEnabled() | ||
}) | ||
}) | ||
|
||
// We do not automatically invoke the callback as the user did not actively connect | ||
expect(mockOnLogin).not.toHaveBeenCalled() | ||
it('should display a Continue as button and call onLogin when clicked', () => { | ||
const mockOnLogin = jest.fn() | ||
mockSocialWalletService.loginAndCreate = jest.fn(() => Promise.resolve(COREKIT_STATUS.LOGGED_IN)) | ||
|
||
const button = await result.findByRole('button') | ||
act(() => { | ||
button.click() | ||
}) | ||
const result = render( | ||
<TxModalProvider> | ||
<SocialSigner | ||
socialWalletService={mockSocialWalletService} | ||
wallet={mockWallet} | ||
supportedChains={['Goerli']} | ||
isMPCLoginEnabled={true} | ||
onLogin={mockOnLogin} | ||
/> | ||
</TxModalProvider>, | ||
) | ||
|
||
await waitFor(async () => { | ||
expect(mockOnLogin).toHaveBeenCalled() | ||
}) | ||
expect(result.getByText('Continue as Test Testermann')).toBeInTheDocument() | ||
|
||
const button = result.getByRole('button') | ||
button.click() | ||
|
||
expect(mockOnLogin).toHaveBeenCalled() | ||
}) | ||
|
||
it('should disable the Google Login button with a message when not on gnosis chain', async () => { | ||
|
@@ -98,10 +110,11 @@ describe('SocialSignerLogin', () => { | |
expect(await result.findByRole('button')).toBeDisabled() | ||
}) | ||
|
||
it('should display Password Recovery form and call onLogin if password recovery succeeds', async () => { | ||
it('should display Password Recovery form and display a Continue as button when login succeeds', async () => { | ||
const mockOnLogin = jest.fn() | ||
mockSocialWalletService.loginAndCreate = jest.fn(() => Promise.resolve(COREKIT_STATUS.REQUIRED_SHARE)) | ||
mockSocialWalletService.getUserInfo = jest.fn(undefined) | ||
mockSocialWalletService.recoverAccountWithPassword = jest.fn(() => Promise.resolve(true)) | ||
|
||
const result = render( | ||
<TxModalProvider> | ||
|
@@ -140,8 +153,17 @@ describe('SocialSignerLogin', () => { | |
submitButton.click() | ||
}) | ||
|
||
mockSocialWalletService.getUserInfo = jest.fn( | ||
() => | ||
({ | ||
email: '[email protected]', | ||
name: 'Test Testermann', | ||
profileImage: 'test.testermann.local/profile.png', | ||
} as unknown as UserInfo), | ||
) | ||
|
||
await waitFor(() => { | ||
expect(mockOnLogin).toHaveBeenCalled() | ||
expect(result.getByText('Continue as Test Testermann')).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
|
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
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
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
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