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

feat(tokens): migrate user added data from legacy state #3267

Merged
merged 125 commits into from
Oct 27, 2023

Conversation

shoom3301
Copy link
Collaborator

@shoom3301 shoom3301 commented Oct 24, 2023

Summary

During the refactoring, some data was moved from redux to jotai atoms.

  1. User-added tokens: redux_localstorage_simple_user.tokens -> userAddedTokensAtom:v1
  2. User-added lists: redux_localstorage_simple_lists -> allTokenListsInfoAtom:v2
  3. Also, favorite tokens were moved from redux_localstorage_simple_user.favouriteTokens to favouriteTokensAtom. I didn't migrate them because it looks like it doesn't worth it.
  4. redux_localstorage_simple_user.pairs was just removed, now tokensStateAtom performs its functions.

To Test

  1. Open https://dev.swap.cow.fi/
  2. Add some custom tokens and lists
  3. Keep some newly added lists enabled and some disabled
  4. Run downloadLocalStorage() in the console (see the snipped below). It will download a file with the localStorage state
  5. Open Dapp from this PR
  6. Clean all browser data for this URL: Console -> Application -> Storage -> "Clear site data"
  7. Copy the content of the file from step 4 and run in the console: var state = <PUT_THE_FILE_CONTENT>, press Enter
  8. Run the code in the console: localStorage.clear(); var stateObj = JSON.parse(state); Object.keys(stateObj).forEach(key => localStorage.setItem(key, stateObj[key])). It will apply the localStorage state from dev.swap.cow.fi into the current tab
  9. Reload the page
  • TOKENS_REFACTORING_MIGRATED should be added in the localStorage
  • User-added tokens should be the same as in dev.swap.cow.fi
  • User-added lists should be the same as in dev.swap.cow.fi including enabled/disabled state
  • Favourite tokens should be reset to defaults
  • redux_localstorage_simple_lists should be removed from localStorage
  • redux_localstorage_simple_user.favouriteTokens should be removed from localStorage
  • redux_localstorage_simple_user.tokens should be removed from localStorage
  • redux_localstorage_simple_user.pairs should be removed from localStorage
  1. Open the PR in incognito mode
  • there should not be user-added tokens
  • there should not be user-added lists

Download localStorage snippet:

function downloadLocalStorage() {
    const storageObj = JSON.stringify(Object.keys(localStorage).reduce((acc, key) => {
        acc[key] = localStorage.getItem(key)

        return acc
    }, {}));
    
    const a = document.createElement('a');
    a.style.display = 'none';
    a.href = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(storageObj))
    // the filename you want
    a.download = 'todo-1.json';
    document.body.appendChild(a);
    a.click();
}

…col/cowswap into refactor/tokens-remove-legacy

# Conflicts:
#	apps/cowswap-frontend/src/legacy/components/SearchModal/ImportList/index.tsx
#	apps/cowswap-frontend/src/legacy/state/lists/reducer.ts
@shoom3301 shoom3301 requested a review from a team October 24, 2023 13:30
@shoom3301 shoom3301 self-assigned this Oct 24, 2023
@vercel
Copy link

vercel bot commented Oct 24, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
swap-dev ✅ Ready (Inspect) Visit Preview Oct 27, 2023 10:49am

🌃 Cosmos ↗︎

import { tokensLegacyStateMigration } from './migrations/tokensLegacyStateMigration'

// Run migrations first of all
// TODO: remove it after 30.01.2024
Copy link
Collaborator Author

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

Copy link
Collaborator

@alfetopito alfetopito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, loved the migration!

One of the tests failed, though.

The legacy simple_lists key is still there.
image

@shoom3301 shoom3301 changed the title feat(tokens): migrate user added data from legacy state [8] feat(tokens): migrate user added data from legacy state Oct 26, 2023
@shoom3301
Copy link
Collaborator Author

@alfetopito it looks like an outdated state in the dev tools. Could you please try to click the refresh button?

image

Copy link
Contributor

@anxolin anxolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I follow correctly the steps, but it didn't work for me

  1. I added SHIT token in DEV: https://etherscan.io/token/0x4e4a47cAC6A28A62dcC20990ed2cdA9BC659469F
image
  1. Exported all my local history in DEV (after adding the SHIT token)

  2. Cleared the local storage in this PR

  3. Imported the local storage

  4. Try to navigate to SHIT. I get an IMPORT MODAL for some other Token I don't know about: SUZUME
    https://swap-dev-git-refactor-tokens-migrations-cowswap.vercel.app/#/1/swap/SHIT

image

@shoom3301
Copy link
Collaborator Author

@anxolin thank you! Nice catch!
It's because I didn't add a strict search for tokens auto-importing.
The fix: 31b33ae

@shoom3301 shoom3301 changed the base branch from refactor/tokens-post-review-fixes to refactor/tokens-lib October 26, 2023 12:39
@shoom3301 shoom3301 changed the title [8] feat(tokens): migrate user added data from legacy state feat(tokens): migrate user added data from legacy state Oct 26, 2023
@alfetopito
Copy link
Collaborator

@alfetopito it looks like an outdated state in the dev tools. Could you please try to click the refresh button?
image

I tried, didn't help:

Screen.Recording.2023-10-26.at.18.21.15.mov

@shoom3301
Copy link
Collaborator Author

@alfetopito thanks!
The problem was in 8. Run the code in the console script. Updated it, works well now

@shoom3301 shoom3301 merged commit d999cca into refactor/tokens-lib Oct 27, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Oct 27, 2023
@alfetopito alfetopito deleted the refactor/tokens-migrations branch October 31, 2023 14:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants