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: Bump @metamask/providers to ^20.0.0 #29936

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
822e8cb
add isConnected logic
jiexi Jan 27, 2025
5195235
Fix setActiveNetwork call order in permissionController:stateChange
jiexi Jan 28, 2025
dce5a67
restore networkVersion loading value
jiexi Jan 28, 2025
5eea5ea
Merge branch 'main' into jl/send-isConnected-in-getProviderState-chai…
jiexi Jan 28, 2025
d6be967
Bump providers to 20.0.0
jiexi Feb 3, 2025
b790d6d
Merge branch 'main' into jl/send-isConnected-in-getProviderState-chai…
jiexi Feb 3, 2025
8739e1d
hardcode isUnlocked in getProviderState to true
jiexi Feb 3, 2025
a6a40f0
remove metamask_unlockStateChanged event
jiexi Feb 3, 2025
0435868
lint
jiexi Feb 3, 2025
d417b42
Merge branch 'main' into jl/send-isConnected-in-getProviderState-chai…
jiexi Feb 5, 2025
38171cb
yarn dedupe
jiexi Feb 5, 2025
8108290
add comments
jiexi Feb 5, 2025
b4e7142
Merge branch 'main' into jl/send-isConnected-in-getProviderState-chai…
jiexi Feb 5, 2025
7b56a80
Merge branch 'main' into jl/send-isConnected-in-getProviderState-chai…
jiexi Feb 6, 2025
7be8143
fix: remove 'isUnlocked' check from _notifyAccountsChange on metamask…
ffmcgee725 Feb 11, 2025
820761d
merge main and fix conflicts
ffmcgee725 Feb 11, 2025
d31071c
Merge branch 'main' into jl/send-isConnected-in-getProviderState-chai…
jiexi Feb 12, 2025
c949078
Merge remote-tracking branch 'origin/jl/send-isConnected-in-getProvid…
jiexi Feb 12, 2025
a457bc2
Merge branch 'main' into jl/send-isConnected-in-getProviderState-chai…
jiexi Feb 12, 2025
4868431
Merge branch 'main' into jl/send-isConnected-in-getProviderState-chai…
jiexi Feb 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
764 changes: 0 additions & 764 deletions .yarn/patches/@metamask-providers-npm-19.0.0-3d962c6f1a.patch

This file was deleted.

