Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate pinned + hidden tokens #5410

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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