-
Notifications
You must be signed in to change notification settings - Fork 498
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(safe-apps): Add custom Safe App warning (#1258)
- Loading branch information
Showing
11 changed files
with
252 additions
and
21 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
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,32 @@ | ||
const appUrl = 'https://safe-custom-app.com' | ||
|
||
describe('When visiting a custom Safe App', () => { | ||
beforeEach(() => { | ||
cy.fixture('safe-app').then((html) => { | ||
cy.intercept('GET', `${appUrl}`, html) | ||
cy.intercept('GET', `${appUrl}/manifest.json`, { | ||
name: 'Cypress Test App', | ||
description: 'Cypress Test App Description', | ||
icons: [{ src: 'logo.svg', sizes: 'any', type: 'image/svg+xml' }], | ||
}) | ||
}) | ||
}) | ||
|
||
it('should show the custom app warning', () => { | ||
cy.visitSafeApp(`${appUrl}`) | ||
|
||
cy.findByText(/accept selection/i).click() | ||
cy.findByRole('heading', { content: /warning/i }) | ||
cy.findByText('https://safe-custom-app.com') | ||
cy.reload() | ||
cy.findByRole('heading', { content: /warning/i }) | ||
cy.findByText('https://safe-custom-app.com') | ||
}) | ||
|
||
it('should stop showing the warning when the check is marked', () => { | ||
cy.findByRole('checkbox').should('exist').click() | ||
cy.findByRole('button', { name: /continue/i }).click() | ||
cy.reload() | ||
cy.findByRole('heading', { content: /warning/i }).should('not.exist') | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react' | ||
import { Typography } from '@mui/material' | ||
import CheckIcon from '@mui/icons-material/Check' | ||
|
||
import styles from './styles.module.css' | ||
|
||
type DomainProps = { | ||
url: string | ||
showInOneLine?: boolean | ||
} | ||
|
||
const Domain: React.FC<DomainProps> = ({ url, showInOneLine }): React.ReactElement => { | ||
return ( | ||
<Typography className={styles.domainText} sx={showInOneLine ? { overflowY: 'hidden', whiteSpace: 'nowrap' } : {}}> | ||
<CheckIcon color="success" className={styles.domainIcon} /> {url} | ||
</Typography> | ||
) | ||
} | ||
|
||
export default Domain |
56 changes: 56 additions & 0 deletions
56
src/components/safe-apps/SafeAppsInfoModal/UnknownAppWarning.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,56 @@ | ||
import { useState } from 'react' | ||
import { Box, Checkbox, FormControlLabel, Typography } from '@mui/material' | ||
import WarningAmberOutlinedIcon from '@mui/icons-material/WarningAmberOutlined' | ||
import Domain from './Domain' | ||
import palette from '@/styles/colors' | ||
|
||
type UnknownAppWarningProps = { | ||
url?: string | ||
onHideWarning?: (hideWarning: boolean) => void | ||
} | ||
|
||
const UnknownAppWarning = ({ url, onHideWarning }: UnknownAppWarningProps): React.ReactElement => { | ||
const [toggleHideWarning, setToggleHideWarning] = useState(false) | ||
|
||
const handleToggleWarningPreference = (): void => { | ||
onHideWarning?.(!toggleHideWarning) | ||
setToggleHideWarning(!toggleHideWarning) | ||
} | ||
|
||
return ( | ||
<Box display="flex" flexDirection="column" height="100%" alignItems="center"> | ||
<Box display="block" alignItems="center" mt={6}> | ||
<WarningAmberOutlinedIcon fontSize="large" color="warning" /> | ||
<Typography variant="h3" fontWeight={700} mt={2} color={palette.warning.main}> | ||
Warning | ||
</Typography> | ||
</Box> | ||
<Typography my={2} fontWeight={700} color={palette.warning.main}> | ||
The application you are trying to access is not in the default Safe Apps list | ||
</Typography> | ||
|
||
<Typography my={2} textAlign="center"> | ||
Check the link you are using and ensure that it comes from a source you trust | ||
</Typography> | ||
|
||
{url && <Domain url={url} showInOneLine />} | ||
|
||
{onHideWarning && ( | ||
<Box mt={2}> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
checked={toggleHideWarning} | ||
onChange={handleToggleWarningPreference} | ||
name="Warning message preference" | ||
/> | ||
} | ||
label="Don't show this warning again" | ||
/> | ||
</Box> | ||
)} | ||
</Box> | ||
) | ||
} | ||
|
||
export default UnknownAppWarning |
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
Oops, something went wrong.