Skip to content

Commit

Permalink
Integrate changes from controllers v15.0.2 (#3071)
Browse files Browse the repository at this point in the history
* ignored tokens updates

* add migration

* cleanup

* bump @metamask/controllers to 15.0.2
  • Loading branch information
adonesky1 authored Sep 2, 2021
1 parent a87884a commit 1ddc113
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 29 deletions.
42 changes: 15 additions & 27 deletions app/core/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ class Engine {

TokensController.update({
allTokens: {},
allIgnoredTokens: {},
ignoredTokens: [],
tokens: [],
suggestedAssets: []
Expand All @@ -446,13 +447,22 @@ class Engine {
});
};

sync = async ({ accounts, preferences, network, transactions, seed, pass, importedAccounts }) => {
sync = async ({
accounts,
preferences,
network,
transactions,
seed,
pass,
importedAccounts,
tokens: { allTokens, allIgnoredTokens }
}) => {
const {
KeyringController,
PreferencesController,
NetworkController,
TransactionController,
TokensController
TokensController,
} = this.context;

// Select same network ?
Expand All @@ -470,31 +480,9 @@ class Engine {
await KeyringController.importAccountWithStrategy('privateKey', [importedAccounts[i]]);
}
}
// Sync tokens
const allTokens = {};
Object.keys(preferences.accountTokens).forEach(address => {
const checksummedAddress = toChecksumAddress(address);
allTokens[checksummedAddress] = {};
Object.keys(preferences.accountTokens[address]).forEach(chainId => {
const network = Object.values(Networks).find(
({ hexChainId: networkChainId }) => networkChainId === chainId
);
const networkType = network?.networkType;
// !networkType this will probably happen on custom rpc networks
if (!networkType) return;
allTokens[checksummedAddress][networkType] =
chainId !== `0x1`
? preferences.accountTokens[address][chainId]
: preferences.accountTokens[address][chainId]
.filter(({ address }) =>
contractMap[toChecksumAddress(address)]
? contractMap[toChecksumAddress(address)].erc20
: true
)
.map((token: { address: string; }) => ({ ...token, address: toChecksumAddress(token.address) }));
});
});
await TokensController.update({ allTokens });

// Restore tokens
await TokensController.update({ allTokens, allIgnoredTokens });

// Restore preferences
const updatedPref = { ...preferences, identities: {} };
Expand Down
45 changes: 44 additions & 1 deletion app/store/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,51 @@ export const migrations = {
: DefaultPreference.set(METRICS_OPT_IN, DENIED);
DefaultPreference.set(ONBOARDING_WIZARD, EXPLORED);

return state;
},
7: state => {
const allTokens = state.engine.backgroundState.TokensController.allTokens;
const newAllTokens = {};
if (allTokens) {
Object.keys(allTokens).forEach(accountAddress => {
Object.keys(allTokens[accountAddress]).forEach(chainId => {
const tokensArray = allTokens[accountAddress][chainId];
if (newAllTokens[chainId] === undefined) {
newAllTokens[chainId] = { [accountAddress]: tokensArray };
} else {
newAllTokens[chainId] = {
...newAllTokens[chainId],
[accountAddress]: tokensArray
};
}
});
});
}

const ignoredTokens = state.engine.backgroundState.TokensController.ignoredTokens;
const newAllIgnoredTokens = {};
Object.keys(allTokens).forEach(accountAddress => {
Object.keys(allTokens[accountAddress]).forEach(chainId => {
if (newAllIgnoredTokens[chainId] === undefined) {
newAllIgnoredTokens[chainId] = {
[accountAddress]: ignoredTokens
};
} else {
newAllIgnoredTokens[chainId] = {
...newAllIgnoredTokens[chainId],
[accountAddress]: ignoredTokens
};
}
});
});

state.engine.backgroundState.TokensController = {
allTokens: newAllTokens,
allIgnoredTokens: newAllIgnoredTokens
};

return state;
}
};

export const version = 6;
export const version = 7;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"dependencies": {
"@exodus/react-native-payments": "https://github.com/wachunei/react-native-payments.git#package-json-hack",
"@metamask/contract-metadata": "^1.23.0",
"@metamask/controllers": "^14.2.0",
"@metamask/controllers": "^15.0.2",
"@metamask/etherscan-link": "^2.0.0",
"@metamask/swaps-controller": "^6.2.0",
"@react-native-community/async-storage": "1.12.1",
Expand Down
42 changes: 42 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,11 @@
resolved "https://registry.yarnpkg.com/@metamask/contract-metadata/-/contract-metadata-1.28.0.tgz#76796f5010aa4aa6d28bf6fe36392017cea687cb"
integrity sha512-QZj6Y1nmSs9BHufBS1GSuPX5TVFa5gbtMhEo/KRuSdKyY43OdlbBKuyT36/l5p30krlzfMX8bN0MAWqw3g0Bog==

"@metamask/contract-metadata@^1.29.0":
version "1.29.0"
resolved "https://registry.yarnpkg.com/@metamask/contract-metadata/-/contract-metadata-1.29.0.tgz#4ca86a2f03d4dad4350d09216a7fe92f9dd21c8e"
integrity sha512-wxsC0ZCyhPKqThvmsL8+2zVWGWPqofSo8HNtOuOnQM9oGbXX9294imJ3T+A/Lov8fkX4jAWZOeNV0uR80zkNtA==

"@metamask/controllers@^14.2.0":
version "14.2.0"
resolved "https://registry.yarnpkg.com/@metamask/controllers/-/controllers-14.2.0.tgz#bed161ac3523fd525be79b0e557b132e2e2526e4"
Expand Down Expand Up @@ -1460,6 +1465,43 @@
web3 "^0.20.7"
web3-provider-engine "^16.0.3"

"@metamask/controllers@^15.0.2":
version "15.0.2"
resolved "https://registry.yarnpkg.com/@metamask/controllers/-/controllers-15.0.2.tgz#b4012a8bf28bd2c8dbb3c96f4d934d6cf1bb778c"
integrity sha512-MPxfZ2OOTzEa5lUzDsSkINtlTDU4q4udjpBNM5Dq1yCnLKIuPKzYC5nl/rA88Ssr9Hs6babCtMbnUpbbjQjLOg==
dependencies:
"@ethereumjs/common" "^2.3.1"
"@ethereumjs/tx" "^3.2.1"
"@metamask/contract-metadata" "^1.29.0"
"@types/uuid" "^8.3.0"
abort-controller "^3.0.0"
async-mutex "^0.2.6"
babel-runtime "^6.26.0"
eth-ens-namehash "^2.0.8"
eth-json-rpc-infura "^5.1.0"
eth-keyring-controller "^6.2.1"
eth-method-registry "1.1.0"
eth-phishing-detect "^1.1.14"
eth-query "^2.1.2"
eth-rpc-errors "^4.0.0"
eth-sig-util "^3.0.0"
ethereumjs-util "^7.0.10"
ethereumjs-wallet "^1.0.1"
ethers "^5.4.1"
ethjs-unit "^0.1.6"
ethjs-util "^0.1.6"
human-standard-collectible-abi "^1.0.2"
human-standard-token-abi "^2.0.0"
immer "^8.0.1"
isomorphic-fetch "^3.0.0"
jsonschema "^1.2.4"
nanoid "^3.1.12"
punycode "^2.1.1"
single-call-balance-checker-abi "^1.0.0"
uuid "^8.3.2"
web3 "^0.20.7"
web3-provider-engine "^16.0.3"

"@metamask/etherscan-link@^2.0.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@metamask/etherscan-link/-/etherscan-link-2.1.0.tgz#c0be8e68445b7b83cf85bcc03a56cdf8e256c973"
Expand Down

0 comments on commit 1ddc113

Please sign in to comment.