Skip to content

Commit 5d74648

Browse files
authored
feat: Add new metadata to gator-permissions-controller (#6552)
## Explanation The new metadata properties `includeInStateLogs` and `usedInUi` have been added to the `GatorpermissionsController`. ## References Fixes #6518 ## 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 b0fd793 commit 5d74648

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

packages/gator-permissions-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` ([#6552](https://github.com/MetaMask/core/pull/6552))
13+
1014
## [0.1.0]
1115

1216
### Added

packages/gator-permissions-controller/src/GatorPermissionContoller.test.ts

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { AccountSigner } from '@metamask/7715-permission-types';
2-
import { Messenger } from '@metamask/base-controller';
2+
import { Messenger, deriveStateFromMetadata } from '@metamask/base-controller';
33
import type { HandleSnapRequest, HasSnap } from '@metamask/snaps-controllers';
44
import type { SnapId } from '@metamask/snaps-sdk';
55
import type { Hex } from '@metamask/utils';
@@ -379,6 +379,80 @@ describe('GatorPermissionsController', () => {
379379
expect(controller.state.isGatorPermissionsEnabled).toBe(true);
380380
});
381381
});
382+
383+
describe('metadata', () => {
384+
it('includes expected state in debug snapshots', () => {
385+
const controller = new GatorPermissionsController({
386+
messenger: getMessenger(),
387+
});
388+
389+
expect(
390+
deriveStateFromMetadata(
391+
controller.state,
392+
controller.metadata,
393+
'anonymous',
394+
),
395+
).toMatchInlineSnapshot(`Object {}`);
396+
});
397+
398+
it('includes expected state in state logs', () => {
399+
const controller = new GatorPermissionsController({
400+
messenger: getMessenger(),
401+
});
402+
403+
expect(
404+
deriveStateFromMetadata(
405+
controller.state,
406+
controller.metadata,
407+
'includeInStateLogs',
408+
),
409+
).toMatchInlineSnapshot(`
410+
Object {
411+
"gatorPermissionsMapSerialized": "{\\"native-token-stream\\":{},\\"native-token-periodic\\":{},\\"erc20-token-stream\\":{},\\"erc20-token-periodic\\":{},\\"other\\":{}}",
412+
"gatorPermissionsProviderSnapId": "@metamask/gator-permissions-snap",
413+
"isFetchingGatorPermissions": false,
414+
"isGatorPermissionsEnabled": false,
415+
}
416+
`);
417+
});
418+
419+
it('persists expected state', () => {
420+
const controller = new GatorPermissionsController({
421+
messenger: getMessenger(),
422+
});
423+
424+
expect(
425+
deriveStateFromMetadata(
426+
controller.state,
427+
controller.metadata,
428+
'persist',
429+
),
430+
).toMatchInlineSnapshot(`
431+
Object {
432+
"gatorPermissionsMapSerialized": "{\\"native-token-stream\\":{},\\"native-token-periodic\\":{},\\"erc20-token-stream\\":{},\\"erc20-token-periodic\\":{},\\"other\\":{}}",
433+
"isGatorPermissionsEnabled": false,
434+
}
435+
`);
436+
});
437+
438+
it('exposes expected state to UI', () => {
439+
const controller = new GatorPermissionsController({
440+
messenger: getMessenger(),
441+
});
442+
443+
expect(
444+
deriveStateFromMetadata(
445+
controller.state,
446+
controller.metadata,
447+
'usedInUi',
448+
),
449+
).toMatchInlineSnapshot(`
450+
Object {
451+
"gatorPermissionsMapSerialized": "{\\"native-token-stream\\":{},\\"native-token-periodic\\":{},\\"erc20-token-stream\\":{},\\"erc20-token-periodic\\":{},\\"other\\":{}}",
452+
}
453+
`);
454+
});
455+
});
382456
});
383457

384458
/**

packages/gator-permissions-controller/src/GatorPermissionsController.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,28 @@ export type GatorPermissionsControllerState = {
7676

7777
const gatorPermissionsControllerMetadata = {
7878
isGatorPermissionsEnabled: {
79+
includeInStateLogs: true,
7980
persist: true,
8081
anonymous: false,
82+
usedInUi: false,
8183
},
8284
gatorPermissionsMapSerialized: {
85+
includeInStateLogs: true,
8386
persist: true,
8487
anonymous: false,
88+
usedInUi: true,
8589
},
8690
isFetchingGatorPermissions: {
91+
includeInStateLogs: true,
8792
persist: false,
8893
anonymous: false,
94+
usedInUi: false,
8995
},
9096
gatorPermissionsProviderSnapId: {
97+
includeInStateLogs: true,
9198
persist: false,
9299
anonymous: false,
100+
usedInUi: false,
93101
},
94102
} satisfies StateMetadata<GatorPermissionsControllerState>;
95103

0 commit comments

Comments
 (0)