-
Notifications
You must be signed in to change notification settings - Fork 101
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
feat(tokens): migrate user added data from legacy state #3267
Merged
Merged
Changes from all commits
Commits
Show all changes
125 commits
Select commit
Hold shift + click to select a range
5fe0f55
refactor(tokens): clean up token consts and use TokenWithLogo
shoom3301 cb6a735
feat(tokens): tokens list, search and management ui
shoom3301 46df189
feat(tokens): wire up new tokens lib into app
shoom3301 9f5cf03
fix(tokens): fix e2e tests for tokens updates
shoom3301 649cfb3
refactor(tokens): remove legacy code
shoom3301 f6b11ce
chore: update npm deps
shoom3301 51f9d35
Merge branch 'refactor/token-search-ui' of https://github.com/cowprot…
shoom3301 c7992aa
Merge branch 'refactor/tokens-lib-wiring' of https://github.com/cowpr…
shoom3301 168fe41
Merge branch 'refactor/tokens-e2e-fix' of https://github.com/cowproto…
shoom3301 3ebba78
chore: revert changes
shoom3301 93bd06d
chore: revert changes
shoom3301 df4a619
chore: revert changes
shoom3301 06e0546
chore: revert changes
shoom3301 7c9bd67
chore: revert changes
shoom3301 bfae888
Merge branch 'refactor/tokens-lib-wiring-2' of https://github.com/cow…
shoom3301 6a838f7
chore: revert changes
shoom3301 7d9f403
chore: revert changes
shoom3301 ddd3518
chore: revert changes
shoom3301 9b0c394
Merge branch 'refactor/tokens-lib-wiring-5' of https://github.com/cow…
shoom3301 63b42de
Merge branch 'refactor/tokens-e2e-fix' of https://github.com/cowproto…
shoom3301 bdf5b73
Merge branch 'refactor/tokens-remove-legacy' of https://github.com/co…
shoom3301 840af3f
fix: fix tokens list loading state
shoom3301 d1f8851
fix: fix token store updating inconsistency
shoom3301 70b87f9
chore: move DEFAULT_FAVOURITE_TOKENS to separate file
shoom3301 58b890f
refactor: refactor useSearchToken() hook
shoom3301 614feea
chore: fix tokens lib exports
shoom3301 b5c1508
chore: refactor TokensListsUpdater
shoom3301 c3cc4a8
fix: remove duplicates from token search results
shoom3301 e1626e7
fix(tokens): fix lists toggling
shoom3301 16ef0a0
fix(tokens): fix list importing
shoom3301 2a8d3d7
refactor(tokens): refactor tokens state
shoom3301 7083d15
Merge branch 'refactor/tokens-lib' of https://github.com/cowprotocol/…
shoom3301 c5a84b8
Merge branch 'refactor/tokens-consts' of https://github.com/cowprotoc…
shoom3301 ea11de1
refactor: refactor tokens UI
shoom3301 a2772af
Merge branch 'refactor/token-search-ui' of https://github.com/cowprot…
shoom3301 a6f810f
Merge branch 'refactor/tokens-lib-wiring-1' of https://github.com/cow…
shoom3301 863e141
Merge branch 'refactor/tokens-lib-wiring-2' of https://github.com/cow…
shoom3301 e82060c
Merge branch 'refactor/tokens-lib-wiring-3' of https://github.com/cow…
shoom3301 38feb47
Merge branch 'refactor/tokens-lib-wiring-4' of https://github.com/cow…
shoom3301 998ab1f
Merge branch 'refactor/tokens-lib-wiring-5' of https://github.com/cow…
shoom3301 9402853
Merge branch 'refactor/tokens-e2e-fix' of https://github.com/cowproto…
shoom3301 d8e4330
Merge branch 'refactor/tokens-remove-legacy' of https://github.com/co…
shoom3301 7287a63
feat(tokens): lists analytics events
shoom3301 e7573de
refactor: group and rename entities
shoom3301 e6be7d3
chore: fix imports
shoom3301 c684d98
chore: fix cosmos fixtures
shoom3301 822d170
chore: remove unused code
shoom3301 0c184d9
Merge branch 'refactor/tokens-lib' of https://github.com/cowprotocol/…
shoom3301 2f23d0a
Merge branch 'refactor/tokens-consts' of https://github.com/cowprotoc…
shoom3301 0f6929d
refactor: refactor tokens UI structure
shoom3301 4b267a9
Merge branch 'refactor/token-search-ui' of https://github.com/cowprot…
shoom3301 3e3479f
Merge branch 'refactor/tokens-lib-wiring-1' of https://github.com/cow…
shoom3301 72c04de
Merge branch 'refactor/tokens-lib-wiring-2' of https://github.com/cow…
shoom3301 a79006e
Merge branch 'refactor/tokens-lib-wiring-3' of https://github.com/cow…
shoom3301 cfe1c48
Merge branch 'refactor/tokens-lib-wiring-4' of https://github.com/cow…
shoom3301 7aae2d9
Merge branch 'refactor/tokens-lib-wiring-5' of https://github.com/cow…
shoom3301 5399b89
Merge branch 'refactor/tokens-e2e-fix' of https://github.com/cowproto…
shoom3301 9701d07
Merge branch 'refactor/tokens-remove-legacy' of https://github.com/co…
shoom3301 2592593
chore: fix import
shoom3301 db8105f
chore: fix typo
shoom3301 4a28d8c
chore: trim input value
shoom3301 caeeeb7
chore: fix list removing
shoom3301 c1ac055
chore: diagrams
shoom3301 6837b14
refactor: simplify unsupported token hooks
shoom3301 cc53a88
refactor: simplify useSearchToken
shoom3301 3127c0e
refactor: rename isTokenAlreadyFoundByAddress
shoom3301 7370a0b
refactor: use lastUpdateTimeAtom instead of localStorage
shoom3301 4ab7dbd
chore: remove TOKENS_LISTS_UPDATER_INTERVAL duplicate
shoom3301 7400345
refactor: use TokenWithLogo.fromToken
shoom3301 9fc64a1
fix: fix FavouriteTokensList mobile view
shoom3301 437ca57
fix: fix mobile appearance
shoom3301 e02d368
fix: select token after import
shoom3301 45feae5
fix: search token by symbol for autoimporting
shoom3301 5552b69
feat: add trust as a fallback to logo urls
shoom3301 734c5f4
refactor: simplify TokenSearchResponse
shoom3301 20af0e7
chore: docs for complex entities
shoom3301 c11ac54
chore: cache inputLowerCase
shoom3301 e1bae58
chore: rename tokenMapToListWithLogo
shoom3301 cbeaa9b
chore: remove unused files
shoom3301 010dcb2
feat: reset unsupported tokens periodically
shoom3301 f07e036
chore: remove excessive files
shoom3301 34e06de
fix: use token with logo in orders state
shoom3301 9aec764
chore: remove excessive files
shoom3301 5537c79
Merge branch 'refactor/tokens-e2e-fix' of https://github.com/cowproto…
shoom3301 00a9f85
Merge branch 'refactor/tokens-remove-legacy' of https://github.com/co…
shoom3301 bf7490c
Merge branch 'refactor/tokens-remove-legacy' of https://github.com/co…
shoom3301 b12a429
refactor: simplify token lists state
shoom3301 2243394
fix: remove local logos for tokens
shoom3301 3a8ffc4
chore: fix test
shoom3301 19e7d6d
chore: change refreshInterval for native balance
shoom3301 b3cc7ca
refactor: fix press enter handler
shoom3301 c4cc71e
chore: fix build
shoom3301 55d2528
chore: fix test
shoom3301 b2dd6b3
chore: fix text
shoom3301 099c3bc
chore: fix OrderLogPopupMixData
shoom3301 cc8982e
Merge branch 'refactor/tokens-lib' of https://github.com/cowprotocol/…
shoom3301 35a98b3
chore: rename cowprotocolTokenLogoUrl
shoom3301 c0e144f
Merge branch 'refactor/tokens-consts' of https://github.com/cowprotoc…
shoom3301 2ebbc3b
Merge branch 'refactor/token-search-ui' of https://github.com/cowprot…
shoom3301 17a7ca2
chore: update tokens list ui
shoom3301 7d39ad5
Merge branch 'refactor/token-search-ui' of https://github.com/cowprot…
shoom3301 f424238
Merge branch 'refactor/tokens-lib-wiring-1' of https://github.com/cow…
shoom3301 3224445
chore: fix merge
shoom3301 0badc64
Merge branch 'refactor/tokens-lib-wiring-2' of https://github.com/cow…
shoom3301 8f60b4e
Merge branch 'refactor/tokens-lib-wiring-3' of https://github.com/cow…
shoom3301 1e701c6
Merge branch 'refactor/tokens-lib-wiring-4' of https://github.com/cow…
shoom3301 66a4811
Merge branch 'refactor/tokens-lib-wiring-5' of https://github.com/cow…
shoom3301 e3fdbf8
Merge remote-tracking branch 'origin/refactor/tokens-e2e-fix' into re…
shoom3301 3af422f
Merge branch 'refactor/tokens-e2e-fix' of https://github.com/cowproto…
shoom3301 4c73cca
chore: remove unused files
shoom3301 2903c28
chore: merge develop
shoom3301 40c0d9d
chore: fix build
shoom3301 78dc458
chore: fix build
shoom3301 b3192bd
chore: fix getTokenLogoFallbacks
shoom3301 3d28e21
chore: fix lists overriding and search input
shoom3301 6a7a227
feat: loader for list search
shoom3301 8602757
chore: fix token logo rounding
shoom3301 31d3eb3
feat(tokens): migrate user added data from legacy state
shoom3301 d402e48
chore: fix migration for empty storage
shoom3301 f4af72b
chore: fix tokens sorting
shoom3301 0a15bcd
Merge branch 'refactor/tokens-post-review-fixes' of https://github.co…
shoom3301 31b33ae
fix: use strict search for auto-imported tokens
shoom3301 a37ebc2
Merge branch 'refactor/tokens-lib' of https://github.com/cowprotocol/…
shoom3301 cb361a6
Merge branch 'refactor/tokens-lib' of https://github.com/cowprotocol/…
shoom3301 71079b7
chore: simplify code
shoom3301 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
101 changes: 101 additions & 0 deletions
101
libs/tokens/src/migrations/tokensLegacyStateMigration.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,101 @@ | ||
import { ListsSourcesByNetwork, TokenListsState } from '../types' | ||
import { SupportedChainId } from '@cowprotocol/cow-sdk' | ||
import { DEFAULT_TOKENS_LISTS } from '../const/tokensLists' | ||
|
||
const MIGRATION_KEY = 'TOKENS_REFACTORING_MIGRATED' | ||
|
||
export function tokensLegacyStateMigration() { | ||
// Run migration only once | ||
if (localStorage.getItem(MIGRATION_KEY)) return | ||
|
||
try { | ||
migrateLegacyTokensInUserState() | ||
} catch (error) { | ||
console.error('Cannot migrate LegacyTokensInUserState', error) | ||
} | ||
|
||
try { | ||
migrateLegacyTokenLists() | ||
} catch (error) { | ||
console.error('Cannot migrate LegacyTokenLists', error) | ||
} | ||
|
||
localStorage.setItem(MIGRATION_KEY, '1') | ||
} | ||
|
||
// Move user-added tokens from legacy redux store (UserState) to a new atom (userAddedTokensAtom) | ||
// And purge the irrelevant localStorage state | ||
function migrateLegacyTokensInUserState() { | ||
const userStateRaw = localStorage.getItem('redux_localstorage_simple_user') | ||
|
||
if (!userStateRaw) return | ||
|
||
const userState = JSON.parse(userStateRaw) | ||
|
||
if (userState?.tokens && Object.keys(userState.tokens).length > 0) { | ||
localStorage.setItem('userAddedTokensAtom:v1', JSON.stringify(userState.tokens)) | ||
} | ||
|
||
// Cleanup legacy redux store (UserState) | ||
delete userState.favouriteTokens | ||
delete userState.tokens | ||
delete userState.pairs | ||
|
||
localStorage.setItem('redux_localstorage_simple_user', JSON.stringify(userState)) | ||
} | ||
|
||
// Copy user-added lists from the legacy state to a new atom (userAddedListsSourcesAtom + listsStatesByChainAtom) | ||
// And purge the irrelevant localStorage state | ||
function migrateLegacyTokenLists() { | ||
const listsStateRaw = localStorage.getItem('redux_localstorage_simple_lists') | ||
|
||
if (!listsStateRaw) return | ||
|
||
const listsState = JSON.parse(listsStateRaw) | ||
|
||
const userAddedListsSources: ListsSourcesByNetwork = { | ||
[SupportedChainId.MAINNET]: [], | ||
[SupportedChainId.GNOSIS_CHAIN]: [], | ||
[SupportedChainId.GOERLI]: [], | ||
} | ||
|
||
const tokenListsState: TokenListsState = { | ||
[SupportedChainId.MAINNET]: {}, | ||
[SupportedChainId.GNOSIS_CHAIN]: {}, | ||
[SupportedChainId.GOERLI]: {}, | ||
} | ||
|
||
Object.keys(listsState).forEach((chainIdStr) => { | ||
const networkLists = listsState[chainIdStr] | ||
|
||
if (!networkLists.byUrl) return | ||
|
||
const chainId = +chainIdStr as SupportedChainId | ||
const defaultLists = DEFAULT_TOKENS_LISTS[chainId] | ||
|
||
Object.keys(networkLists.byUrl).forEach((listSource) => { | ||
const list = networkLists.byUrl[listSource] | ||
|
||
if (!list || !list.current) return | ||
|
||
const isListInDefaults = defaultLists.find((defaultList) => defaultList.source === listSource) | ||
|
||
if (isListInDefaults) return | ||
|
||
userAddedListsSources[chainId].push({ | ||
source: listSource, | ||
}) | ||
|
||
tokenListsState[chainId][listSource] = { | ||
source: listSource, | ||
list: list.current, | ||
isEnabled: !!networkLists.activeListUrls?.includes(listSource), | ||
} | ||
}) | ||
}) | ||
|
||
localStorage.setItem('userAddedTokenListsAtom:v2', JSON.stringify(userAddedListsSources)) | ||
localStorage.setItem('allTokenListsInfoAtom:v2', JSON.stringify(tokenListsState)) | ||
|
||
localStorage.removeItem('redux_localstorage_simple_lists') | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's enough to keep the migration for the next 3 months