From 56310e56245c970283e55dab2f3e1458b4ceca3d Mon Sep 17 00:00:00 2001 From: Daniel Rocha Date: Tue, 12 Sep 2023 11:49:07 +0200 Subject: [PATCH] Move the `saveSnapKeyring` callback to the `SnapKeyring` constructor (#20786) * Move the `saveSnapKeyring` callback to the `SnapKeyring` constructor This commit removes `saveSnapKeyring` from the list of callbacks passed to the Snap Controller since this function contains business logic specific to the Snap Keyring. Instead, `saveSnapKeyring` is injected into the Snap Keyring through a new argument called `callbacks`. In the future, the `callbacks` argument can be reused to pass other callbacks. * Update the Snap Keyring dependency * chore: use release versions of `eth-snap-keyring` and `rpc-methods` * chore: update `yarn.lock` * chore: update `yarn.lock` --- app/scripts/metamask-controller.js | 10 ++++++---- package.json | 2 +- yarn.lock | 10 +++++----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 707f30b435a5..4f2270b13364 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -827,7 +827,12 @@ export default class MetamaskController extends EventEmitter { ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) additionalKeyrings.push( (() => { - const builder = () => new SnapKeyring(this.snapController); + const builder = () => + new SnapKeyring(this.snapController, { + saveState: async () => { + await this.keyringController.persistAllKeyrings(); + }, + }); builder.type = SnapKeyring.type; return builder; })(), @@ -1955,9 +1960,6 @@ export default class MetamaskController extends EventEmitter { ///: END:ONLY_INCLUDE_IN ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) getSnapKeyring: this.getSnapKeyring.bind(this), - saveSnapKeyring: async () => { - await this.keyringController.persistAllKeyrings(); - }, ///: END:ONLY_INCLUDE_IN ///: BEGIN:ONLY_INCLUDE_IN(snaps) }), diff --git a/package.json b/package.json index 0c52672a97dd..808e004ce92e 100644 --- a/package.json +++ b/package.json @@ -244,7 +244,7 @@ "@metamask/eth-json-rpc-middleware": "^11.0.0", "@metamask/eth-keyring-controller": "^10.0.1", "@metamask/eth-ledger-bridge-keyring": "^0.15.0", - "@metamask/eth-snap-keyring": "^0.1.3", + "@metamask/eth-snap-keyring": "^0.1.4", "@metamask/eth-token-tracker": "^4.0.0", "@metamask/eth-trezor-keyring": "^1.1.0", "@metamask/etherscan-link": "^2.2.0", diff --git a/yarn.lock b/yarn.lock index e4d07d62519d..a78f1e06d483 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4151,9 +4151,9 @@ __metadata: languageName: node linkType: hard -"@metamask/eth-snap-keyring@npm:^0.1.3": - version: 0.1.3 - resolution: "@metamask/eth-snap-keyring@npm:0.1.3" +"@metamask/eth-snap-keyring@npm:^0.1.4": + version: 0.1.4 + resolution: "@metamask/eth-snap-keyring@npm:0.1.4" dependencies: "@ethereumjs/tx": "npm:^4.1.2" "@metamask/eth-sig-util": "npm:^5.1.0" @@ -4163,7 +4163,7 @@ __metadata: "@types/uuid": "npm:^9.0.1" superstruct: "npm:^1.0.3" uuid: "npm:^9.0.0" - checksum: df426fca165d3b22347324a4b17cefa8fc86dd3ef669ab054233c168437f567f77992b69633ec13a1d8c5b77701ba2df25b68fba246cd46ee14f97072f0ac1a6 + checksum: fe626464be4cc86665fadece8e55d55494eecaa9b86193f2381f72f8366781ff5f4faca4fb5a94e0ab4d75f8b21bb7914b22854f733bb941f6ea359ba386285e languageName: node linkType: hard @@ -24193,7 +24193,7 @@ __metadata: "@metamask/eth-json-rpc-middleware": "npm:^11.0.0" "@metamask/eth-keyring-controller": "npm:^10.0.1" "@metamask/eth-ledger-bridge-keyring": "npm:^0.15.0" - "@metamask/eth-snap-keyring": "npm:^0.1.3" + "@metamask/eth-snap-keyring": "npm:^0.1.4" "@metamask/eth-token-tracker": "npm:^4.0.0" "@metamask/eth-trezor-keyring": "npm:^1.1.0" "@metamask/etherscan-link": "npm:^2.2.0"