Skip to content

Commit

Permalink
Create migration to reset initially subscribed state for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchung committed Dec 5, 2023
1 parent 44fc143 commit 020c96c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@/migrations/types';
import { deleteImgixMMKVCache } from '@/migrations/migrations/deleteImgixMMKVCache';
import { migrateNotificationSettingsToV2 } from '@/migrations/migrations/migrateNotificationSettingsToV2';
import { migrateNotificationSettingsToV3 } from '@/migrations/migrations/migrateNotificationSettingsToV3';
import { prepareDefaultNotificationGroupSettingsState } from '@/migrations/migrations/prepareDefaultNotificationGroupSettingsState';
import { changeLanguageKeys } from './migrations/changeLanguageKeys';
import { fixHiddenUSDC } from './migrations/fixHiddenUSDC';
Expand All @@ -36,6 +37,7 @@ const migrations: Migration[] = [
migrateNotificationSettingsToV2(),
changeLanguageKeys(),
fixHiddenUSDC(),
migrateNotificationSettingsToV3(),
];

/**
Expand Down
24 changes: 24 additions & 0 deletions src/migrations/migrations/migrateNotificationSettingsToV3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Migration, MigrationName } from '@/migrations/types';
import {
getAllNotificationSettingsFromStorage,
setAllNotificationSettingsToStorage,
} from '@/notifications/settings/storage';

export function migrateNotificationSettingsToV3(): Migration {
return {
name: MigrationName.migrateNotificationSettingsToVersion3,
async migrate() {
const walletSettings = getAllNotificationSettingsFromStorage();

// reset successfullyFinishedInitialSubscription
if (walletSettings.length) {
const newSettings = walletSettings.map(wallet => ({
...wallet,
successfullyFinishedInitialSubscription: false,
}));
setAllNotificationSettingsToStorage(newSettings);
}
return;
},
};
}
1 change: 1 addition & 0 deletions src/migrations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum MigrationName {
prepareDefaultNotificationGroupSettingsState = 'migration_addDefaultNotificationGroupSettings',
changeLanguageKeys = 'migration_changeLanguageKeys',
fixHiddenUSDC = 'migration_fixHiddenUSDC',
migrateNotificationSettingsToVersion3 = 'migration_migrateNotificationSettingsToVersion3',
}

export type Migration = {
Expand Down

0 comments on commit 020c96c

Please sign in to comment.