-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Open sea security provider warning message #17662
Merged
bschorchit
merged 9 commits into
develop
from
open-sea-security-provider-warning-message
Feb 23, 2023
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ead938d
Warning message for the OpenSea security provider
filipsekulic 507f1ea
Updated snapshots
filipsekulic d83157e
Removed flask usage
filipsekulic 17b766f
Covered more test cases
filipsekulic 7d86790
Code refactor
filipsekulic c7caadc
Fixed errors
filipsekulic c72bed0
Code refactor
filipsekulic 85db441
Fixed few issues
filipsekulic f25e7c0
Covered more code with tests
filipsekulic 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 @@ | ||
export { default } from './security-provider-banner-message'; |
5 changes: 5 additions & 0 deletions
5
...onents/app/security-provider-banner-message/security-provider-banner-message.constants.js
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,5 @@ | ||
export const SECURITY_PROVIDER_MESSAGE_SEVERITIES = { | ||
NOT_MALICIOUS: 0, | ||
MALICIOUS: 1, | ||
NOT_SAFE: 2, | ||
}; |
68 changes: 68 additions & 0 deletions
68
ui/components/app/security-provider-banner-message/security-provider-banner-message.js
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,68 @@ | ||
import React, { useContext } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
Color, | ||
SEVERITIES, | ||
Size, | ||
TypographyVariant, | ||
} from '../../../helpers/constants/design-system'; | ||
import { I18nContext } from '../../../../.storybook/i18n'; | ||
import { BannerAlert, ButtonLink } from '../../component-library'; | ||
import Typography from '../../ui/typography/typography'; | ||
import { SECURITY_PROVIDER_MESSAGE_SEVERITIES } from './security-provider-banner-message.constants'; | ||
|
||
export default function SecurityProviderBannerMessage({ | ||
securityProviderResponse, | ||
}) { | ||
const t = useContext(I18nContext); | ||
|
||
let messageTitle; | ||
let messageText; | ||
let severity; | ||
|
||
if ( | ||
securityProviderResponse.flagAsDangerous === | ||
SECURITY_PROVIDER_MESSAGE_SEVERITIES.MALICIOUS | ||
) { | ||
messageTitle = securityProviderResponse.reason_header; | ||
messageText = securityProviderResponse.reason; | ||
severity = SEVERITIES.DANGER; | ||
} else if ( | ||
securityProviderResponse.flagAsDangerous === | ||
SECURITY_PROVIDER_MESSAGE_SEVERITIES.NOT_SAFE | ||
) { | ||
messageTitle = t('requestMayNotBeSafe'); | ||
messageText = t('requestMayNotBeSafeError'); | ||
severity = SEVERITIES.WARNING; | ||
} else { | ||
messageTitle = t('requestNotVerified'); | ||
messageText = t('requestNotVerifiedError'); | ||
severity = SEVERITIES.WARNING; | ||
} | ||
|
||
return ( | ||
<BannerAlert | ||
marginTop={4} | ||
marginRight={4} | ||
marginLeft={4} | ||
title={messageTitle} | ||
severity={severity} | ||
> | ||
<Typography variant={TypographyVariant.H6}>{messageText}</Typography> | ||
<Typography variant={TypographyVariant.H7} color={Color.textAlternative}> | ||
{t('thisIsBasedOn')} | ||
<ButtonLink | ||
size={Size.inherit} | ||
href="https://opensea.io/" | ||
target="_blank" | ||
> | ||
{t('openSeaNew')} | ||
</ButtonLink> | ||
</Typography> | ||
</BannerAlert> | ||
); | ||
} | ||
|
||
SecurityProviderBannerMessage.propTypes = { | ||
securityProviderResponse: PropTypes.object, | ||
}; |
122 changes: 122 additions & 0 deletions
122
ui/components/app/security-provider-banner-message/security-provider-banner-message.test.js
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,122 @@ | ||
import { fireEvent } from '@testing-library/react'; | ||
import React from 'react'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import { renderWithProvider } from '../../../../test/lib/render-helpers'; | ||
import SecurityProviderBannerMessage from './security-provider-banner-message'; | ||
import { SECURITY_PROVIDER_MESSAGE_SEVERITIES } from './security-provider-banner-message.constants'; | ||
|
||
describe('Security Provider Banner Message', () => { | ||
const store = configureMockStore()({}); | ||
|
||
const thisIsBasedOnText = 'This is based on information from'; | ||
|
||
it('should render SecurityProviderBannerMessage component properly when flagAsDangerous is malicious', () => { | ||
const securityProviderResponse = { | ||
flagAsDangerous: SECURITY_PROVIDER_MESSAGE_SEVERITIES.MALICIOUS, | ||
reason: | ||
'Approval is to an unverified smart contract known for stealing NFTs in the past.', | ||
reason_header: 'This could be a scam', | ||
}; | ||
|
||
const { getByText } = renderWithProvider( | ||
<SecurityProviderBannerMessage | ||
securityProviderResponse={securityProviderResponse} | ||
/>, | ||
store, | ||
); | ||
|
||
expect(getByText(securityProviderResponse.reason)).toBeInTheDocument(); | ||
expect( | ||
getByText(securityProviderResponse.reason_header), | ||
).toBeInTheDocument(); | ||
expect(getByText(thisIsBasedOnText)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render SecurityProviderBannerMessage component properly when flagAsDangerous is not safe', () => { | ||
const securityProviderResponse = { | ||
flagAsDangerous: SECURITY_PROVIDER_MESSAGE_SEVERITIES.NOT_SAFE, | ||
reason: 'Some reason...', | ||
reason_header: 'Some reason header...', | ||
}; | ||
|
||
const requestMayNotBeSafe = 'Request may not be safe'; | ||
const requestMayNotBeSafeError = | ||
"The security provider didn't detect any known malicious activity, but it still may not be safe to continue."; | ||
|
||
const { getByText } = renderWithProvider( | ||
<SecurityProviderBannerMessage | ||
securityProviderResponse={securityProviderResponse} | ||
/>, | ||
store, | ||
); | ||
|
||
expect(getByText(requestMayNotBeSafe)).toBeInTheDocument(); | ||
expect(getByText(requestMayNotBeSafeError)).toBeInTheDocument(); | ||
expect(getByText(thisIsBasedOnText)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render SecurityProviderBannerMessage component properly when flagAsDangerous is undefined', () => { | ||
const securityProviderResponse = { | ||
flagAsDangerous: '?', | ||
reason: 'Some reason...', | ||
reason_header: 'Some reason header...', | ||
}; | ||
|
||
const requestNotVerified = 'Request not verified'; | ||
const requestNotVerifiedError = | ||
'Because of an error, this request was not verified by the security provider. Proceed with caution.'; | ||
|
||
const { getByText } = renderWithProvider( | ||
<SecurityProviderBannerMessage | ||
securityProviderResponse={securityProviderResponse} | ||
/>, | ||
store, | ||
); | ||
|
||
expect(getByText(requestNotVerified)).toBeInTheDocument(); | ||
expect(getByText(requestNotVerifiedError)).toBeInTheDocument(); | ||
expect(getByText(thisIsBasedOnText)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render SecurityProviderBannerMessage component properly when securityProviderResponse is empty', () => { | ||
const securityProviderResponse = {}; | ||
|
||
const requestNotVerified = 'Request not verified'; | ||
const requestNotVerifiedError = | ||
'Because of an error, this request was not verified by the security provider. Proceed with caution.'; | ||
|
||
const { getByText } = renderWithProvider( | ||
<SecurityProviderBannerMessage | ||
securityProviderResponse={securityProviderResponse} | ||
/>, | ||
store, | ||
); | ||
|
||
expect(getByText(requestNotVerified)).toBeInTheDocument(); | ||
expect(getByText(requestNotVerifiedError)).toBeInTheDocument(); | ||
expect(getByText(thisIsBasedOnText)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should navigate to the OpenSea web page when clicked on the OpenSea button', () => { | ||
const securityProviderResponse = { | ||
flagAsDangerous: SECURITY_PROVIDER_MESSAGE_SEVERITIES.NOT_SAFE, | ||
reason: 'Some reason...', | ||
reason_header: 'Some reason header...', | ||
}; | ||
|
||
const { getByText } = renderWithProvider( | ||
<SecurityProviderBannerMessage | ||
securityProviderResponse={securityProviderResponse} | ||
/>, | ||
store, | ||
); | ||
|
||
const link = getByText('OpenSea'); | ||
|
||
expect(link).toBeInTheDocument(); | ||
|
||
fireEvent.click(link); | ||
|
||
expect(link.closest('a')).toHaveAttribute('href', 'https://opensea.io/'); | ||
}); | ||
}); |
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.
Will be nice to have test coverage of the code change in this component.
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.
Fixed here: 40ce40f