Skip to content

Commit

Permalink
chainid migration (#2161)
Browse files Browse the repository at this point in the history
* chainidmigration

* Update app/store/migrations.js

Co-authored-by: Erik Marks <25517051+rekmarks@users.noreply.github.com>

* migration2

* bump

* logs

* migrations

* bump

* circle

* Revert "bump"

This reverts commit cdceb58.

Co-authored-by: Erik Marks <25517051+rekmarks@users.noreply.github.com>
  • Loading branch information
estebanmino and rekmarks authored Jan 25, 2021
1 parent e664c4f commit 99959d0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
27 changes: 26 additions & 1 deletion app/store/migrations.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NetworksChainId } from '@metamask/controllers';
import AppConstants from '../core/AppConstants';
import { getAllNetworks, isSafeChainId } from '../util/networks';

Expand Down Expand Up @@ -47,7 +48,31 @@ export const migrations = {
};
}
return state;
},
3: state => {
const provider = state.engine.backgroundState.NetworkController.provider;
const chainId = NetworksChainId[provider.type];
// if chainId === '' is a rpc
if (chainId) {
state.engine.backgroundState.NetworkController.provider = { ...provider, chainId };
return state;
}

// If provider is rpc, check if the current network has a valid chainId
const storedChainId = typeof provider.chainId === 'string' ? provider.chainId : '';
const isDecimalString = /^[1-9]\d*$/u.test(storedChainId);
const hasInvalidChainId = !isDecimalString || !isSafeChainId(parseInt(storedChainId, 10));

if (hasInvalidChainId) {
// If the current network does not have a chainId, switch to testnet.
state.engine.backgroundState.NetworkController.provider = {
ticker: 'ETH',
type: 'rinkeby',
chainId: NetworksChainId.rinkeby
};
}
return state;
}
};

export const version = 2;
export const version = 3;
4 changes: 2 additions & 2 deletions ios/MetaMask.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@
CODE_SIGN_ENTITLEMENTS = MetaMask/MetaMaskDebug.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 564;
CURRENT_PROJECT_VERSION = 567;
DEAD_CODE_STRIPPING = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = 48XVW22RCG;
Expand Down Expand Up @@ -910,7 +910,7 @@
CODE_SIGN_ENTITLEMENTS = MetaMask/MetaMask.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 564;
CURRENT_PROJECT_VERSION = 567;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = 48XVW22RCG;
FRAMEWORK_SEARCH_PATHS = (
Expand Down

0 comments on commit 99959d0

Please sign in to comment.