-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix favorites tokens with no icon (#5982)
* fix favorites default list * wip * π * Update src/resources/favorites.ts * fix format --------- Co-authored-by: Matthew Wall <[email protected]>
- Loading branch information
1 parent
eabc40e
commit c1f0d5f
Showing
6 changed files
with
83 additions
and
113 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
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
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,54 @@ | ||
import { AddressOrEth, UniqueId } from '@/__swaps__/types/assets'; | ||
import { getStandardizedUniqueIdWorklet } from '@/__swaps__/utils/swaps'; | ||
import { EthereumAddress, RainbowToken } from '@/entities'; | ||
import { createQueryKey, persistOptions, queryClient } from '@/react-query'; | ||
import { favoritesQueryKey } from '@/resources/favorites'; | ||
import { ethereumUtils } from '@/utils'; | ||
import { persistQueryClientRestore, persistQueryClientSave } from '@tanstack/react-query-persist-client'; | ||
import { Migration, MigrationName } from '../types'; | ||
|
||
const favoritesV1QueryKey = createQueryKey('favorites', {}, { persisterVersion: 1 }); | ||
const favoritesV2QueryKey = createQueryKey('favorites', {}, { persisterVersion: 2 }); | ||
|
||
export function migrateFavoritesV2(): Migration { | ||
return { | ||
name: MigrationName.migrateFavoritesV2, | ||
async migrate() { | ||
await persistQueryClientRestore({ queryClient, persister: persistOptions.persister }); // first restore persisted data | ||
|
||
// v1 used just the address as key, v2 uses uniqueId as key and builds this uniqueId with ChainId instead of Network | ||
const v1Data = queryClient.getQueryData<Record<EthereumAddress, RainbowToken>>(favoritesV1QueryKey); | ||
|
||
if (!v1Data) return; | ||
|
||
const migratedFavorites: Record<UniqueId, RainbowToken> = {}; | ||
for (const favorite of Object.values(v1Data)) { | ||
const uniqueId = getStandardizedUniqueIdWorklet({ | ||
address: favorite.address as AddressOrEth, | ||
chainId: ethereumUtils.getChainIdFromNetwork(favorite.network), | ||
}); | ||
favorite.uniqueId = uniqueId; // v2 unique uses chainId instead of Network | ||
migratedFavorites[uniqueId] = favorite; | ||
} | ||
queryClient.setQueryData(favoritesQueryKey, migratedFavorites); | ||
|
||
await persistQueryClientSave({ queryClient, persister: persistOptions.persister }); | ||
}, | ||
}; | ||
} | ||
|
||
export function migrateFavoritesV3(): Migration { | ||
return { | ||
name: MigrationName.migrateFavoritesV3, | ||
async migrate() { | ||
await persistQueryClientRestore({ queryClient, persister: persistOptions.persister }); // first restore persisted data | ||
|
||
const v2Data = queryClient.getQueryData<Record<UniqueId, RainbowToken>>(favoritesV2QueryKey); | ||
if (!v2Data) return; | ||
|
||
queryClient.setQueryData(favoritesQueryKey, v2Data, { updatedAt: 0 }); | ||
|
||
await persistQueryClientSave({ queryClient, persister: persistOptions.persister }); | ||
}, | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
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
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