Skip to content

Commit

Permalink
migration: fix hidden usdc
Browse files Browse the repository at this point in the history
  • Loading branch information
skylarbarrera authored and ibrahimtaveras00 committed Oct 18, 2023
1 parent 5eb23cf commit 3e65720
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -34,6 +35,7 @@ const migrations: Migration[] = [
prepareDefaultNotificationGroupSettingsState(),
migrateNotificationSettingsToV2(),
changeLanguageKeys(),
fixHiddenUSDC(),
];

/**
Expand Down Expand Up @@ -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) {
Expand Down
42 changes: 42 additions & 0 deletions src/migrations/migrations/fixHiddenUSDC.ts
Original file line number Diff line number Diff line change
@@ -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));
}
},
};
}
1 change: 1 addition & 0 deletions src/migrations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum MigrationName {
migrateNotificationSettingsToVersion2 = 'migration_migrateNotificationSettingsToVersion2',
prepareDefaultNotificationGroupSettingsState = 'migration_addDefaultNotificationGroupSettings',
changeLanguageKeys = 'migration_changeLanguageKeys',
fixHiddenUSDC = 'migration_fixHiddenUSDC',
}

export type Migration = {
Expand Down

0 comments on commit 3e65720

Please sign in to comment.