Skip to content

Commit

Permalink
Merge branch 'brian/network-controller-v20-merging-in-v21' of github.…
Browse files Browse the repository at this point in the history
…com:MetaMask/metamask-extension into brian/network-controller-v20-merging-in-v21
  • Loading branch information
bergeron committed Aug 27, 2024
2 parents 7b28e0c + aa585ab commit fc75a82
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 10 deletions.
55 changes: 55 additions & 0 deletions app/scripts/migrations/129.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
44 changes: 44 additions & 0 deletions app/scripts/migrations/129.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { cloneDeep } from 'lodash';

type VersionedData = {
meta: { version: number };
data: Record<string, unknown>;
};

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<VersionedData> {
const versionedData = cloneDeep(originalVersionedData);
versionedData.meta.version = version;
transformState(versionedData.data);
return versionedData;
}

function transformState(state: Record<string, unknown>): void {
const preferencesControllerState = state?.PreferencesController as
| Record<string, unknown>
| undefined;

const preferences = preferencesControllerState?.preferences as
| Record<string, unknown>
| undefined;

if (preferences) {
// Existing MetaMask users will have the option null by default
preferences.showMultiRpcModal = null;
}
}
2 changes: 1 addition & 1 deletion app/scripts/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ const migrations = [
require('./124'),
require('./125'),
require('./126'),
require('./127'),
require('./128'),
require('./129'),
];

export default migrations;
1 change: 0 additions & 1 deletion shared/modules/selectors/multi-rpc-edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ type MultiRpcEditMetaMaskState = {
metamask: {
preferences: {
showMultiRpcModal: boolean | null;
showMultiRpcModalUpgrade: boolean | null;
};
};
};
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/default-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function defaultFixture(inputChainId = CHAIN_IDS.LOCALHOST) {
smartTransactionsOptInStatus: false,
useNativeCurrencyAsPrimaryCurrency: true,
petnamesEnabled: true,
showMultiRpcModal: false,
showMultiRpcModal: true,
isRedesignedConfirmationsDeveloperEnabled: false,
showConfirmationAdvancedDetails: false,
},
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/fixture-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function onboardingFixture() {
smartTransactionsOptInStatus: false,
useNativeCurrencyAsPrimaryCurrency: true,
petnamesEnabled: true,
showMultiRpcModal: false,
showMultiRpcModal: true,
isRedesignedConfirmationsDeveloperEnabled: false,
showConfirmationAdvancedDetails: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"currentAppVersion": "string",
"previousAppVersion": "",
"previousMigrationVersion": 0,
"currentMigrationVersion": "number",
"showMultiRpcModalUpgrade": "object"
"currentMigrationVersion": "number"
},
"AppStateController": {
"connectedStatusPopoverHasBeenShown": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
"previousAppVersion": "",
"previousMigrationVersion": 0,
"currentMigrationVersion": "number",
"showMultiRpcModalUpgrade": "object",
"balances": "object",
"selectedNetworkClientId": "string",
"networksMetadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,7 +42,7 @@ function MultiRpcEditModal({ isOpen, onClose }: MultiRpcEditModalProps) {
return (
<Modal
isOpen={isOpen}
onClose={() => onClose(true)}
onClose={() => dispatch(setShowMultiRpcModal(true))}
isClosedOnOutsideClick={false}
isClosedOnEscapeKey={false}
className="mm-modal__custom-scrollbar auto-detect-in-modal"
Expand Down
11 changes: 11 additions & 0 deletions ui/pages/home/home.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -934,6 +936,7 @@ export default class Home extends PureComponent {
firstTimeFlowType,
newNetworkAddedConfigurationId,
isSmartTransactionsOptInModalAvailable,
showMultiRpcModal,
///: END:ONLY_INCLUDE_IF
} = this.props;

Expand All @@ -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
Expand All @@ -985,6 +994,8 @@ export default class Home extends PureComponent {
hideWhatsNewPopup={hideWhatsNewPopup}
/>

<MultiRpcEditModal isOpen={showMultiRpcEditModal} />

{showWhatsNew ? <WhatsNewPopup onClose={hideWhatsNewPopup} /> : null}
{!showWhatsNew && showRecoveryPhraseReminder ? (
<RecoveryPhraseReminder
Expand Down

0 comments on commit fc75a82

Please sign in to comment.