Skip to content
Open
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d8ad969
bump chain-agnostic-permission and multichain-api-middleware
jiexi Apr 13, 2026
c9a6288
pass in sortAccountIdsByLastSelected where necessary
jiexi Apr 13, 2026
70593ba
Fix spec
jiexi Apr 13, 2026
5d5cb42
add specs
jiexi Apr 13, 2026
79e82bb
Merge branch 'main' into jl/WAPI-1387/multichain-api-accounts-ordering
jiexi Apr 13, 2026
604df80
yarn dedupe
jiexi Apr 13, 2026
d5e87f4
lint
jiexi Apr 13, 2026
0368835
update comment
jiexi Apr 13, 2026
7df2bce
add explicit error check to try catch in AccountGroupChange handler
jiexi Apr 13, 2026
e2185d9
Merge branch 'main' into jl/WAPI-1387/multichain-api-accounts-ordering
jiexi Apr 13, 2026
ec887ba
Merge branch 'main' into jl/WAPI-1387/multichain-api-accounts-ordering
jiexi Apr 15, 2026
33bc472
fix spec
jiexi Apr 15, 2026
45a0781
Merge branch 'main' into jl/WAPI-1387/multichain-api-accounts-ordering
jiexi Apr 20, 2026
6795aff
Merge branch 'main' into jl/WAPI-1387/multichain-api-accounts-ordering
jiexi Apr 23, 2026
afdd175
refetch caveat value again
jiexi Apr 23, 2026
397d716
sort using AccountGroup metadata
jiexi Apr 23, 2026
8fe874a
lint
jiexi Apr 23, 2026
079a44f
Merge branch 'main' into jl/WAPI-1387/multichain-api-accounts-ordering
jiexi Apr 23, 2026
b8c5e46
Merge remote-tracking branch 'origin/jl/WAPI-1387/multichain-api-acco…
jiexi Apr 23, 2026
3c05cfd
Revert "lint"
jiexi Apr 23, 2026
9edb66d
Revert "sort using AccountGroup metadata"
jiexi Apr 23, 2026
724e71e
Merge branch 'main' into jl/WAPI-1387/multichain-api-accounts-ordering
jiexi Apr 23, 2026
3203940
Reapply "sort using AccountGroup metadata"
jiexi Apr 23, 2026
09e60f9
Reapply "lint"
jiexi Apr 23, 2026
45f624c
remove setTimeout hack
jiexi Apr 23, 2026
6c8aed9
lint
jiexi Apr 23, 2026
fd17a8d
Merge branch 'jl/WAPI-1387/multichain-api-accounts-ordering' into jl/…
jiexi Apr 23, 2026
65154d1
Merge branch 'main' into jl/WAPI-1387/multichain-api-accounts-ordering
jiexi Apr 27, 2026
e7728c2
Merge branch 'jl/WAPI-1387/multichain-api-accounts-ordering' into jl/…
jiexi Apr 27, 2026
f0b2327
Merge branch 'main' into jl/use-account-group-metadata-for-sorting-in…
jiexi Apr 28, 2026
5166b38
lint
jiexi Apr 28, 2026
65c7973
Update app/core/Permissions/index.test.ts
jiexi Apr 29, 2026
b7c67b3
Update app/core/Permissions/index.test.ts
jiexi Apr 29, 2026
bbffdf9
Merge branch 'main' into jl/use-account-group-metadata-for-sorting-in…
jiexi Apr 30, 2026
4055330
Merge remote-tracking branch 'origin/jl/use-account-group-metadata-fo…
jiexi Apr 30, 2026
9f702c1
remove unused imports
jiexi Apr 30, 2026
8ba0fcf
Merge branch 'main' into jl/use-account-group-metadata-for-sorting-in…
jiexi May 4, 2026
97c4b45
lint
jiexi May 4, 2026
a9161a0
Merge branch 'main' into jl/use-account-group-metadata-for-sorting-in…
jiexi May 7, 2026
2341564
fix spec
jiexi May 7, 2026
93431ee
fix spec
jiexi May 8, 2026
a4df7df
lint
jiexi May 8, 2026
fd55c79
Merge branch 'main' into jl/use-account-group-metadata-for-sorting-in…
jiexi May 8, 2026
ab23364
Merge branch 'main' into jl/use-account-group-metadata-for-sorting-in…
jiexi May 8, 2026
91f00b1
Merge branch 'main' into jl/use-account-group-metadata-for-sorting-in…
jiexi May 11, 2026
94f075e
fix spec
jiexi May 11, 2026
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
19 changes: 1 addition & 18 deletions app/core/BackgroundBridge/BackgroundBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -1246,24 +1246,7 @@ export class BackgroundBridge extends EventEmitter {
Caip25CaveatType,
);
if (caip25Caveat) {
// TODO: Remove this setTimeout once the core issue in https://github.com/MetaMask/core/pull/8261 is resolved.
// Two issues still exist. One is that the AccountGroup metadata is not available when the wallet is locked.
// The other is that the EVM metadata is not updated by by the time the selectedAccountGroupChange event is fired.
// The former issue mainly affects Extension, not Mobile, but to keep both in sync, we'll keep the setTimeout for now.
// The latter issue is what requires the setTimeout below.
setTimeout(() => {
// We refetch the caip25Caveat to get the latest value in case it
// has changed since we first fetched it.
const caip25CaveatRefetched =
Engine.context.PermissionController.getCaveat(
this.channelIdOrOrigin,
Caip25EndowmentPermissionName,
Caip25CaveatType,
);
if (caip25CaveatRefetched) {
this.notifyCaipAuthorizationChange(caip25CaveatRefetched.value);
}
}, 1000);
this.notifyCaipAuthorizationChange(caip25Caveat.value);
}
} catch (err) {
if (err instanceof PermissionDoesNotExistError) {
Expand Down
38 changes: 22 additions & 16 deletions app/core/BackgroundBridge/BackgroundBridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1725,12 +1725,10 @@ describe('BackgroundBridge', () => {

describe('handleSessionChangedFromSelectedAccountGroupChanges', () => {
beforeEach(() => {
jest.useFakeTimers();
jest.clearAllMocks();
});

afterEach(() => {
jest.useRealTimers();
PermissionController.getCaveat.mockReset();
});

Expand All @@ -1744,7 +1742,6 @@ describe('BackgroundBridge', () => {
});

bridge.handleSessionChangedFromSelectedAccountGroupChanges();
jest.advanceTimersByTime(1000);

expect(bridge.multichainEngine.emit).not.toHaveBeenCalled();
});
Expand All @@ -1757,12 +1754,11 @@ describe('BackgroundBridge', () => {
PermissionController.getCaveat.mockReturnValue(undefined);

bridge.handleSessionChangedFromSelectedAccountGroupChanges();
jest.advanceTimersByTime(1000);

expect(bridge.multichainEngine.emit).not.toHaveBeenCalled();
});

it('calls notifyCaipAuthorizationChange with the refetched caveat value', () => {
it('calls notifyCaipAuthorizationChange with the caveat value', () => {
const url = 'https://www.mock.io';
const bridge = setupBackgroundBridge(url);
const notifySpy = jest.spyOn(bridge, 'notifyCaipAuthorizationChange');
Expand Down Expand Up @@ -1802,9 +1798,7 @@ describe('BackgroundBridge', () => {

jest.advanceTimersByTime(1000);

// The caveat is fetched once synchronously and once again inside the
// setTimeout so that the latest value is used when notifying.
expect(PermissionController.getCaveat).toHaveBeenCalledTimes(2);
expect(PermissionController.getCaveat).toHaveBeenCalledOnce();
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
expect(notifySpy).toHaveBeenCalledWith(mockRefetchedCaveatValue);
expect(notifySpy).not.toHaveBeenCalledWith(mockInitialCaveatValue);
});
Expand All @@ -1825,18 +1819,30 @@ describe('BackgroundBridge', () => {
sessionProperties: {},
};
PermissionController.getCaveat.mockClear();
PermissionController.getCaveat
.mockReturnValueOnce({
type: Caip25CaveatType,
value: mockCaveatValue,
})
.mockReturnValueOnce(undefined);
PermissionController.getCaveat.mockReturnValueOnce({
type: Caip25CaveatType,
value: mockCaveatValue,
});

bridge.handleSessionChangedFromSelectedAccountGroupChanges();

jest.advanceTimersByTime(1000);
expect(PermissionController.getCaveat).toHaveBeenCalledTimes(1);
expect(notifySpy).toHaveBeenCalledWith(mockCaveatValue);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Test name contradicts its actual assertion

Medium Severity

The test is named "does not call notifyCaipAuthorizationChange if the caveat is revoked before the setTimeout fires" but line 1830 asserts expect(notifySpy).toHaveBeenCalledWith(mockCaveatValue), confirming it WAS called. Since the setTimeout was removed and the function now fires synchronously, the assertion body is correct for the new behavior, but the test name claims the opposite — providing false documentation of the contract.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 2341564. Configure here.


it('rethrows unexpected errors from getCaveat', () => {
const url = 'https:www.mock.io';
const bridge = setupBackgroundBridge(url);
const notifySpy = jest.spyOn(bridge, 'notifyCaipAuthorizationChange');

const unexpectedError = new Error('unexpected');
PermissionController.getCaveat.mockImplementation(() => {
throw unexpectedError;
});

expect(PermissionController.getCaveat).toHaveBeenCalledTimes(2);
expect(() =>
bridge.handleSessionChangedFromSelectedAccountGroupChanges(),
).toThrow(unexpectedError);
expect(notifySpy).not.toHaveBeenCalled();
});
});
Expand Down
Loading
Loading