From 3d14996a2b47a352e2d965df04b05bc8073e0652 Mon Sep 17 00:00:00 2001 From: salimtb Date: Mon, 26 Aug 2024 18:21:22 +0200 Subject: [PATCH 1/3] feat: call multiRpc migration modal --- shared/modules/selectors/multi-rpc-edit.ts | 1 - test/e2e/default-fixture.js | 2 +- test/e2e/fixture-builder.js | 2 +- .../errors-after-init-opt-in-background-state.json | 3 +-- .../errors-after-init-opt-in-ui-state.json | 1 - .../app/multi-rpc-edit-modal/multi-rpc-edit-modal.tsx | 5 ++--- ui/pages/home/home.component.js | 11 +++++++++++ 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/shared/modules/selectors/multi-rpc-edit.ts b/shared/modules/selectors/multi-rpc-edit.ts index 09ff665254ba..c612aff2d92f 100644 --- a/shared/modules/selectors/multi-rpc-edit.ts +++ b/shared/modules/selectors/multi-rpc-edit.ts @@ -2,7 +2,6 @@ type MultiRpcEditMetaMaskState = { metamask: { preferences: { showMultiRpcModal: boolean | null; - showMultiRpcModalUpgrade: boolean | null; }; }; }; diff --git a/test/e2e/default-fixture.js b/test/e2e/default-fixture.js index 2585045505af..4b95a8b360a5 100644 --- a/test/e2e/default-fixture.js +++ b/test/e2e/default-fixture.js @@ -203,7 +203,7 @@ function defaultFixture(inputChainId = CHAIN_IDS.LOCALHOST) { smartTransactionsOptInStatus: false, useNativeCurrencyAsPrimaryCurrency: true, petnamesEnabled: true, - showMultiRpcModal: false, + showMultiRpcModal: true, isRedesignedConfirmationsDeveloperEnabled: false, showConfirmationAdvancedDetails: false, }, diff --git a/test/e2e/fixture-builder.js b/test/e2e/fixture-builder.js index dfdb1ab728b9..c47999d751e2 100644 --- a/test/e2e/fixture-builder.js +++ b/test/e2e/fixture-builder.js @@ -70,7 +70,7 @@ function onboardingFixture() { smartTransactionsOptInStatus: false, useNativeCurrencyAsPrimaryCurrency: true, petnamesEnabled: true, - showMultiRpcModal: false, + showMultiRpcModal: true, isRedesignedConfirmationsDeveloperEnabled: false, showConfirmationAdvancedDetails: false, }, diff --git a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json index a0ec2809ed52..0b405966c6a3 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json @@ -18,8 +18,7 @@ "currentAppVersion": "string", "previousAppVersion": "", "previousMigrationVersion": 0, - "currentMigrationVersion": "number", - "showMultiRpcModalUpgrade": "object" + "currentMigrationVersion": "number" }, "AppStateController": { "connectedStatusPopoverHasBeenShown": true, diff --git a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json index 5b3aeaf94961..63cd13203cbc 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json @@ -86,7 +86,6 @@ "previousAppVersion": "", "previousMigrationVersion": 0, "currentMigrationVersion": "number", - "showMultiRpcModalUpgrade": "object", "balances": "object", "selectedNetworkClientId": "string", "networksMetadata": { diff --git a/ui/components/app/multi-rpc-edit-modal/multi-rpc-edit-modal.tsx b/ui/components/app/multi-rpc-edit-modal/multi-rpc-edit-modal.tsx index 59a08d8d6069..ea99c2d422af 100644 --- a/ui/components/app/multi-rpc-edit-modal/multi-rpc-edit-modal.tsx +++ b/ui/components/app/multi-rpc-edit-modal/multi-rpc-edit-modal.tsx @@ -28,10 +28,9 @@ import NetworkListItem from './network-list-item/network-list-item'; type MultiRpcEditModalProps = { isOpen: boolean; - onClose: (arg: boolean) => void; }; -function MultiRpcEditModal({ isOpen, onClose }: MultiRpcEditModalProps) { +function MultiRpcEditModal({ isOpen }: MultiRpcEditModalProps) { const t = useI18nContext(); const dispatch = useDispatch(); const isPopUp = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP; @@ -43,7 +42,7 @@ function MultiRpcEditModal({ isOpen, onClose }: MultiRpcEditModalProps) { return ( onClose(true)} + onClose={() => dispatch(setShowMultiRpcModal(true))} isClosedOnOutsideClick={false} isClosedOnEscapeKey={false} className="mm-modal__custom-scrollbar auto-detect-in-modal" diff --git a/ui/pages/home/home.component.js b/ui/pages/home/home.component.js index 410068aa5a97..ee4f638701c3 100644 --- a/ui/pages/home/home.component.js +++ b/ui/pages/home/home.component.js @@ -50,6 +50,7 @@ import { ModalHeader, ModalOverlay, } from '../../components/component-library'; +import MultiRpcEditModal from '../../components/app/multi-rpc-edit-modal/multi-rpc-edit-modal'; import { RESTORE_VAULT_ROUTE, CONFIRM_TRANSACTION_ROUTE, @@ -154,6 +155,7 @@ export default class Home extends PureComponent { announcementsToShow: PropTypes.bool.isRequired, onboardedInThisUISession: PropTypes.bool, isSmartTransactionsOptInModalAvailable: PropTypes.bool.isRequired, + showMultiRpcModal: PropTypes.bool.isRequired, ///: END:ONLY_INCLUDE_IF newNetworkAddedConfigurationId: PropTypes.string, isNotification: PropTypes.bool.isRequired, @@ -934,6 +936,7 @@ export default class Home extends PureComponent { firstTimeFlowType, newNetworkAddedConfigurationId, isSmartTransactionsOptInModalAvailable, + showMultiRpcModal, ///: END:ONLY_INCLUDE_IF } = this.props; @@ -960,6 +963,12 @@ export default class Home extends PureComponent { showWhatsNewPopup && !showSmartTransactionsOptInModal; + const showMultiRpcEditModal = + canSeeModals && + showMultiRpcModal && + !showSmartTransactionsOptInModal && + !showWhatsNew; + const showTermsOfUse = completedOnboarding && !onboardedInThisUISession && showTermsOfUsePopup; ///: END:ONLY_INCLUDE_IF @@ -985,6 +994,8 @@ export default class Home extends PureComponent { hideWhatsNewPopup={hideWhatsNewPopup} /> + + {showWhatsNew ? : null} {!showWhatsNew && showRecoveryPhraseReminder ? ( Date: Mon, 26 Aug 2024 21:56:15 +0200 Subject: [PATCH 2/3] fix: fix migration modal script --- app/scripts/migrations/129.test.ts | 55 ++++++++++++++++++++++++++++++ app/scripts/migrations/129.ts | 44 ++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 app/scripts/migrations/129.test.ts create mode 100644 app/scripts/migrations/129.ts diff --git a/app/scripts/migrations/129.test.ts b/app/scripts/migrations/129.test.ts new file mode 100644 index 000000000000..991e97b45b9b --- /dev/null +++ b/app/scripts/migrations/129.test.ts @@ -0,0 +1,55 @@ +import { migrate, version } from './124'; + +const oldVersion = 128; + +describe('migration #129', () => { + it('updates the version metadata', async () => { + const oldStorage = { + meta: { version: oldVersion }, + data: {}, + }; + + const newStorage = await migrate(oldStorage); + + expect(newStorage.meta).toStrictEqual({ version }); + }); + + it('does nothing if no preferences controller state is set', async () => { + const oldState = { + OtherController: {}, + }; + + const transformedState = await migrate({ + meta: { version: oldVersion }, + data: oldState, + }); + + expect(transformedState.data).toEqual(oldState); + }); + + it('adds property if migration runs', async () => { + const oldState = { + PreferencesController: { + preferences: { + showMultiRpcModal: true, + }, + }, + }; + + const expectedState = { + PreferencesController: { + preferences: { + redesignedTransactionsEnabled: false, + showMultiRpcModal: true, + }, + }, + }; + + const transformedState = await migrate({ + meta: { version: oldVersion }, + data: oldState, + }); + + expect(transformedState.data).toEqual(expectedState); + }); +}); diff --git a/app/scripts/migrations/129.ts b/app/scripts/migrations/129.ts new file mode 100644 index 000000000000..3a4aa3a3f490 --- /dev/null +++ b/app/scripts/migrations/129.ts @@ -0,0 +1,44 @@ +import { cloneDeep } from 'lodash'; + +type VersionedData = { + meta: { version: number }; + data: Record; +}; + +export const version = 129; + +/** + * This migration sets the preference `redesignedTransactionsEnabled` if the + * user has existing data. + * + * @param originalVersionedData - Versioned MetaMask extension state, exactly + * what we persist to dist. + * @param originalVersionedData.meta - State metadata. + * @param originalVersionedData.meta.version - The current state version. + * @param originalVersionedData.data - The persisted MetaMask state, keyed by + * controller. + * @returns Updated versioned MetaMask extension state. + */ +export async function migrate( + originalVersionedData: VersionedData, +): Promise { + const versionedData = cloneDeep(originalVersionedData); + versionedData.meta.version = version; + transformState(versionedData.data); + return versionedData; +} + +function transformState(state: Record): void { + const preferencesControllerState = state?.PreferencesController as + | Record + | undefined; + + const preferences = preferencesControllerState?.preferences as + | Record + | undefined; + + if (preferences) { + // Existing MetaMask users will have the option null by default + preferences.showMultiRpcModal = null; + } +} From aa585ab494e4304530168decadef858869000b9d Mon Sep 17 00:00:00 2001 From: salimtb Date: Mon, 26 Aug 2024 22:07:08 +0200 Subject: [PATCH 3/3] fix: execute migrations --- app/scripts/migrations/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js index f3ee81dcdcd8..49d80d2eb2ca 100644 --- a/app/scripts/migrations/index.js +++ b/app/scripts/migrations/index.js @@ -143,8 +143,8 @@ const migrations = [ require('./124'), require('./125'), require('./126'), - require('./127'), require('./128'), + require('./129'), ]; export default migrations;