Skip to content

Commit

Permalink
chore: migrate pinned + hidden tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
skylarbarrera authored and ibrahimtaveras00 committed Feb 15, 2024
1 parent 1f08e05 commit df2c45b
Show file tree
Hide file tree
Showing 3 changed files with 46 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 @@ -11,6 +11,7 @@ import { prepareDefaultNotificationGroupSettingsState } from '@/migrations/migra
import { changeLanguageKeys } from './migrations/changeLanguageKeys';
import { fixHiddenUSDC } from './migrations/fixHiddenUSDC';
import { purgeWcConnectionsWithoutAccounts } from './migrations/purgeWcConnectionsWithoutAccounts';
import { migratePinnedAndHiddenTokenUniqueIds } from './migrations/migratePinnedAndHiddenTokenUniqueIds';

/**
* Local storage for migrations only. Should not be exported.
Expand All @@ -33,6 +34,7 @@ const migrations: Migration[] = [
changeLanguageKeys(),
fixHiddenUSDC(),
purgeWcConnectionsWithoutAccounts(),
migratePinnedAndHiddenTokenUniqueIds(),
];

/**
Expand Down
43 changes: 43 additions & 0 deletions src/migrations/migrations/migratePinnedAndHiddenTokenUniqueIds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { BooleanMap } from '@/hooks/useCoinListEditOptions';
import { Migration, MigrationName } from '@/migrations/types';
import { loadAddress } from '@/model/wallet';
import { Network } from '@/networks/types';
import { getUniqueId } from '@/utils/ethereumUtils';
import { MMKV } from 'react-native-mmkv';

const mmkv = new MMKV();

export function migratePinnedAndHiddenTokenUniqueIds(): Migration {
return {
name: MigrationName.migratePinnedAndHiddenTokenUniqueIds,
async defer() {
const address = await loadAddress();
const hiddenCoinsKey = 'hidden-coins-obj-' + address;
const pinnedCoinsKey = 'pinned-coins-obj-' + address;
const hiddenCoinsString = mmkv.getString(hiddenCoinsKey);
const pinnedCoinsString = mmkv.getString(pinnedCoinsKey);
const hiddenCoinsKeys = Object.keys(hiddenCoinsString ? JSON.parse(hiddenCoinsString) : {});
const pinnedCoinsKeys = Object.keys(pinnedCoinsString ? JSON.parse(pinnedCoinsString) : {});
const newHiddenCoins = hiddenCoinsKeys.reduce((acc, curr) => {
if (!curr.includes('_')) {
acc[getUniqueId(curr, Network.mainnet)] = true;
return acc;
}
acc[curr] = true;
return acc;
}, {} as BooleanMap);

const newPinnedCoins = pinnedCoinsKeys.reduce((acc, curr) => {
if (!curr.includes('_')) {
acc[getUniqueId(curr, Network.mainnet)] = true;
return acc;
}
acc[curr] = true;
return acc;
}, {} as BooleanMap);

mmkv.set('hidden-coins-obj-' + address, JSON.stringify(newHiddenCoins));
mmkv.set('pinned-coins-obj-' + address, JSON.stringify(newPinnedCoins));
},
};
}
1 change: 1 addition & 0 deletions src/migrations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum MigrationName {
changeLanguageKeys = 'migration_changeLanguageKeys',
fixHiddenUSDC = 'migration_fixHiddenUSDC',
purgeWcConnectionsWithoutAccounts = 'migration_purgeWcConnectionsWithoutAccounts',
migratePinnedAndHiddenTokenUniqueIds = 'migration_migratePinnedAndHiddenTokenUniqueIds',
}

export type Migration = {
Expand Down

0 comments on commit df2c45b

Please sign in to comment.