rainbow-me / browser-extension

An Ethereum wallet built for speed 🌈
https://rainbow.me/
GNU General Public License v3.0
168 stars 40 forks source link

fix chain migrations #1738

Closed estebanmino closed 1 month ago

estebanmino commented 1 month ago

Fixes BX-#### Figma link (if any):

What changed (plus any additional context for devs)

Couple of issues are happening right now

For state userChains we could update version to SUPPORTED_CHAINS.length so if there's a new change we don't have to update the version number manually and zustand migrates automatically.

This works in state/userChains but it doesn't in state/rainbowChains because we're using persistOptions that doesn't allow this.

persistOptions needs to manually pass a new migration function on every version bump which is not ideal and is causing additional issues for this case in particular: if rainbowChains updates with a new chain, the migration doesn't pick it automatically, I had to add

function v10(state: unknown) {
          const rnbwState = state as RainbowChainsState;
          rnbwState.rainbowChains = getInitialRainbowChains();
          return rnbwState;
        },

which is manually adding the new chains, we need another way to handle this state bumps automatically

Screen recordings / screenshots

What to test