Skip to content

Commit

Permalink
Move the saveSnapKeyring callback to the SnapKeyring constructor (#…
Browse files Browse the repository at this point in the history
…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`
  • Loading branch information
danroc authored Sep 12, 2023
1 parent 947cb0e commit 56310e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})(),
Expand Down Expand Up @@ -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)
}),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 56310e5

Please sign in to comment.