Skip to content

Commit d1f1f0a

Browse files
fix: Handle withKeyring breaking change in MultichainRouter (#3238)
`KeyringController.withKeyring` had a breaking change in MetaMask/core@8e15f01 where the format of the callback parameters was changed. This breaks the SIP-26 branch as the extension is already using the latest version of the `KeyringController`. This PR adjusts our usage of `withKeyring` to expect the new format.
1 parent adecea5 commit d1f1f0a

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

packages/snaps-controllers/src/multichain/MultichainRouter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type SnapKeyring = {
7272

7373
// Expecting a bound function that calls KeyringController.withKeyring selecting the Snap keyring
7474
type WithSnapKeyringFunction = <ReturnType>(
75-
operation: (keyring: SnapKeyring) => Promise<ReturnType>,
75+
operation: ({ keyring }: { keyring: SnapKeyring }) => Promise<ReturnType>,
7676
) => Promise<ReturnType>;
7777

7878
export type AccountsControllerListMultichainAccountsAction = {
@@ -165,7 +165,7 @@ export class MultichainRouter {
165165
request: JsonRpcRequest,
166166
) {
167167
try {
168-
const result = await this.#withSnapKeyring(async (keyring) =>
168+
const result = await this.#withSnapKeyring(async ({ keyring }) =>
169169
keyring.resolveAccountAddress(snapId, scope, request),
170170
);
171171
const address = result?.address;
@@ -323,7 +323,7 @@ export class MultichainRouter {
323323
);
324324

325325
if (accountId) {
326-
return this.#withSnapKeyring(async (keyring) =>
326+
return this.#withSnapKeyring(async ({ keyring }) =>
327327
keyring.submitRequest({
328328
account: accountId,
329329
scope,

packages/snaps-controllers/src/test-utils/multichain.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ type MockSnapKeyring = {
9595
) => Promise<{ address: CaipAccountId } | null>;
9696
};
9797

98-
type MockOperationCallback = (keyring: MockSnapKeyring) => Promise<Json>;
98+
type MockOperationCallback = ({
99+
keyring,
100+
}: {
101+
keyring: MockSnapKeyring;
102+
}) => Promise<Json>;
99103

100104
export const getMockWithSnapKeyring = (
101105
{ submitRequest = jest.fn(), resolveAccountAddress = jest.fn() } = {
@@ -105,7 +109,9 @@ export const getMockWithSnapKeyring = (
105109
) => {
106110
return async (callback: MockOperationCallback) =>
107111
callback({
108-
submitRequest,
109-
resolveAccountAddress,
112+
keyring: {
113+
submitRequest,
114+
resolveAccountAddress,
115+
},
110116
});
111117
};

0 commit comments

Comments
 (0)