Conversation
6163af0 to
a475727
Compare
Builds ready [a475727]
Page Load Metrics (591 ± 21 ms)
|
| */ | ||
| _subscribeProviderType() { | ||
| this.network.providerStore.subscribe(() => { | ||
| _subscribeToNetworkDidChange() { |
There was a problem hiding this comment.
As far as I can tell, this change is functionally equivalent, as the NETWORK_DID_CHANGE event is only emitted at the time that the providerStore is updated.
| @@ -671,8 +672,8 @@ export default class PreferencesController { | |||
| * | |||
There was a problem hiding this comment.
Nit: the code comment for this method could be slightly modified. Subscription to NETWORK_DID_CHANGE events or something like that.
There was a problem hiding this comment.
reworded comment in the latest commit
app/scripts/migrations/052.js
Outdated
| const newAccountHiddenTokens = {}; | ||
|
|
||
| if (accountTokens && Object.keys(accountTokens).length > 0) { | ||
| for (const account of Object.keys(accountTokens)) { |
There was a problem hiding this comment.
Nit: I think the account variable might be more appropriately name address or accountAddress, which better conveys what that variable is.
There was a problem hiding this comment.
done in the latest
app/scripts/migrations/052.js
Outdated
| break; | ||
| } | ||
| } | ||
| if (accountTokens[account][NETWORK_TYPE_RPC]) { |
There was a problem hiding this comment.
Any reason to put this in its own if block instead of add it as a case to the above switch?
There was a problem hiding this comment.
Oh, because you need the above for loop to complete before the below logic can properly migrate account tokens for custom rpcs that share a chain id with one of the default networks
app/scripts/migrations/052.js
Outdated
| ) { | ||
| newAccountTokens[account][detail.chainId] = uniqBy( | ||
| [ | ||
| ...newAccountTokens[account][detail.chainId], |
There was a problem hiding this comment.
Given this logic, it seems the following could happen:
- user currently has token ABC on mainnet
- user currently has token DEF on a custom rpc X, which has the same chainId as mainnet
- user currently has tokens GHI on a custom rpc Y, which has a different chainId than mainnet
- so currently, on mainnet, the user will only see ABC, but on both X and Y the user will see both DEF and GHI (because all tokens are stored by provider type, and X and Y have the same provider type
NETWORK_TYPE_RPC) - after this migration, the user will (as desired) continue to see ABC on mainnet and will see ABC on X (via
...newAccountTokens[account][detail.chainId]), and (as desired) will see DEF on mainnet and X, BUT will also see GHI on mainnet and X (via...accountTokens[account][NETWORK_TYPE_RPC])
I think we should avoid this if possible, but I am not sure that it is possible...
There was a problem hiding this comment.
or am I misunderstanding somehow?
There was a problem hiding this comment.
If I am not misunderstanding, the only way to achieve a distinction of NETWORK_TYPE_RPC tokens by chainId would be to check on chain data via a network request. That is, we could check if the user has any of the token each of the networks with the chain id. Not sure if this is feasbile within our migration or desirable given network load.
There was a problem hiding this comment.
Perhaps we need to add precision to what we are keying by here: key by a combination of provider type and chain id
There was a problem hiding this comment.
key by a combination of provider type and chain id
This would result in the following:
- the migration would not change the current tokens of default networks
- all custom networks would continue to have all the tokens they already do
- custom networks and default networks that share chainIds would NOT have each others tokens as a result of the migration
- post migration, newly added tokens will be added network by network, and even if two networks share a chainId, adding a token to one will not add a token to another (unless we add further code that ensures that)
There was a problem hiding this comment.
I might suggest a simpler solution that gets more to the heart of #8668 (treating custom networks with the chainId 0x1 as mainnet) - For this migration prefer the tokens listed under mainnet for '0x1'. So the following would happen:
- For all custom networks the user has added that don't share a chainId with a default MetaMask chain, they will continue to have all tokens listed under 'rpc' provider type.
- For all default networks the user tokens will be unchanged.
- For any custom network that shares a chainId with a default network, they will inherit the default network's tokens and those will be shared across them.
If we want to preserve the ability to have different tokens on different networks (which is sort of going against the spirit of #8668 in my opinion) that share the same chainId, then I'm fine with @danjm 's suggestion.
@MetaMask/extension-devs anyone else have opinions?
There was a problem hiding this comment.
If I am not misunderstanding, the only way to achieve a distinction of NETWORK_TYPE_RPC tokens by chainId would be to check on chain data via a network request. That is, we could check if the user has any of the token each of the networks with the chain id. Not sure if this is feasbile within our migration or desirable given network load.
i'd like to point out that we don't currently do this, any token a user adds for a custom network is added to all custom networks. I think it's out of scope to consider this for this migration and puts the extension in a better place to handle it in the future by isolating tokens added per chain.
There was a problem hiding this comment.
@brad-decker The simpler solution you suggested sounds good. One remaining question about this case:
For any custom network that shares a chainId with a default network, they will inherit the default network's tokens and those will be shared across them.
Will such custom networks also continue to have all other tokens that are currently under the rpc provider type. Or are you suggesting that, after the migration, these custom networks will only have the tokens that are from the default network they share a chainId with?
There was a problem hiding this comment.
Given the following current state:
const frequentRpcListDetail = [
{
chainId: '0x1',
networkName: 'mainnet custom endpoint'
},
{
chainId: '0xabc',
networkName: 'non default network'
}
];
const accounTokens = {
'0x1111': {
'mainnet': ['X', 'Y', 'Z'],
'rpc': ['A', 'B', 'C', 'Z'],
}
};the resulting new structure of accountTokens would be:
accounTokens = {
'0x1111': {
'0x1': ['X', 'Y', 'Z'],
'0xabc': ['A', 'B', 'C', 'Z'],
}
};so previously the user connected to their custom mainnet endpoint and added 'Z' token, which is also in the default mainnet. presumably for the purposes of tracking that mainnet token on their custom network. They also added 'A', 'B', 'C' tokens for the '0xabc' chain. After the migration the custom network and mainnet will have identical token lists and will remain in sync, including hiding tokens. The custom network with a non default network chain id will remain in the same state it was in prior to the migration with the added benefit that hiding tokens on that network will not hide the tokens elsewhere and adding new tokens to it will not add them elsewhere (for custom RPCs anyways)
There was a problem hiding this comment.
This logic was implemented in the latest commit
app/scripts/migrations/052.js
Outdated
| ) { | ||
| newAccountHiddenTokens[account][detail.chainId] = uniqBy( | ||
| [ | ||
| ...newAccountHiddenTokens[account][detail.chainId], |
There was a problem hiding this comment.
This is subject to similar concerns that I raised above.
a475727 to
7291990
Compare
Builds ready [7291990]
Page Load Metrics (667 ± 49 ms)
|
danjm
left a comment
There was a problem hiding this comment.
Latest changes look good. Tests look good. Approved.
Progresses: #8668
fixes #10518
Explanation: Tokens are keyed by providerType which is 'rpc' for all custom networks. Adding a token to one custom network replicates it across all custom networks. This is not only inappropriate but also could lead to issues where a token doesn't exist at the same contract address across chains.
This PR aims to replicate the user's current experience but silently move the 'rpc' tokens into keys by chainId. It also merges chainIds for the five pre-programmed chains with any custom networks that share those chainIds, so mainnet and custom network with chainId 0x1 will have the same tokens.
after the migration, any new tokens added per chain will be specific to that chain, and removing tokens from custom networks will not remove them from all.