-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate pinned + hidden tokens
- Loading branch information
1 parent
1f08e05
commit df2c45b
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/migrations/migrations/migratePinnedAndHiddenTokenUniqueIds.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters