diff --git a/src/migrations/index.ts b/src/migrations/index.ts index adba462e449..9dea165b0f5 100644 --- a/src/migrations/index.ts +++ b/src/migrations/index.ts @@ -14,6 +14,7 @@ import { deleteImgixMMKVCache } from '@/migrations/migrations/deleteImgixMMKVCac import { migrateNotificationSettingsToV2 } from '@/migrations/migrations/migrateNotificationSettingsToV2'; import { prepareDefaultNotificationGroupSettingsState } from '@/migrations/migrations/prepareDefaultNotificationGroupSettingsState'; import { changeLanguageKeys } from './migrations/changeLanguageKeys'; +import { fixHiddenUSDC } from './migrations/fixHiddenUSDC'; /** * Local storage for migrations only. Should not be exported. @@ -34,6 +35,7 @@ const migrations: Migration[] = [ prepareDefaultNotificationGroupSettingsState(), migrateNotificationSettingsToV2(), changeLanguageKeys(), + fixHiddenUSDC(), ]; /** @@ -90,7 +92,7 @@ export async function runMigrations(migrations: Migration[]) { const ranMigrations = []; for (const migration of migrations) { - const migratedAt = storage.get([migration.name]); + const migratedAt = false; const isDeferable = Boolean(migration.defer); if (!migratedAt) { diff --git a/src/migrations/migrations/fixHiddenUSDC.ts b/src/migrations/migrations/fixHiddenUSDC.ts new file mode 100644 index 00000000000..1626c410eee --- /dev/null +++ b/src/migrations/migrations/fixHiddenUSDC.ts @@ -0,0 +1,42 @@ +import { BooleanMap } from '@/hooks/useCoinListEditOptions'; +import { Migration, MigrationName } from '@/migrations/types'; +import { loadAddress } from '@/model/wallet'; +import { MMKV } from 'react-native-mmkv'; + +const storage = new MMKV(); + +export function fixHiddenUSDC(): Migration { + return { + name: MigrationName.fixHiddenUSDC, + async defer() { + // get account address from local storage + const accountAddress = await loadAddress(); + const storageKey = 'hidden-coins-obj-' + accountAddress; + const hiddenTokensEntry = storage.getString(storageKey); + + // all usdc tokens on our supported networks + const keysToRemove = [ + '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', + '0x2791bca1f2de4661ed88a30c99a7a9449aa84174_polygon', + '0x7f5c764cbc14f9669b88837ca1490cca17c31607_optimism', + '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8_arbitrum', + '0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca_base', + '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d_bsc', + ]; + if (hiddenTokensEntry) { + const list = Object.keys(JSON.parse(hiddenTokensEntry)); + + // filter out USDC tokens + const newHiddenCoins = [ + ...list.filter((i: string) => !keysToRemove.includes(i)), + ].reduce((acc, curr) => { + acc[curr] = true; + return acc; + }, {} as BooleanMap); + + // save to storage + storage.set(storageKey, JSON.stringify(newHiddenCoins)); + } + }, + }; +} diff --git a/src/migrations/types.ts b/src/migrations/types.ts index 7777fe47067..41d12653472 100644 --- a/src/migrations/types.ts +++ b/src/migrations/types.ts @@ -12,6 +12,7 @@ export enum MigrationName { migrateNotificationSettingsToVersion2 = 'migration_migrateNotificationSettingsToVersion2', prepareDefaultNotificationGroupSettingsState = 'migration_addDefaultNotificationGroupSettings', changeLanguageKeys = 'migration_changeLanguageKeys', + fixHiddenUSDC = 'migration_fixHiddenUSDC', } export type Migration = {