1 change: 0 additions & 1 deletion app/scripts/controllers/permissions/enums.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export enum NOTIFICATION_NAMES {
accountsChanged = 'metamask_accountsChanged',
unlockStateChanged = 'metamask_unlockStateChanged',
chainChanged = 'metamask_chainChanged',
}
58 changes: 22 additions & 36 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2827,6 +2827,10 @@ export default class MetamaskController extends EventEmitter {
if (chains.length > 0 && !chains.includes(currentChainIdForOrigin)) {
const networkClientId =
this.networkController.findNetworkClientIdByChainId(chains[0]);
// setActiveNetwork should be called before setNetworkClientIdForDomain
// to ensure that the isConnected value can be accurately inferred from
// NetworkController.state.networksMetadata in return value of
// `metamask_getProviderState` requests and `metamask_chainChanged` events.
this.networkController.setActiveNetwork(networkClientId);
ffmcgee725 marked this conversation as resolved.
Show resolved Hide resolved
this.selectedNetworkController.setNetworkClientIdForDomain(
origin,
Expand Down Expand Up @@ -3078,7 +3082,11 @@ export default class MetamaskController extends EventEmitter {
const providerNetworkState = await this.getProviderNetworkState(origin);

return {
isUnlocked: this.isUnlocked(),
/**
* We default `isUnlocked` to `true` because even though we no longer emit events depending on this,
* embedded dapp providers might listen directly to our streams, and therefore depend on it, so we leave it here.
*/
isUnlocked: true,
ffmcgee725 marked this conversation as resolved.
Show resolved Hide resolved
accounts: this.getPermittedAccounts(origin),
...providerNetworkState,
};
Expand Down Expand Up @@ -6564,20 +6572,8 @@ export default class MetamaskController extends EventEmitter {

/**
* Handle global application unlock.
* Notifies all connections that the extension is unlocked, and which
* account(s) are currently accessible, if any.
*/
_onUnlock() {
this.notifyAllConnections((origin) => {
return {
method: NOTIFICATION_NAMES.unlockStateChanged,
params: {
isUnlocked: true,
accounts: this.getPermittedAccounts(origin),
Copy link
Member

Choose a reason for hiding this comment

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

Hmm. There might still be a case where a dapp doesn't find out about an account change: when the accounts change before the wallet is marked as unlocked (e.g. if a change is triggered during that update, not sure exactly what the sequence of events is).

I see that we react to account changes below in this file, in _notifyAccountsChange, but we still have the if (this.isUnlocked()) { condition there. If we don't emit the new accounts either here or there, that seems like a problem.

Maybe we can continue emitting them here, or remove that isUnlocked condition in _notifyAccountsChange? Or am I misunderstanding how this works

Copy link
Member

Choose a reason for hiding this comment

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

resolved in 7be8143 by removing isUnlocked condition in _notifyAccountsChange

},
};
});

this.unMarkPasswordForgotten();

// In the current implementation, this handler is triggered by a
Expand All @@ -6588,16 +6584,8 @@ export default class MetamaskController extends EventEmitter {

/**
* Handle global application lock.
* Notifies all connections that the extension is locked.
*/
_onLock() {
this.notifyAllConnections({
method: NOTIFICATION_NAMES.unlockStateChanged,
params: {
isUnlocked: false,
},
});

// In the current implementation, this handler is triggered by a
// KeyringController event. Other controllers subscribe to the 'lock'
// event of the MetaMaskController itself.
Expand Down Expand Up @@ -7126,21 +7114,19 @@ export default class MetamaskController extends EventEmitter {
}

_notifyAccountsChange(origin, newAccounts) {
if (this.isUnlocked()) {
this.notifyConnections(origin, {
method: NOTIFICATION_NAMES.accountsChanged,
// This should be the same as the return value of `eth_accounts`,
// namely an array of the current / most recently selected Ethereum
// account.
params:
newAccounts.length < 2
? // If the length is 1 or 0, the accounts are sorted by definition.
newAccounts
: // If the length is 2 or greater, we have to execute
// `eth_accounts` vi this method.
this.getPermittedAccounts(origin),
});
}
this.notifyConnections(origin, {
method: NOTIFICATION_NAMES.accountsChanged,
// This should be the same as the return value of `eth_accounts`,
// namely an array of the current / most recently selected Ethereum
// account.
params:
newAccounts.length < 2
? // If the length is 1 or 0, the accounts are sorted by definition.
newAccounts
: // If the length is 2 or greater, we have to execute
// `eth_accounts` vi this method.
this.getPermittedAccounts(origin),
});

this.permissionLogController.updateAccountsHistory(origin, newAccounts);
}
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@
"tslib@npm:^2.3.0": "~2.6.0",
"tslib@npm:^2.3.1": "~2.6.0",
"tslib@npm:^2.4.0": "~2.6.0",
"tslib@npm:^2.6.2": "~2.6.0",
"@metamask/providers@npm:^18.3.1": "patch:@metamask/providers@npm%3A19.0.0#~/.yarn/patches/@metamask-providers-npm-19.0.0-3d962c6f1a.patch"
"tslib@npm:^2.6.2": "~2.6.0"
},
"dependencies": {
"@babel/runtime": "patch:@babel/runtime@npm%3A7.25.9#~/.yarn/patches/@babel-runtime-npm-7.25.9-fe8c62510a.patch",
Expand Down Expand Up @@ -340,7 +339,7 @@
"@metamask/ppom-validator": "0.36.0",
"@metamask/preinstalled-example-snap": "^0.3.0",
"@metamask/profile-sync-controller": "^7.0.1",
"@metamask/providers": "patch:@metamask/providers@npm%3A19.0.0#~/.yarn/patches/@metamask-providers-npm-19.0.0-3d962c6f1a.patch",
"@metamask/providers": "^20.0.0",
"@metamask/queued-request-controller": "^7.0.1",
"@metamask/rate-limit-controller": "^6.0.3",
"@metamask/remote-feature-flag-controller": "^1.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ export const NetworkListMenu = ({ onClose }: { onClose: () => void }) => {
// the dapp via silent switchEthereumChain that the
// network has changed due to user action
if (selectedTabOrigin && domains[selectedTabOrigin]) {
// setActiveNetwork should be called before setNetworkClientIdForDomain
// to ensure that the isConnected value can be accurately inferred from
// NetworkController.state.networksMetadata in return value of
// `metamask_getProviderState` requests and `metamask_chainChanged` events.
setNetworkClientIdForDomain(selectedTabOrigin, networkClientId);
}

Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6067,9 +6067,9 @@ __metadata:
languageName: node
linkType: hard

"@metamask/providers@npm:19.0.0":
version: 19.0.0
resolution: "@metamask/providers@npm:19.0.0"
"@metamask/providers@npm:^18.3.1":
version: 18.3.1
resolution: "@metamask/providers@npm:18.3.1"
dependencies:
"@metamask/json-rpc-engine": "npm:^10.0.2"
"@metamask/json-rpc-middleware-stream": "npm:^8.0.6"
Expand All @@ -6084,13 +6084,13 @@ __metadata:
readable-stream: "npm:^3.6.2"
peerDependencies:
webextension-polyfill: ^0.10.0 || ^0.11.0 || ^0.12.0
checksum: 10/e45b2e90aa45db689bed582e85181d6964daff3c4b651ffc8503edcec2206a1b76677c0ae6fc0b29cef37a1b33775545e73bd1cf62802a4fc5e2841973cdafb6
checksum: 10/0e21ba9cce926a49dedbfe30fc964cd2349ee6bf9156f525fb894dcbc147a3ae480384884131a6b1a0a508989b547d8c8d2aeb3d10e11f67a8ee5230c45631a8
languageName: node
linkType: hard

"@metamask/providers@patch:@metamask/providers@npm%3A19.0.0#~/.yarn/patches/@metamask-providers-npm-19.0.0-3d962c6f1a.patch":
version: 19.0.0
resolution: "@metamask/providers@patch:@metamask/providers@npm%3A19.0.0#~/.yarn/patches/@metamask-providers-npm-19.0.0-3d962c6f1a.patch::version=19.0.0&hash=46053a"
"@metamask/providers@npm:^20.0.0":
version: 20.0.0
resolution: "@metamask/providers@npm:20.0.0"
dependencies:
"@metamask/json-rpc-engine": "npm:^10.0.2"
"@metamask/json-rpc-middleware-stream": "npm:^8.0.6"
Expand All @@ -6105,7 +6105,7 @@ __metadata:
readable-stream: "npm:^3.6.2"
peerDependencies:
webextension-polyfill: ^0.10.0 || ^0.11.0 || ^0.12.0
checksum: 10/2999f2613502ea9b26e7693e6113d55e22cca783cc670a88b8fd9b4fc135da2db1687880fea968e6848596050eb52f3bc704438b265aa1eeebf449d7916a5d71
checksum: 10/b958d03a9380d86e605db239109a3debcc1ffde90371abe5beb82a5bed46c7718303a2bb92ec269eae16eff145b9ebbfcb3445a2b6bad4f297a590ee725a5bad
languageName: node
linkType: hard

Expand Down Expand Up @@ -26689,7 +26689,7 @@ __metadata:
"@metamask/preferences-controller": "npm:^15.0.2"
"@metamask/preinstalled-example-snap": "npm:^0.3.0"
"@metamask/profile-sync-controller": "npm:^7.0.1"
"@metamask/providers": "patch:@metamask/providers@npm%3A19.0.0#~/.yarn/patches/@metamask-providers-npm-19.0.0-3d962c6f1a.patch"
"@metamask/providers": "npm:^20.0.0"
"@metamask/queued-request-controller": "npm:^7.0.1"
"@metamask/rate-limit-controller": "npm:^6.0.3"
"@metamask/remote-feature-flag-controller": "npm:^1.3.0"
Expand Down
Loading