From 0e2ed4f0e47aeaa8dd95bd2b50080d30f143f320 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Tue, 26 Mar 2024 14:53:22 +0000 Subject: [PATCH 1/9] wip --- app/scripts/migrations/114.ts | 1 + .../confirm-transaction-base.component.js | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/app/scripts/migrations/114.ts b/app/scripts/migrations/114.ts index 9052e44a8efa..0c68f0fa294d 100644 --- a/app/scripts/migrations/114.ts +++ b/app/scripts/migrations/114.ts @@ -43,6 +43,7 @@ function transformState(state: Record) { ) { if (state.PreferencesController.transactionSecurityCheckEnabled) { state.PreferencesController.securityAlertsEnabled = true; + state.PreferencesController.hasUserMigratedFromOpenSeaToBlockaid = true; } delete state.PreferencesController.transactionSecurityCheckEnabled; diff --git a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js index 2e684d2dae67..55b5fde30de4 100644 --- a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js +++ b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js @@ -65,6 +65,8 @@ import SnapAccountTransactionLoadingScreen from '../../snap-account-transaction- import { isHardwareKeyring } from '../../../helpers/utils/hardware'; import FeeDetailsComponent from '../components/fee-details-component/fee-details-component'; import { SimulationDetails } from '../components/simulation-details'; +import { BannerAlert, BannerBase } from '../../../components/component-library'; +import { Severity } from '../../../helpers/constants/design-system'; export default class ConfirmTransactionBase extends Component { static contextTypes = { @@ -182,6 +184,7 @@ export default class ConfirmTransactionBase extends Component { ///: BEGIN:ONLY_INCLUDE_IF(build-mmi) noteText: '', ///: END:ONLY_INCLUDE_IF + showBanner: true, }; componentDidUpdate(prevProps) { @@ -516,8 +519,32 @@ export default class ConfirmTransactionBase extends Component { /> ); + // migratedTheUserFromOpensea && !seenAndDismissed + const showBlockaidBannerAlert = this.state.showBanner; + const handleCloseBlockaidBannerAlert = () => { + // dispatch seenAndDismissed= true + this.setState({ showBanner: false }); + }; + return (
+ {showBlockaidBannerAlert ? ( + + ) : null} From 37621a5df48b1fc1e4b1546704a8026792b36fa2 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Tue, 26 Mar 2024 19:08:41 +0000 Subject: [PATCH 2/9] feat: Adds opensea to blockaid migration BannerAlert --- app/_locales/en/messages.json | 9 ++ app/scripts/controllers/preferences.js | 9 ++ app/scripts/controllers/preferences.test.js | 17 +++ app/scripts/metamask-controller.js | 4 + app/scripts/migrations/114.test.ts | 3 +- app/scripts/migrations/114.ts | 2 +- ...migrate-opensea-to-blockaid-banner.spec.js | 144 ++++++++++++++++++ .../signature-request-original.component.js | 35 +++++ .../signature-request-original.container.js | 15 ++ .../confirm-transaction-base.component.js | 28 ++-- .../confirm-transaction-base.container.js | 15 ++ .../token-allowance/token-allowance.js | 53 ++++++- ui/selectors/selectors.js | 22 +++ ui/selectors/selectors.test.js | 34 +++++ ui/store/actions.ts | 17 +++ 15 files changed, 393 insertions(+), 14 deletions(-) create mode 100644 test/e2e/tests/ppom/migrate-opensea-to-blockaid-banner.spec.js diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index c7acae9705c9..0f8cb41d4e59 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -3317,6 +3317,15 @@ "openSeaNew": { "message": "OpenSea" }, + "openSeaToBlockaidBtnLabel": { + "message": "Explore Snaps" + }, + "openSeaToBlockaidDescription": { + "message": "Security alerts are no longer available on this network. Installing a Snap may improve your security." + }, + "openSeaToBlockaidTitle": { + "message": "Heads up!" + }, "operationFailed": { "message": "Operation Failed" }, diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index b12f02c4da03..a3e9a56d9f19 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -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 @@ -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 * diff --git a/app/scripts/controllers/preferences.test.js b/app/scripts/controllers/preferences.test.js index bca97e6657e9..4f666c03e527 100644 --- a/app/scripts/controllers/preferences.test.js +++ b/app/scripts/controllers/preferences.test.js @@ -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(); diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 5ab12ea3e351..3279b6acb348 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -2879,6 +2879,10 @@ export default class MetamaskController extends EventEmitter { preferencesController.setUseMultiAccountBalanceChecker.bind( preferencesController, ), + dismissOpenSeaToBlockaidBanner: + preferencesController.dismissOpenSeaToBlockaidBanner.bind( + preferencesController, + ), setUseSafeChainsListValidation: preferencesController.setUseSafeChainsListValidation.bind( preferencesController, diff --git a/app/scripts/migrations/114.test.ts b/app/scripts/migrations/114.test.ts index 0184d753652f..10474bc2c262 100644 --- a/app/scripts/migrations/114.test.ts +++ b/app/scripts/migrations/114.test.ts @@ -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, @@ -32,6 +32,7 @@ describe('migration #114', () => { const expectedState = { PreferencesController: { securityAlertsEnabled: true, + hasMigratedFromOpenSeaToBlockaid: true, }, }; diff --git a/app/scripts/migrations/114.ts b/app/scripts/migrations/114.ts index 0c68f0fa294d..2288dc84d612 100644 --- a/app/scripts/migrations/114.ts +++ b/app/scripts/migrations/114.ts @@ -43,7 +43,7 @@ function transformState(state: Record) { ) { if (state.PreferencesController.transactionSecurityCheckEnabled) { state.PreferencesController.securityAlertsEnabled = true; - state.PreferencesController.hasUserMigratedFromOpenSeaToBlockaid = true; + state.PreferencesController.hasMigratedFromOpenSeaToBlockaid = true; } delete state.PreferencesController.transactionSecurityCheckEnabled; diff --git a/test/e2e/tests/ppom/migrate-opensea-to-blockaid-banner.spec.js b/test/e2e/tests/ppom/migrate-opensea-to-blockaid-banner.spec.js new file mode 100644 index 000000000000..0ca532327aae --- /dev/null +++ b/test/e2e/tests/ppom/migrate-opensea-to-blockaid-banner.spec.js @@ -0,0 +1,144 @@ +// const { strict: assert } = require('assert'); +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({ + preferences: { 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({ + preferences: { 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({ + preferences: { 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.only('Shows up on contract interaction', async function () { + await withFixtures( + { + dapp: true, + fixtures: new FixtureBuilder() + .withPreferencesController({ + preferences: { 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' }); + }, + ); + }); +}); diff --git a/ui/pages/confirmations/components/signature-request-original/signature-request-original.component.js b/ui/pages/confirmations/components/signature-request-original/signature-request-original.component.js index 5afe027b3f65..111a2ab8dad0 100644 --- a/ui/pages/confirmations/components/signature-request-original/signature-request-original.component.js +++ b/ui/pages/confirmations/components/signature-request-original/signature-request-original.component.js @@ -26,6 +26,7 @@ import { TextAlign, TextColor, Size, + Severity, ///: BEGIN:ONLY_INCLUDE_IF(build-mmi) IconColor, Display, @@ -36,6 +37,7 @@ import { } from '../../../../helpers/constants/design-system'; import { ButtonLink, + BannerAlert, ///: BEGIN:ONLY_INCLUDE_IF(build-mmi) Box, Icon, @@ -129,6 +131,8 @@ export default class SignatureRequestOriginal extends Component { }; renderBody = () => { + const { t } = this.context; + let rows; const notice = `${this.context.t('youSign')}:`; @@ -150,6 +154,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 (
{ @@ -162,6 +180,23 @@ export default class SignatureRequestOriginal extends Component { securityProviderResponse={txData.securityProviderResponse} /> )} + {showOpenSeaToBlockaidBannerAlert ? ( + + ) : null} { ///: BEGIN:ONLY_INCLUDE_IF(build-mmi) this.props.selectedAccount.address === diff --git a/ui/pages/confirmations/components/signature-request-original/signature-request-original.container.js b/ui/pages/confirmations/components/signature-request-original/signature-request-original.container.js index 0d0b981c7409..2c671a10f94a 100644 --- a/ui/pages/confirmations/components/signature-request-original/signature-request-original.container.js +++ b/ui/pages/confirmations/components/signature-request-original/signature-request-original.container.js @@ -8,6 +8,7 @@ import { rejectPendingApproval, rejectAllMessages, completedTx, + dismissOpenSeaToBlockaidBanner, } from '../../../../store/actions'; ///: BEGIN:ONLY_INCLUDE_IF(build-mmi) // eslint-disable-next-line import/order @@ -22,6 +23,9 @@ import { doesAddressRequireLedgerHidConnection, unconfirmedMessagesHashSelector, getTotalUnapprovedMessagesCount, + getIsNetworkSupportedByBlockaid, + getHasDismissedOpenSeaToBlockaidBanner, + getHasMigratedFromOpenSeaToBlockaid, ///: BEGIN:ONLY_INCLUDE_IF(build-mmi) getAccountType, getSelectedInternalAccount, @@ -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, @@ -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), @@ -90,6 +103,8 @@ mapDispatchToProps = function (dispatch) { cancelAllApprovals: (messagesList) => { dispatch(rejectAllMessages(messagesList)); }, + dismissOpenSeaToBlockaidBanner: () => + dispatch(dismissOpenSeaToBlockaidBanner()), }; }; diff --git a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js index 55b5fde30de4..00d1cc716687 100644 --- a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js +++ b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js @@ -67,6 +67,7 @@ import FeeDetailsComponent from '../components/fee-details-component/fee-details import { SimulationDetails } from '../components/simulation-details'; import { BannerAlert, BannerBase } from '../../../components/component-library'; import { Severity } from '../../../helpers/constants/design-system'; +import { SUPPORTED_CHAIN_IDS } from '../../../../app/scripts/lib/ppom/ppom-middleware'; export default class ConfirmTransactionBase extends Component { static contextTypes = { @@ -396,6 +397,10 @@ export default class ConfirmTransactionBase extends Component { tokenSymbol, isUsingPaymaster, isMultiLayerFeeNetwork, + hasMigratedFromOpenSeaToBlockaid, + hasDismissedOpenSeaToBlockaidBanner, + dismissOpenSeaToBlockaidBanner, + isNetworkSupportedByBlockaid, } = this.props; const { t } = this.context; @@ -519,30 +524,31 @@ export default class ConfirmTransactionBase extends Component { /> ); - // migratedTheUserFromOpensea && !seenAndDismissed - const showBlockaidBannerAlert = this.state.showBanner; - const handleCloseBlockaidBannerAlert = () => { - // dispatch seenAndDismissed= true - this.setState({ showBanner: false }); + const showOpenSeaToBlockaidBannerAlert = + hasMigratedFromOpenSeaToBlockaid && + !isNetworkSupportedByBlockaid && + !hasDismissedOpenSeaToBlockaidBanner; + const handleCloseOpenSeaToBlockaidBannerAlert = () => { + dismissOpenSeaToBlockaidBanner(); }; return (
- {showBlockaidBannerAlert ? ( + {showOpenSeaToBlockaidBannerAlert ? ( ) : null} { const isUserOpContractDeployError = fullTxData.isUserOperation && type === TransactionType.deployContract; + const hasMigratedFromOpenSeaToBlockaid = + getHasMigratedFromOpenSeaToBlockaid(state); + const hasDismissedOpenSeaToBlockaidBanner = + getHasDismissedOpenSeaToBlockaidBanner(state); + const isNetworkSupportedByBlockaid = getIsNetworkSupportedByBlockaid(state); + return { balance, fromAddress, @@ -335,6 +345,9 @@ const mapStateToProps = (state, ownProps) => { custodianPublishesTransaction, rpcUrl, ///: END:ONLY_INCLUDE_IF + hasMigratedFromOpenSeaToBlockaid, + hasDismissedOpenSeaToBlockaidBanner, + isNetworkSupportedByBlockaid, }; }; @@ -425,6 +438,8 @@ export const mapDispatchToProps = (dispatch) => { setWaitForConfirmDeepLinkDialog: (wait) => dispatch(mmiActions.setWaitForConfirmDeepLinkDialog(wait)), ///: END:ONLY_INCLUDE_IF + dismissOpenSeaToBlockaidBanner: () => + dispatch(dismissOpenSeaToBlockaidBanner()), }; }; diff --git a/ui/pages/confirmations/token-allowance/token-allowance.js b/ui/pages/confirmations/token-allowance/token-allowance.js index 63f977e7ae41..3fead3454196 100644 --- a/ui/pages/confirmations/token-allowance/token-allowance.js +++ b/ui/pages/confirmations/token-allowance/token-allowance.js @@ -14,6 +14,7 @@ import { FLEX_DIRECTION, FontWeight, JustifyContent, + Severity, TextAlign, TextColor, TextVariant, @@ -36,6 +37,9 @@ import { getTargetAccountWithSendEtherInfo, getCustomNonceValue, getNextSuggestedNonce, + getHasMigratedFromOpenSeaToBlockaid, + getIsNetworkSupportedByBlockaid, + getHasDismissedOpenSeaToBlockaidBanner, } from '../../../selectors'; import { NETWORK_TO_NAME_MAP } from '../../../../shared/constants/network'; import { @@ -45,6 +49,7 @@ import { updateAndApproveTx, getNextNonce, updateCustomNonce, + dismissOpenSeaToBlockaidBanner, } from '../../../store/actions'; import { clearConfirmTransaction } from '../../../ducks/confirm-transaction/confirm-transaction.duck'; import { getMostRecentOverviewPage } from '../../../ducks/history/history'; @@ -71,7 +76,12 @@ import { useSimulationFailureWarning } from '../hooks/useSimulationFailureWarnin import SimulationErrorMessage from '../components/simulation-error-message'; import LedgerInstructionField from '../components/ledger-instruction-field/ledger-instruction-field'; import SecurityProviderBannerMessage from '../components/security-provider-banner-message/security-provider-banner-message'; -import { Icon, IconName, Text } from '../../../components/component-library'; +import { + BannerAlert, + Icon, + IconName, + Text, +} from '../../../components/component-library'; import { ConfirmPageContainerWarning } from '../components/confirm-page-container/confirm-page-container-content'; import CustomNonce from '../components/custom-nonce'; import FeeDetailsComponent from '../components/fee-details-component/fee-details-component'; @@ -336,6 +346,30 @@ export default function TokenAllowance({ txData.securityAlertResponse?.result_type === BlockaidResultType.Malicious ? 'danger-primary' : 'primary'; + + const hasMigratedFromOpenSeaToBlockaid = useSelector( + getHasMigratedFromOpenSeaToBlockaid, + ); + const isNetworkSupportedByBlockaid = useSelector( + getIsNetworkSupportedByBlockaid, + ); + const hasDismissedOpenSeaToBlockaidBanner = useSelector( + getHasDismissedOpenSeaToBlockaidBanner, + ); + + const showOpenSeaToBlockaidBannerAlert = + hasMigratedFromOpenSeaToBlockaid && + !isNetworkSupportedByBlockaid && + !hasDismissedOpenSeaToBlockaidBanner; + + console.log({ + hasMigratedFromOpenSeaToBlockaid, + isNetworkSupportedByBlockaid, + hasDismissedOpenSeaToBlockaidBanner, + }); + const handleCloseOpenSeaToBlockaidBannerAlert = () => { + dispatch(dismissOpenSeaToBlockaidBanner()); + }; return ( @@ -387,6 +421,23 @@ export default function TokenAllowance({ ///: END:ONLY_INCLUDE_IF } + {showOpenSeaToBlockaidBannerAlert ? ( + + ) : null} {isSuspiciousResponse(txData?.securityProviderResponse) && ( { }); }); + describe('#getIsNetworkSupportedByBlockaid', () => { + it('returns true if current network is Linea', () => { + const modifiedMockState = { + ...mockState, + metamask: { + ...mockState.metamask, + providerConfig: { + ...mockState.metamask.providerConfig, + chainId: CHAIN_IDS.LINEA_MAINNET, + }, + }, + }; + const isSupported = + selectors.getIsNetworkSupportedByBlockaid(modifiedMockState); + expect(isSupported).toBe(true); + }); + + it('returns false if current network is Goerli', () => { + const modifiedMockState = { + ...mockState, + metamask: { + ...mockState.metamask, + providerConfig: { + ...mockState.metamask.providerConfig, + chainId: CHAIN_IDS.GOERLI, + }, + }, + }; + const isSupported = + selectors.getIsNetworkSupportedByBlockaid(modifiedMockState); + expect(isSupported).toBe(true); + }); + }); + describe('#getAllEnabledNetworks', () => { it('returns only Mainnet and Linea with showTestNetworks off', () => { const networks = selectors.getAllEnabledNetworks({ diff --git a/ui/store/actions.ts b/ui/store/actions.ts index e782f6e6a834..3205f3fd9d1b 100644 --- a/ui/store/actions.ts +++ b/ui/store/actions.ts @@ -3168,6 +3168,23 @@ export function setUseMultiAccountBalanceChecker( }; } +export function dismissOpenSeaToBlockaidBanner(): ThunkAction< + void, + MetaMaskReduxState, + unknown, + AnyAction +> { + return (dispatch: MetaMaskReduxDispatch) => { + // skipping loading indication as it blips in the UI and looks weird + log.debug(`background.dismissOpenSeaToBlockaidBanner`); + callBackgroundMethod('dismissOpenSeaToBlockaidBanner', [], (err) => { + if (err) { + dispatch(displayWarning(err)); + } + }); + }; +} + export function setUseSafeChainsListValidation( val: boolean, ): ThunkAction { From 519644272ee7278b15db3262f08b9af95f0a2134 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Tue, 26 Mar 2024 19:26:34 +0000 Subject: [PATCH 3/9] wip --- test/e2e/tests/ppom/migrate-opensea-to-blockaid-banner.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/tests/ppom/migrate-opensea-to-blockaid-banner.spec.js b/test/e2e/tests/ppom/migrate-opensea-to-blockaid-banner.spec.js index 0ca532327aae..8ae153f85d79 100644 --- a/test/e2e/tests/ppom/migrate-opensea-to-blockaid-banner.spec.js +++ b/test/e2e/tests/ppom/migrate-opensea-to-blockaid-banner.spec.js @@ -112,7 +112,7 @@ describe('Migrate Opensea to Blockaid Banner @no-mmi', function () { ); }); - it.only('Shows up on contract interaction', async function () { + it('Shows up on contract interaction', async function () { await withFixtures( { dapp: true, From aefa3d7584a103df15a3ec5d1ebd01dddf10fb54 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Wed, 27 Mar 2024 10:30:51 +0000 Subject: [PATCH 4/9] clean up --- .../migrate-opensea-to-blockaid-banner.spec.js | 17 ++++------------- .../token-allowance/token-allowance.js | 5 ----- ui/selectors/selectors.js | 8 +------- 3 files changed, 5 insertions(+), 25 deletions(-) diff --git a/test/e2e/tests/ppom/migrate-opensea-to-blockaid-banner.spec.js b/test/e2e/tests/ppom/migrate-opensea-to-blockaid-banner.spec.js index 8ae153f85d79..7cc1a78c7279 100644 --- a/test/e2e/tests/ppom/migrate-opensea-to-blockaid-banner.spec.js +++ b/test/e2e/tests/ppom/migrate-opensea-to-blockaid-banner.spec.js @@ -1,4 +1,3 @@ -// const { strict: assert } = require('assert'); const { connectAccountToTestDapp } = require('../../accounts/common'); const FixtureBuilder = require('../../fixture-builder'); const { @@ -15,9 +14,7 @@ describe('Migrate Opensea to Blockaid Banner @no-mmi', function () { { dapp: true, fixtures: new FixtureBuilder() - .withPreferencesController({ - preferences: { hasMigratedFromOpenSeaToBlockaid: true }, - }) + .withPreferencesController({ hasMigratedFromOpenSeaToBlockaid: true }) .build(), ganacheOptions: defaultGanacheOptions, title: this.test.fullTitle(), @@ -44,9 +41,7 @@ describe('Migrate Opensea to Blockaid Banner @no-mmi', function () { { dapp: true, fixtures: new FixtureBuilder() - .withPreferencesController({ - preferences: { hasMigratedFromOpenSeaToBlockaid: true }, - }) + .withPreferencesController({ hasMigratedFromOpenSeaToBlockaid: true }) .build(), ganacheOptions: defaultGanacheOptions, title: this.test.fullTitle(), @@ -88,9 +83,7 @@ describe('Migrate Opensea to Blockaid Banner @no-mmi', function () { { dapp: true, fixtures: new FixtureBuilder() - .withPreferencesController({ - preferences: { hasMigratedFromOpenSeaToBlockaid: true }, - }) + .withPreferencesController({ hasMigratedFromOpenSeaToBlockaid: true }) .build(), ganacheOptions: defaultGanacheOptions, title: this.test.fullTitle(), @@ -117,9 +110,7 @@ describe('Migrate Opensea to Blockaid Banner @no-mmi', function () { { dapp: true, fixtures: new FixtureBuilder() - .withPreferencesController({ - preferences: { hasMigratedFromOpenSeaToBlockaid: true }, - }) + .withPreferencesController({ hasMigratedFromOpenSeaToBlockaid: true }) .build(), ganacheOptions: defaultGanacheOptions, title: this.test.fullTitle(), diff --git a/ui/pages/confirmations/token-allowance/token-allowance.js b/ui/pages/confirmations/token-allowance/token-allowance.js index 3fead3454196..eed5a269a1f8 100644 --- a/ui/pages/confirmations/token-allowance/token-allowance.js +++ b/ui/pages/confirmations/token-allowance/token-allowance.js @@ -362,11 +362,6 @@ export default function TokenAllowance({ !isNetworkSupportedByBlockaid && !hasDismissedOpenSeaToBlockaidBanner; - console.log({ - hasMigratedFromOpenSeaToBlockaid, - isNetworkSupportedByBlockaid, - hasDismissedOpenSeaToBlockaidBanner, - }); const handleCloseOpenSeaToBlockaidBannerAlert = () => { dispatch(dismissOpenSeaToBlockaidBanner()); }; diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index 8c50c55cdb68..0f4a20eaf7ca 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -2298,16 +2298,10 @@ export function getShowFiatInTestnets(state) { } export function getHasMigratedFromOpenSeaToBlockaid(state) { - const { hasMigratedFromOpenSeaToBlockaid } = getPreferences(state); - return Boolean(hasMigratedFromOpenSeaToBlockaid); + return Boolean(state.metamask.hasMigratedFromOpenSeaToBlockaid); } export function getHasDismissedOpenSeaToBlockaidBanner(state) { - console.log({ - state, - hasDismissedOpenSeaToBlockaidBanner: - state.metamask.hasDismissedOpenSeaToBlockaidBanner, - }); return Boolean(state.metamask.hasDismissedOpenSeaToBlockaidBanner); } From c12be7d590f02687d9c229932918808981e72519 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Wed, 27 Mar 2024 10:42:11 +0000 Subject: [PATCH 5/9] fix tests --- ui/selectors/selectors.js | 4 ++-- ui/selectors/selectors.test.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index 0f4a20eaf7ca..5b17fcee14b8 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -1790,8 +1790,8 @@ export function getCurrentNetwork(state) { } export function getIsNetworkSupportedByBlockaid(state) { - const currentNetwork = getCurrentNetwork(state); - const isSupported = SUPPORTED_CHAIN_IDS.includes(currentNetwork.chainId); + const currentChainId = getCurrentChainId(state); + const isSupported = SUPPORTED_CHAIN_IDS.includes(currentChainId); return isSupported; } diff --git a/ui/selectors/selectors.test.js b/ui/selectors/selectors.test.js index 191885f09d34..e5257269cb0e 100644 --- a/ui/selectors/selectors.test.js +++ b/ui/selectors/selectors.test.js @@ -556,7 +556,7 @@ describe('Selectors', () => { }; const isSupported = selectors.getIsNetworkSupportedByBlockaid(modifiedMockState); - expect(isSupported).toBe(true); + expect(isSupported).toBe(false); }); }); From 3b98bc3d4b399a880857634dd77243af505bbeae Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Wed, 27 Mar 2024 11:18:02 +0000 Subject: [PATCH 6/9] fix lint warnings --- ui/selectors/selectors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index 5b17fcee14b8..56d94f358302 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -106,6 +106,7 @@ import { SURVEY_END_TIME, SURVEY_START_TIME, } from '../helpers/constants/survey'; +import { SUPPORTED_CHAIN_IDS } from '../../app/scripts/lib/ppom/ppom-middleware'; import { getCurrentNetworkTransactions, getUnapprovedTransactions, @@ -119,7 +120,6 @@ import { getOrderedConnectedAccountsForActiveTab, } from './permissions'; import { createDeepEqualSelector } from './util'; -import { SUPPORTED_CHAIN_IDS } from '../../app/scripts/lib/ppom/ppom-middleware'; /** * Returns true if the currently selected network is inaccessible or whether no From c30834390d94aa0fed1b6ab6ef0c59a75bd7dca7 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Wed, 27 Mar 2024 11:26:01 +0000 Subject: [PATCH 7/9] fix proptypes --- .../signature-request-original.component.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ui/pages/confirmations/components/signature-request-original/signature-request-original.component.js b/ui/pages/confirmations/components/signature-request-original/signature-request-original.component.js index 111a2ab8dad0..fcf24c05237f 100644 --- a/ui/pages/confirmations/components/signature-request-original/signature-request-original.component.js +++ b/ui/pages/confirmations/components/signature-request-original/signature-request-original.component.js @@ -87,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 From 8bd6b685fde9537d4b71532449b2f49251807436 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Wed, 27 Mar 2024 11:34:02 +0000 Subject: [PATCH 8/9] fix proptypes --- .../confirm-transaction-base.component.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js index 00d1cc716687..75e971aee6aa 100644 --- a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js +++ b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js @@ -65,9 +65,8 @@ import SnapAccountTransactionLoadingScreen from '../../snap-account-transaction- import { isHardwareKeyring } from '../../../helpers/utils/hardware'; import FeeDetailsComponent from '../components/fee-details-component/fee-details-component'; import { SimulationDetails } from '../components/simulation-details'; -import { BannerAlert, BannerBase } from '../../../components/component-library'; +import { BannerAlert } from '../../../components/component-library'; import { Severity } from '../../../helpers/constants/design-system'; -import { SUPPORTED_CHAIN_IDS } from '../../../../app/scripts/lib/ppom/ppom-middleware'; export default class ConfirmTransactionBase extends Component { static contextTypes = { @@ -171,6 +170,10 @@ export default class ConfirmTransactionBase extends Component { useMaxValue: PropTypes.bool, maxValue: PropTypes.string, isMultiLayerFeeNetwork: PropTypes.bool, + hasMigratedFromOpenSeaToBlockaid: PropTypes.bool, + hasDismissedOpenSeaToBlockaidBanner: PropTypes.bool, + dismissOpenSeaToBlockaidBanner: PropTypes.func, + isNetworkSupportedByBlockaid: PropTypes.bool, }; state = { @@ -185,7 +188,6 @@ export default class ConfirmTransactionBase extends Component { ///: BEGIN:ONLY_INCLUDE_IF(build-mmi) noteText: '', ///: END:ONLY_INCLUDE_IF - showBanner: true, }; componentDidUpdate(prevProps) { From 299652a588e6f91cef34098d8dc6e25b479d09f9 Mon Sep 17 00:00:00 2001 From: Pedro Figueiredo Date: Wed, 27 Mar 2024 12:36:44 +0000 Subject: [PATCH 9/9] fix snapshot tests --- app/scripts/lib/setupSentry.js | 1 + .../errors-after-init-opt-in-background-state.json | 1 + .../tests/state-snapshots/errors-after-init-opt-in-ui-state.json | 1 + 3 files changed, 3 insertions(+) diff --git a/app/scripts/lib/setupSentry.js b/app/scripts/lib/setupSentry.js index ad1e0b9f22a7..b03a15a45dd3 100644 --- a/app/scripts/lib/setupSentry.js +++ b/app/scripts/lib/setupSentry.js @@ -237,6 +237,7 @@ export const SENTRY_BACKGROUND_STATE = { useTokenDetection: true, useRequestQueue: true, useTransactionSimulations: true, + hasDismissedOpenSeaToBlockaidBanner: true, }, SelectedNetworkController: { domains: false }, SignatureController: { diff --git a/test/e2e/tests/state-snapshots/errors-after-init-opt-in-background-state.json b/test/e2e/tests/state-snapshots/errors-after-init-opt-in-background-state.json index 44aebd984800..85b35d794363 100644 --- a/test/e2e/tests/state-snapshots/errors-after-init-opt-in-background-state.json +++ b/test/e2e/tests/state-snapshots/errors-after-init-opt-in-background-state.json @@ -155,6 +155,7 @@ "addSnapAccountEnabled": "boolean", "advancedGasFee": {}, "featureFlags": {}, + "hasDismissedOpenSeaToBlockaidBanner": false, "incomingTransactionsPreferences": {}, "knownMethodData": "object", "currentLocale": "en", diff --git a/test/e2e/tests/state-snapshots/errors-after-init-opt-in-ui-state.json b/test/e2e/tests/state-snapshots/errors-after-init-opt-in-ui-state.json index 4ecc3f0c42f9..d0d28f8cae09 100644 --- a/test/e2e/tests/state-snapshots/errors-after-init-opt-in-ui-state.json +++ b/test/e2e/tests/state-snapshots/errors-after-init-opt-in-ui-state.json @@ -74,6 +74,7 @@ "showAccountBanner": true, "trezorModel": null, "hadAdvancedGasFeesSetPriorToMigration92_3": false, + "hasDismissedOpenSeaToBlockaidBanner": false, "nftsDropdownState": {}, "termsOfUseLastAgreed": "number", "qrHardware": {},