diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 5402d0d02..b0e3fb712 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -1264,18 +1264,6 @@ "message": "Swapping on mobile is here!", "description": "Title for a notification in the 'See What's New' popup. Tells users that they can now use MetaMask Swaps on Mobile." }, - "notifications2ActionText": { - "message": "Start survey", - "description": "The 'call to action' label on the button, or link, of the 'Help improve MetaMask' 'See What's New' notification. Upon clicking, users will be taken to an external page where they can complete a survey." - }, - "notifications2Description": { - "message": "Please share your experience in this 5 minute survey.", - "description": "Description of a notification in the 'See What's New' popup. Further clarifies how the users can help: by completing a 5 minute survey about MetaMask." - }, - "notifications2Title": { - "message": "Help improve MetaMask", - "description": "Title for a notification in the 'See What's New' popup. Asks users to take action to make MetaMask better." - }, "notifications3ActionText": { "message": "Read more", "description": "The 'call to action' on the button, or link, of the 'Stay secure' notification. Upon clicking, users will be taken to a page about security on the metamask support website." diff --git a/app/scripts/migrations/060.js b/app/scripts/migrations/060.js new file mode 100644 index 000000000..db985f6e5 --- /dev/null +++ b/app/scripts/migrations/060.js @@ -0,0 +1,35 @@ +import { cloneDeep, isPlainObject } from 'lodash'; + +const version = 60; +const SUPPORT_NOTIFICATION_KEY = 2; +const SUPPORT_NOTIFICATION_DATE = '2020-08-31'; + +/** + * Removes the support survey notification + */ +export default { + version, + async migrate(originalVersionedData) { + const versionedData = cloneDeep(originalVersionedData); + versionedData.meta.version = version; + const state = versionedData.data; + const newState = transformState(state); + versionedData.data = newState; + return versionedData; + }, +}; + +function transformState(state) { + const notifications = state?.NotificationController?.notifications; + if (isPlainObject(notifications)) { + if ( + notifications[SUPPORT_NOTIFICATION_KEY]?.date === + SUPPORT_NOTIFICATION_DATE + ) { + delete state.NotificationController.notifications[ + SUPPORT_NOTIFICATION_KEY + ]; + } + } + return state; +} diff --git a/app/scripts/migrations/060.test.js b/app/scripts/migrations/060.test.js new file mode 100644 index 000000000..c0116c9a7 --- /dev/null +++ b/app/scripts/migrations/060.test.js @@ -0,0 +1,143 @@ +import { strict as assert } from 'assert'; +import migration60 from './060'; + +describe('migration #60', function () { + it('should update the version metadata', async function () { + const oldStorage = { + meta: { + version: 59, + }, + data: {}, + }; + + const newStorage = await migration60.migrate(oldStorage); + assert.deepEqual(newStorage.meta, { + version: 60, + }); + }); + + it('prunes the support notification', async function () { + const oldStorage = { + meta: {}, + data: { + NotificationController: { + notifications: { + 1: { + id: 1, + date: '2021-03-17', + image: { + src: 'images/mobile-link-qr.svg', + height: '230px', + width: '230px', + placeImageBelowDescription: true, + }, + }, + 2: { + id: 2, + date: '2020-08-31', + }, + 3: { + id: 3, + date: '2021-03-08', + }, + 4: { + id: 4, + date: '2021-05-11', + image: { + src: 'images/source-logos-bsc.svg', + width: '100%', + }, + }, + }, + }, + }, + }; + + const newStorage = await migration60.migrate(oldStorage); + const { notifications } = newStorage.data.NotificationController; + const notificationKeys = Object.keys(notifications); + // Assert support notification is removed + assert.equal(notificationKeys.length, 3); + notificationKeys.forEach((key) => { + assert.notEqual(notifications[key].date, '2020-08-31'); + }); + }); + + it('does not modify state when the support notification does not exist', async function () { + const oldStorage = { + meta: {}, + data: { + NotificationController: { + notifications: { + 1: { + id: 1, + date: '2021-03-17', + image: { + src: 'images/mobile-link-qr.svg', + height: '230px', + width: '230px', + placeImageBelowDescription: true, + }, + }, + 3: { + id: 3, + date: '2021-03-08', + }, + 4: { + id: 4, + date: '2021-05-11', + image: { + src: 'images/source-logos-bsc.svg', + width: '100%', + }, + }, + }, + }, + }, + }; + + const newStorage = await migration60.migrate(oldStorage); + assert.deepEqual(oldStorage.data, newStorage.data); + }); + + it('does not modify state when NotificationsController is undefined', async function () { + const oldStorage = { + meta: {}, + data: { + arbitraryPropOne: 1, + arbitraryPropTwo: 2, + }, + }; + + const newStorage = await migration60.migrate(oldStorage); + assert.deepEqual(oldStorage.data, newStorage.data); + }); + + it('does not modify state when notifications are undefined', async function () { + const oldStorage = { + meta: {}, + data: { + NotificationController: { + arbitraryControllerProp: 'foo', + }, + }, + }; + + const newStorage = await migration60.migrate(oldStorage); + assert.deepEqual(oldStorage.data, newStorage.data); + }); + + it('does not modify state when notifications are not an object', async function () { + const oldStorage = { + meta: {}, + data: { + NotificationController: { + notifications: [], + }, + }, + }; + + const newStorage = await migration60.migrate(oldStorage); + assert.deepEqual(oldStorage.data, newStorage.data); + }); +}); diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js index 47925fbba..682ba6d08 100644 --- a/app/scripts/migrations/index.js +++ b/app/scripts/migrations/index.js @@ -64,6 +64,7 @@ const migrations = [ require('./057').default, require('./058').default, require('./059').default, + require('./060').default, ]; export default migrations; diff --git a/shared/notifications/index.js b/shared/notifications/index.js index 3eb433420..ad2387f99 100644 --- a/shared/notifications/index.js +++ b/shared/notifications/index.js @@ -10,10 +10,6 @@ export const UI_NOTIFICATIONS = { placeImageBelowDescription: true, }, }, - 2: { - id: 2, - date: '2020-08-31', - }, 3: { id: 3, date: '2021-03-08', @@ -43,15 +39,6 @@ export const getTranslatedUINoficiations = (t, locale) => { new Date(UI_NOTIFICATIONS[1].date), ), }, - 2: { - ...UI_NOTIFICATIONS[2], - title: t('notifications2Title'), - description: t('notifications2Description'), - actionText: t('notifications2ActionText'), - date: new Intl.DateTimeFormat(formattedLocale).format( - new Date(UI_NOTIFICATIONS[2].date), - ), - }, 3: { ...UI_NOTIFICATIONS[3], title: t('notifications3Title'),