Skip to content
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

[Seedless Onboarding] QA fixes #2721

Merged
merged 11 commits into from
Nov 1, 2023
3 changes: 0 additions & 3 deletions src/components/common/ConnectWallet/ConnectionCenter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import KeyholeIcon from '@/components/common/icons/KeyholeIcon'
import WalletDetails from '@/components/common/ConnectWallet/WalletDetails'

import css from '@/components/common/ConnectWallet/styles.module.css'
import { useCurrentChain } from '@/hooks/useChains'

const ConnectionCenter = (): ReactElement => {
const chain = useCurrentChain()

const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null)
const open = !!anchorEl

Expand Down
1 change: 1 addition & 0 deletions src/components/common/ConnectWallet/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
align-items: center;
text-align: left;
gap: var(--space-1);
padding: 0 var(--space-2);
}

.popoverContainer {
Expand Down
7 changes: 5 additions & 2 deletions src/components/common/SocialLoginInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Typography } from '@mui/material'
import { Badge, Box, Typography } from '@mui/material'
import css from './styles.module.css'
import { type ChainInfo } from '@safe-global/safe-gateway-typescript-sdk'
import { type ConnectedWallet } from '@/services/onboard'
Expand Down Expand Up @@ -28,7 +28,10 @@ const SocialLoginInfo = ({

return (
<Box width="100%" display="flex" flexDirection="row" alignItems="center" gap={1}>
<img src={userInfo.profileImage} className={css.profileImg} alt="Profile Image" referrerPolicy="no-referrer" />
<Box position="relative">
<img src={userInfo.profileImage} className={css.profileImg} alt="Profile Image" referrerPolicy="no-referrer" />
{!socialWalletService?.isMFAEnabled() && <Badge variant="dot" color="warning" className={css.bubble} />}
</Box>
<div className={css.profileData}>
<Typography className={css.text} variant="body2" fontWeight={700}>
{userInfo.name}
Expand Down
16 changes: 14 additions & 2 deletions src/components/common/SocialLoginInfo/styles.module.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
.profileImg {
border-radius: var(--space-2);
width: 32px;
height: 32px;
width: 28px;
height: 28px;
display: block;
}

.bubble {
content: '';
position: absolute;
right: 3px;
bottom: 3px;
}

.bubble span {
outline: 1px solid var(--color-background-paper);
}

.profileData {
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/SocialSigner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export const SocialSigner = ({
ml: 0.5,
}}
/>
Currently only supported on {supportedChains.join(', ')}
Currently only supported on {supportedChains.join(', ')}. More network support coming soon.
</Typography>
)}
</>
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/WalletOverview/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
display: none;
}

.socialLoginInfo > div > div {
.socialLoginInfo > div > div:last-child {
display: none;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type PendingSafeData } from '@/components/new-safe/create/types'
import { renderHook } from '@/tests/test-utils'
import useSyncSafeCreationStep from '@/components/new-safe/create/useSyncSafeCreationStep'
import * as wallet from '@/hooks/wallets/useWallet'
Expand All @@ -21,10 +22,9 @@ describe('useSyncSafeCreationStep', () => {

beforeEach(() => {
jest.clearAllMocks()
const setPendingSafeSpy = jest.fn()
})

it('should go to the first step if no wallet is connected', async () => {
it('should go to the first step if no wallet is connected and there is no pending safe', async () => {
const mockPushRoute = jest.fn()
jest.spyOn(wallet, 'default').mockReturnValue(null)
jest.spyOn(usePendingSafe, 'usePendingSafe').mockReturnValue([undefined, setPendingSafeSpy])
Expand All @@ -39,6 +39,20 @@ describe('useSyncSafeCreationStep', () => {
expect(mockPushRoute).toHaveBeenCalledWith({ pathname: AppRoutes.welcome.index, query: undefined })
})

it('should not go to the first step if no wallet is connected but there is a pending safe', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case is a duplicate of "should go to the fourth step if there is a pending safe"
We could add the expectation not to call mockPushRoute to that test case.

const mockPushRoute = jest.fn()
jest.spyOn(wallet, 'default').mockReturnValue(null)
jest.spyOn(usePendingSafe, 'usePendingSafe').mockReturnValue([{} as PendingSafeData, setPendingSafeSpy])
jest.spyOn(useRouter, 'useRouter').mockReturnValue({
push: mockPushRoute,
} as unknown as NextRouter)
const mockSetStep = jest.fn()

renderHook(() => useSyncSafeCreationStep(mockSetStep))

expect(mockPushRoute).not.toHaveBeenCalled()
})

it('should go to the fourth step if there is a pending safe', async () => {
jest.spyOn(localStorage, 'default').mockReturnValue([{}, jest.fn()])
jest.spyOn(wallet, 'default').mockReturnValue({ address: '0x1' } as ConnectedWallet)
Expand Down
2 changes: 1 addition & 1 deletion src/components/new-safe/create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ const CreateSafe = () => {

<Grid item xs={12} md={4} mb={[3, null, 0]} order={[0, null, 1]}>
<Grid container spacing={3}>
{activeStep < 3 && <OverviewWidget safeName={safeName} />}
{activeStep < 2 && <OverviewWidget safeName={safeName} />}
{wallet?.address && <CreateSafeInfos staticHint={staticHint} dynamicHint={dynamicHint} />}
</Grid>
</Grid>
Expand Down
4 changes: 2 additions & 2 deletions src/components/new-safe/create/useSyncSafeCreationStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const useSyncSafeCreationStep = (setStep: StepRenderProps<NewSafeFormData>['setS
return
}

// Jump to connect wallet step if there is no wallet and no pending Safe
if (!wallet) {
// Jump to the welcome page if there is no wallet and no pending Safe
if (!wallet && !pendingSafe) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has no effect because the above condition returns if pendingSafe is defined.
The new test case also passes without this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this also doesn't fix the original issue when reloading the page since both wallet and pendingSafe are undefined at the start so the user always gets redirected back.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussion I have reverted this change again. We could also remove the hook from the status screen but I think currently it does no harm.

router.push({ pathname: AppRoutes.welcome.index, query: router.query })
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Chip, Grid, SvgIcon, Typography, IconButton } from '@mui/material'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { useCallback, useEffect, useRef } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import type { ReactElement } from 'react'

import { CustomTooltip } from '@/components/common/CustomTooltip'
Expand All @@ -26,6 +26,7 @@ import type { AddedSafesOnChain } from '@/store/addedSafesSlice'
import type { PushNotificationPreferences } from '@/services/push-notifications/preferences'
import type { NotifiableSafes } from '../logic'
import useWallet from '@/hooks/wallets/useWallet'
import CircularProgress from '@mui/material/CircularProgress'

import css from './styles.module.css'

Expand Down Expand Up @@ -103,6 +104,7 @@ const TrackBanner = (): null => {
}

export const PushNotificationsBanner = ({ children }: { children: ReactElement }): ReactElement => {
const [isSubmitting, setIsSubmitting] = useState<boolean>(false)
const isNotificationFeatureEnabled = useHasFeature(FEATURES.PUSH_NOTIFICATIONS)
const chain = useCurrentChain()
const totalAddedSafes = useAppSelector(selectTotalAdded)
Expand Down Expand Up @@ -136,6 +138,8 @@ export const PushNotificationsBanner = ({ children }: { children: ReactElement }
return
}

setIsSubmitting(true)

trackEvent(PUSH_NOTIFICATION_EVENTS.ENABLE_ALL)

const allPreferences = getAllPreferences()
Expand All @@ -144,11 +148,13 @@ export const PushNotificationsBanner = ({ children }: { children: ReactElement }
try {
await assertWalletChain(onboard, safe.chainId)
} catch {
setIsSubmitting(false)
return
}

await registerNotifications(safesToRegister)

setIsSubmitting(false)
dismissBanner()
}

Expand Down Expand Up @@ -195,7 +201,8 @@ export const PushNotificationsBanner = ({ children }: { children: ReactElement }
size="small"
className={css.button}
onClick={onEnableAll}
disabled={!isOk || !onboard}
startIcon={isSubmitting ? <CircularProgress size={12} color="inherit" /> : null}
disabled={!isOk || !onboard || isSubmitting}
>
Enable all
</Button>
Expand Down
4 changes: 4 additions & 0 deletions src/components/sidebar/SidebarNavigation/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ export const generalSettingsNavItems = [
label: 'Notifications',
href: AppRoutes.settings.notifications,
},
{
label: 'Security & Login',
href: AppRoutes.settings.securityLogin,
},
{
label: 'Data',
href: AppRoutes.settings.data,
Expand Down
Loading