Skip to content

Commit cb132de

Browse files
authored
feat: Add new metadata to confirmation controllers (#6473)
## Explanation The new metadata properties `includeInStateLogs` and `usedInUi` have been added to all controllers maintained by the confirmations team. ## References Relates to #6443 ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [x] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes
1 parent 544be71 commit cb132de

30 files changed

+1008
-28
lines changed

packages/address-book-controller/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add two new controller state metadata properties: `includeInStateLogs` and `usedInUi` ([#6473](https://github.com/MetaMask/core/pull/6473))
13+
1014
### Changed
1115

1216
- Bump `@metamask/base-controller` from `^8.0.1` to `^8.3.0` ([#6284](https://github.com/MetaMask/core/pull/6284), [#6355](https://github.com/MetaMask/core/pull/6355), [#6465](https://github.com/MetaMask/core/pull/6465))

packages/address-book-controller/src/AddressBookController.test.ts

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Messenger } from '@metamask/base-controller';
1+
import { Messenger, deriveStateFromMetadata } from '@metamask/base-controller';
22
import { toHex } from '@metamask/controller-utils';
33
import type { Hex } from '@metamask/utils';
44

@@ -618,4 +618,66 @@ describe('AddressBookController', () => {
618618
expect(chain2Contacts).toHaveLength(2);
619619
expect(chain137Contacts).toHaveLength(1);
620620
});
621+
622+
describe('metadata', () => {
623+
it('includes expected state in debug snapshots', () => {
624+
const { controller } = arrangeMocks();
625+
626+
expect(
627+
deriveStateFromMetadata(
628+
controller.state,
629+
controller.metadata,
630+
'anonymous',
631+
),
632+
).toMatchInlineSnapshot(`Object {}`);
633+
});
634+
635+
it('includes expected state in state logs', () => {
636+
const { controller } = arrangeMocks();
637+
638+
expect(
639+
deriveStateFromMetadata(
640+
controller.state,
641+
controller.metadata,
642+
'includeInStateLogs',
643+
),
644+
).toMatchInlineSnapshot(`
645+
Object {
646+
"addressBook": Object {},
647+
}
648+
`);
649+
});
650+
651+
it('persists expected state', () => {
652+
const { controller } = arrangeMocks();
653+
654+
expect(
655+
deriveStateFromMetadata(
656+
controller.state,
657+
controller.metadata,
658+
'persist',
659+
),
660+
).toMatchInlineSnapshot(`
661+
Object {
662+
"addressBook": Object {},
663+
}
664+
`);
665+
});
666+
667+
it('exposes expected state to UI', () => {
668+
const { controller } = arrangeMocks();
669+
670+
expect(
671+
deriveStateFromMetadata(
672+
controller.state,
673+
controller.metadata,
674+
'usedInUi',
675+
),
676+
).toMatchInlineSnapshot(`
677+
Object {
678+
"addressBook": Object {},
679+
}
680+
`);
681+
});
682+
});
621683
});

packages/address-book-controller/src/AddressBookController.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,12 @@ export type AddressBookControllerEvents =
147147
| AddressBookControllerContactDeletedEvent;
148148

149149
const addressBookControllerMetadata = {
150-
addressBook: { persist: true, anonymous: false },
150+
addressBook: {
151+
includeInStateLogs: true,
152+
persist: true,
153+
anonymous: false,
154+
usedInUi: true,
155+
},
151156
};
152157

153158
/**

packages/approval-controller/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add two new controller state metadata properties: `includeInStateLogs` and `usedInUi` ([#6473](https://github.com/MetaMask/core/pull/6473))
13+
1014
### Changed
1115

1216
- Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))

packages/approval-controller/src/ApprovalController.test.ts

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable jest/expect-expect */
22

3-
import { Messenger } from '@metamask/base-controller';
3+
import { deriveStateFromMetadata, Messenger } from '@metamask/base-controller';
44
import { errorCodes, JsonRpcError } from '@metamask/rpc-errors';
55
import { nanoid } from 'nanoid';
66

@@ -1712,4 +1712,62 @@ describe('approval controller', () => {
17121712
});
17131713
});
17141714
});
1715+
1716+
describe('metadata', () => {
1717+
it('includes expected state in debug snapshots', () => {
1718+
expect(
1719+
deriveStateFromMetadata(
1720+
approvalController.state,
1721+
approvalController.metadata,
1722+
'anonymous',
1723+
),
1724+
).toMatchInlineSnapshot(`
1725+
Object {
1726+
"pendingApprovals": Object {},
1727+
}
1728+
`);
1729+
});
1730+
1731+
it('includes expected state in state logs', () => {
1732+
expect(
1733+
deriveStateFromMetadata(
1734+
approvalController.state,
1735+
approvalController.metadata,
1736+
'includeInStateLogs',
1737+
),
1738+
).toMatchInlineSnapshot(`
1739+
Object {
1740+
"approvalFlows": Array [],
1741+
"pendingApprovalCount": 0,
1742+
"pendingApprovals": Object {},
1743+
}
1744+
`);
1745+
});
1746+
1747+
it('persists expected state', () => {
1748+
expect(
1749+
deriveStateFromMetadata(
1750+
approvalController.state,
1751+
approvalController.metadata,
1752+
'persist',
1753+
),
1754+
).toMatchInlineSnapshot(`Object {}`);
1755+
});
1756+
1757+
it('exposes expected state to UI', () => {
1758+
expect(
1759+
deriveStateFromMetadata(
1760+
approvalController.state,
1761+
approvalController.metadata,
1762+
'usedInUi',
1763+
),
1764+
).toMatchInlineSnapshot(`
1765+
Object {
1766+
"approvalFlows": Array [],
1767+
"pendingApprovalCount": 0,
1768+
"pendingApprovals": Object {},
1769+
}
1770+
`);
1771+
});
1772+
});
17151773
});

packages/approval-controller/src/ApprovalController.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,24 @@ export const APPROVAL_TYPE_RESULT_SUCCESS = 'result_success';
2727
const controllerName = 'ApprovalController';
2828

2929
const stateMetadata = {
30-
pendingApprovals: { persist: false, anonymous: true },
31-
pendingApprovalCount: { persist: false, anonymous: false },
32-
approvalFlows: { persist: false, anonymous: false },
30+
pendingApprovals: {
31+
includeInStateLogs: true,
32+
persist: false,
33+
anonymous: true,
34+
usedInUi: true,
35+
},
36+
pendingApprovalCount: {
37+
includeInStateLogs: true,
38+
persist: false,
39+
anonymous: false,
40+
usedInUi: true,
41+
},
42+
approvalFlows: {
43+
includeInStateLogs: true,
44+
persist: false,
45+
anonymous: false,
46+
usedInUi: true,
47+
},
3348
};
3449

3550
const getAlreadyPendingMessage = (origin: string, type: string) =>

packages/ens-controller/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add two new controller state metadata properties: `includeInStateLogs` and `usedInUi` ([#6473](https://github.com/MetaMask/core/pull/6473))
13+
1014
### Changed
1115

1216
- Bump `@metamask/base-controller` from `^8.0.1` to `^8.3.0` ([#6284](https://github.com/MetaMask/core/pull/6284), [#6355](https://github.com/MetaMask/core/pull/6355), [#6465](https://github.com/MetaMask/core/pull/6465))

0 commit comments

Comments
 (0)