Skip to content

Commit

Permalink
[Seedless Onboarding] Only continue to safe creation if login succeeds (
Browse files Browse the repository at this point in the history
#2714)

* fix: Only continue to safe creation if login succeeds

* fix: Add new test case
  • Loading branch information
usame-algan authored Oct 31, 2023
1 parent 351b360 commit 4d2a81a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/welcome/WelcomeLogin/WalletLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const WalletLogin = ({ onLogin }: { onLogin: () => void }) => {

const login = async () => {
const walletState = await connectWallet()
if (walletState) {

if (walletState && walletState.length > 0) {
onLogin()
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/components/welcome/WelcomeLogin/__tests__/WalletLogin.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,27 @@ describe('WalletLogin', () => {
expect(mockOnLogin).toHaveBeenCalled()
})
})

it('should not invoke the callback if connection fails', async () => {
const mockOnLogin = jest.fn()
jest.spyOn(useConnectWallet, 'default').mockReturnValue(jest.fn().mockReturnValue([]))

const result = render(<WalletLogin onLogin={mockOnLogin} />)

await waitFor(() => {
expect(result.findByText('Connect wallet')).resolves.toBeDefined()
})

// We do not automatically invoke the callback as the user did not actively connect
expect(mockOnLogin).not.toHaveBeenCalled()

act(() => {
const button = result.getByRole('button')
button.click()
})

await waitFor(() => {
expect(mockOnLogin).not.toHaveBeenCalled()
})
})
})

0 comments on commit 4d2a81a

Please sign in to comment.