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

feat: Adds opensea to blockaid migration BannerAlert #23743

Merged
merged 9 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default class PreferencesController {
eth_sign: false,
},
useMultiAccountBalanceChecker: true,
hasDismissedOpenSeaToBlockaidBanner: false,
useSafeChainsListValidation: true,
// set to true means the dynamic list from the API is being used
// set to false will be using the static list from contract-metadata
Expand Down Expand Up @@ -192,6 +193,14 @@ export default class PreferencesController {
this.store.updateState({ useMultiAccountBalanceChecker: val });
}

/**
* Setter for the `dismissOpenSeaToBlockaidBanner` property
*
*/
dismissOpenSeaToBlockaidBanner() {
this.store.updateState({ hasDismissedOpenSeaToBlockaidBanner: true });
}

/**
* Setter for the `useSafeChainsListValidation` property
*
Expand Down
17 changes: 17 additions & 0 deletions app/scripts/controllers/preferences.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,23 @@ describe('preferences controller', () => {
});
});

describe('dismissOpenSeaToBlockaidBanner', () => {
it('hasDismissedOpenSeaToBlockaidBanner should default to false', () => {
expect(
preferencesController.store.getState()
.hasDismissedOpenSeaToBlockaidBanner,
).toStrictEqual(false);
});

it('should set the hasDismissedOpenSeaToBlockaidBanner property in state', () => {
preferencesController.dismissOpenSeaToBlockaidBanner();
expect(
preferencesController.store.getState()
.hasDismissedOpenSeaToBlockaidBanner,
).toStrictEqual(true);
});
});

describe('setUseSafeChainsListValidation', function () {
it('should default to true', function () {
const state = preferencesController.store.getState();
Expand Down
1 change: 1 addition & 0 deletions app/scripts/lib/setupSentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export const SENTRY_BACKGROUND_STATE = {
useTokenDetection: true,
useRequestQueue: true,
useTransactionSimulations: true,
hasDismissedOpenSeaToBlockaidBanner: true,
},
SelectedNetworkController: { domains: false },
SignatureController: {
Expand Down
4 changes: 4 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2879,6 +2879,10 @@ export default class MetamaskController extends EventEmitter {
preferencesController.setUseMultiAccountBalanceChecker.bind(
preferencesController,
),
dismissOpenSeaToBlockaidBanner:
preferencesController.dismissOpenSeaToBlockaidBanner.bind(
preferencesController,
),
setUseSafeChainsListValidation:
preferencesController.setUseSafeChainsListValidation.bind(
preferencesController,
Expand Down
3 changes: 2 additions & 1 deletion app/scripts/migrations/114.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('migration #114', () => {
});

describe('deprecates transactionSecurityCheckEnabled in PreferencesController', () => {
it('sets securityAlertsEnabled to true if transactionSecurityCheckEnabled is true', async () => {
it('sets securityAlertsEnabled and hasMigratedFromOpenSeaToBlockaid to true if transactionSecurityCheckEnabled is true', async () => {
const oldStorage = {
PreferencesController: {
transactionSecurityCheckEnabled: true,
Expand All @@ -32,6 +32,7 @@ describe('migration #114', () => {
const expectedState = {
PreferencesController: {
securityAlertsEnabled: true,
hasMigratedFromOpenSeaToBlockaid: true,
},
};

Expand Down
1 change: 1 addition & 0 deletions app/scripts/migrations/114.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function transformState(state: Record<string, any>) {
) {
if (state.PreferencesController.transactionSecurityCheckEnabled) {
state.PreferencesController.securityAlertsEnabled = true;
state.PreferencesController.hasMigratedFromOpenSeaToBlockaid = true;
}

delete state.PreferencesController.transactionSecurityCheckEnabled;
Expand Down
135 changes: 135 additions & 0 deletions test/e2e/tests/ppom/migrate-opensea-to-blockaid-banner.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
const { connectAccountToTestDapp } = require('../../accounts/common');
const FixtureBuilder = require('../../fixture-builder');
const {
defaultGanacheOptions,
unlockWallet,
withFixtures,
openDapp,
WINDOW_TITLES,
} = require('../../helpers');

describe('Migrate Opensea to Blockaid Banner @no-mmi', function () {
it('Shows up on simple send transaction', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPreferencesController({ hasMigratedFromOpenSeaToBlockaid: true })
.build(),
ganacheOptions: defaultGanacheOptions,
title: this.test.fullTitle(),
},
async ({ driver }) => {
await driver.navigate();
await unlockWallet(driver);
await openDapp(driver);

await connectAccountToTestDapp(driver);

await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.clickElement('#sendButton');
await driver.delay(2000);

await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.waitForSelector({ text: 'Heads up!', tag: 'p' });
},
);
});

it('Shows up on token approval', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPreferencesController({ hasMigratedFromOpenSeaToBlockaid: true })
.build(),
ganacheOptions: defaultGanacheOptions,
title: this.test.fullTitle(),
},
async ({ driver }) => {
await driver.navigate();
await unlockWallet(driver);
await openDapp(driver);

await connectAccountToTestDapp(driver);

await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.findClickableElement('#createToken');
await driver.clickElement('#createToken');
await driver.delay(2000);

await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.findClickableElements({
text: 'Confirm',
tag: 'button',
});
await driver.clickElement({
text: 'Confirm',
tag: 'button',
});

await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.clickElement({ text: 'Approve Tokens', tag: 'button' });
await driver.delay(2000);

await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.waitForSelector({ text: 'Heads up!', tag: 'p' });
},
);
});

it('Shows up on personal signature', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPreferencesController({ hasMigratedFromOpenSeaToBlockaid: true })
.build(),
ganacheOptions: defaultGanacheOptions,
title: this.test.fullTitle(),
},
async ({ driver }) => {
await driver.navigate();
await unlockWallet(driver);
await openDapp(driver);

await connectAccountToTestDapp(driver);

await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.clickElement('#personalSign');
await driver.delay(2000);

await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.waitForSelector({ text: 'Heads up!', tag: 'p' });
},
);
});

it('Shows up on contract interaction', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPreferencesController({ hasMigratedFromOpenSeaToBlockaid: true })
.build(),
ganacheOptions: defaultGanacheOptions,
title: this.test.fullTitle(),
},
async ({ driver }) => {
await driver.navigate();
await unlockWallet(driver);
await openDapp(driver);

await connectAccountToTestDapp(driver);

await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);

await driver.clickElement('#deployMultisigButton');
await driver.delay(2000);

await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.waitForSelector({ text: 'Heads up!', tag: 'p' });
},
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
"addSnapAccountEnabled": "boolean",
"advancedGasFee": {},
"featureFlags": {},
"hasDismissedOpenSeaToBlockaidBanner": false,
"incomingTransactionsPreferences": {},
"knownMethodData": "object",
"currentLocale": "en",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"showAccountBanner": true,
"trezorModel": null,
"hadAdvancedGasFeesSetPriorToMigration92_3": false,
"hasDismissedOpenSeaToBlockaidBanner": false,
"nftsDropdownState": {},
"termsOfUseLastAgreed": "number",
"qrHardware": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
TextAlign,
TextColor,
Size,
Severity,
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
IconColor,
Display,
Expand All @@ -36,6 +37,7 @@ import {
} from '../../../../helpers/constants/design-system';
import {
ButtonLink,
BannerAlert,
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
Box,
Icon,
Expand Down Expand Up @@ -85,6 +87,10 @@ export default class SignatureRequestOriginal extends Component {
mostRecentOverviewPage: PropTypes.string.isRequired,
resolvePendingApproval: PropTypes.func.isRequired,
completedTx: PropTypes.func.isRequired,
hasMigratedFromOpenSeaToBlockaid: PropTypes.bool.isRequired,
isNetworkSupportedByBlockaid: PropTypes.bool.isRequired,
hasDismissedOpenSeaToBlockaidBanner: PropTypes.bool.isRequired,
dismissOpenSeaToBlockaidBanner: PropTypes.func.isRequired,
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
// Used to show a warning if the signing account is not the selected account
// Largely relevant for contract wallet custodians
Expand Down Expand Up @@ -129,6 +135,8 @@ export default class SignatureRequestOriginal extends Component {
};

renderBody = () => {
const { t } = this.context;

let rows;
const notice = `${this.context.t('youSign')}:`;

Expand All @@ -150,6 +158,20 @@ export default class SignatureRequestOriginal extends Component {
? subjectMetadata?.[txData.msgParams.origin]
: null;

const {
hasMigratedFromOpenSeaToBlockaid,
isNetworkSupportedByBlockaid,
hasDismissedOpenSeaToBlockaidBanner,
dismissOpenSeaToBlockaidBanner,
} = this.props;
const showOpenSeaToBlockaidBannerAlert =
hasMigratedFromOpenSeaToBlockaid &&
!isNetworkSupportedByBlockaid &&
!hasDismissedOpenSeaToBlockaidBanner;
const handleCloseOpenSeaToBlockaidBannerAlert = () => {
dismissOpenSeaToBlockaidBanner();
};

return (
<div className="request-signature__body">
{
Expand All @@ -162,6 +184,23 @@ export default class SignatureRequestOriginal extends Component {
securityProviderResponse={txData.securityProviderResponse}
/>
)}
{showOpenSeaToBlockaidBannerAlert ? (
<BannerAlert
severity={Severity.Info}
title={t('openSeaToBlockaidTitle')}
description={t('openSeaToBlockaidDescription')}
actionButtonLabel={t('openSeaToBlockaidBtnLabel')}
actionButtonProps={{
href: 'https://snaps.metamask.io/transaction-insights',
externalLink: true,
}}
marginBottom={4}
marginLeft={4}
marginTop={4}
marginRight={4}
onClose={handleCloseOpenSeaToBlockaidBannerAlert}
/>
) : null}
{
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
this.props.selectedAccount.address ===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
rejectPendingApproval,
rejectAllMessages,
completedTx,
dismissOpenSeaToBlockaidBanner,
} from '../../../../store/actions';
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
// eslint-disable-next-line import/order
Expand All @@ -22,6 +23,9 @@ import {
doesAddressRequireLedgerHidConnection,
unconfirmedMessagesHashSelector,
getTotalUnapprovedMessagesCount,
getIsNetworkSupportedByBlockaid,
getHasDismissedOpenSeaToBlockaidBanner,
getHasMigratedFromOpenSeaToBlockaid,
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
getAccountType,
getSelectedInternalAccount,
Expand All @@ -44,6 +48,12 @@ function mapStateToProps(state, ownProps) {
const messagesList = unconfirmedMessagesHashSelector(state);
const messagesCount = getTotalUnapprovedMessagesCount(state);

const hasMigratedFromOpenSeaToBlockaid =
getHasMigratedFromOpenSeaToBlockaid(state);
const hasDismissedOpenSeaToBlockaidBanner =
getHasDismissedOpenSeaToBlockaidBanner(state);
const isNetworkSupportedByBlockaid = getIsNetworkSupportedByBlockaid(state);

return {
requester: null,
requesterAddress: null,
Expand All @@ -55,6 +65,9 @@ function mapStateToProps(state, ownProps) {
subjectMetadata: getSubjectMetadata(state),
messagesList,
messagesCount,
hasMigratedFromOpenSeaToBlockaid,
hasDismissedOpenSeaToBlockaidBanner,
isNetworkSupportedByBlockaid,
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
accountType: getAccountType(state),
selectedAccount: getSelectedInternalAccount(state),
Expand Down Expand Up @@ -90,6 +103,8 @@ mapDispatchToProps = function (dispatch) {
cancelAllApprovals: (messagesList) => {
dispatch(rejectAllMessages(messagesList));
},
dismissOpenSeaToBlockaidBanner: () =>
dispatch(dismissOpenSeaToBlockaidBanner()),
};
};

Expand Down
Loading
Loading