Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions packages/base-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Bump `@metamask/utils` from `^11.4.2` to `^11.8.0` ([#6588](https://github.com/MetaMask/core/pull/6588))
- In experimental `next` export, rename `anonymous` metadata property to `includeInDebugSnapshot` ([#6593](https://github.com/MetaMask/core/pull/6593))
- In experimental `next` export, make `includeInStateLogs` and `usedInUi` metadata properties required ([#6593](https://github.com/MetaMask/core/pull/6593))

## [8.3.0]

Expand Down
83 changes: 42 additions & 41 deletions packages/base-controller/src/next/BaseController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export type CountControllerEvent = ControllerStateChangeEvent<

export const countControllerStateMetadata = {
count: {
anonymous: true,
includeInDebugSnapshot: true,
includeInStateLogs: true,
persist: true,
usedInUi: true,
Expand Down Expand Up @@ -109,7 +109,7 @@ type MessagesControllerEvent = ControllerStateChangeEvent<

const messagesControllerStateMetadata = {
messages: {
anonymous: true,
includeInDebugSnapshot: true,
includeInStateLogs: true,
persist: true,
usedInUi: true,
Expand Down Expand Up @@ -609,7 +609,7 @@ describe('BaseController', () => {

const visitorControllerStateMetadata = {
visitors: {
anonymous: true,
includeInDebugSnapshot: true,
includeInStateLogs: true,
persist: true,
usedInUi: true,
Expand Down Expand Up @@ -679,7 +679,7 @@ describe('BaseController', () => {

const visitorOverflowControllerMetadata = {
maxVisitors: {
anonymous: true,
includeInDebugSnapshot: true,
includeInStateLogs: true,
persist: false,
usedInUi: true,
Expand Down Expand Up @@ -794,7 +794,7 @@ describe('getAnonymizedState', () => {
{ count: 1 },
{
count: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
Expand All @@ -814,25 +814,25 @@ describe('getAnonymizedState', () => {
},
{
password: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
},
privateKey: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
},
network: {
anonymous: true,
includeInDebugSnapshot: true,
includeInStateLogs: false,
persist: false,
usedInUi: false,
},
tokens: {
anonymous: true,
includeInDebugSnapshot: true,
includeInStateLogs: false,
persist: false,
usedInUi: false,
Expand All @@ -856,7 +856,7 @@ describe('getAnonymizedState', () => {
},
{
transactionHash: {
anonymous: anonymizeTransactionHash,
includeInDebugSnapshot: anonymizeTransactionHash,
includeInStateLogs: false,
persist: false,
usedInUi: false,
Expand All @@ -881,7 +881,7 @@ describe('getAnonymizedState', () => {
},
{
txMeta: {
anonymous: anonymizeTxMeta,
includeInDebugSnapshot: anonymizeTxMeta,
includeInStateLogs: false,
persist: false,
usedInUi: false,
Expand Down Expand Up @@ -921,7 +921,7 @@ describe('getAnonymizedState', () => {
},
{
txMeta: {
anonymous: anonymizeTxMeta,
includeInDebugSnapshot: anonymizeTxMeta,
includeInStateLogs: false,
persist: false,
usedInUi: false,
Expand All @@ -941,7 +941,7 @@ describe('getAnonymizedState', () => {
},
{
count: {
anonymous: (count) => Number(count),
includeInDebugSnapshot: (count) => Number(count),
includeInStateLogs: false,
persist: false,
usedInUi: false,
Expand All @@ -963,13 +963,13 @@ describe('getAnonymizedState', () => {
// @ts-expect-error Intentionally testing invalid state
{
privateKey: {
anonymous: true,
includeInDebugSnapshot: true,
includeInStateLogs: true,
persist: true,
usedInUi: true,
},
network: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
Expand Down Expand Up @@ -999,7 +999,7 @@ describe('getPersistentState', () => {
{ count: 1 },
{
count: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
Expand All @@ -1019,25 +1019,25 @@ describe('getPersistentState', () => {
},
{
password: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: true,
usedInUi: false,
},
privateKey: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: true,
usedInUi: false,
},
network: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
},
tokens: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
Expand All @@ -1061,7 +1061,7 @@ describe('getPersistentState', () => {
},
{
transactionHash: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: normalizeTransacitonHash,
usedInUi: false,
Expand All @@ -1086,7 +1086,7 @@ describe('getPersistentState', () => {
},
{
txMeta: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: getPersistentTxMeta,
usedInUi: false,
Expand Down Expand Up @@ -1126,7 +1126,7 @@ describe('getPersistentState', () => {
},
{
txMeta: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: getPersistentTxMeta,
usedInUi: false,
Expand All @@ -1146,7 +1146,7 @@ describe('getPersistentState', () => {
},
{
count: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: (count) => Number(count),
usedInUi: false,
Expand All @@ -1168,13 +1168,13 @@ describe('getPersistentState', () => {
// @ts-expect-error Intentionally testing invalid state
{
privateKey: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: true,
usedInUi: false,
},
network: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: true,
Expand All @@ -1200,20 +1200,21 @@ describe('deriveStateFromMetadata', () => {
{ count: 1 },
{
count: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
// usedInUi is not set
usedInUi: false,
},
},
'usedInUi',
// @ts-expect-error Intentionally passing in fake unset property
'unset',
);

expect(derivedState).toStrictEqual({});
});

describe.each([
'anonymous',
'includeInDebugSnapshot',
'includeInStateLogs',
'persist',
'usedInUi',
Expand All @@ -1227,7 +1228,7 @@ describe('deriveStateFromMetadata', () => {
{ count: 1 },
{
count: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
Expand All @@ -1250,28 +1251,28 @@ describe('deriveStateFromMetadata', () => {
},
{
password: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
[property]: true,
},
privateKey: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
[property]: true,
},
network: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
[property]: false,
},
tokens: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
Expand Down Expand Up @@ -1299,7 +1300,7 @@ describe('deriveStateFromMetadata', () => {
},
{
transactionHash: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
Expand All @@ -1326,7 +1327,7 @@ describe('deriveStateFromMetadata', () => {
},
{
txMeta: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
Expand Down Expand Up @@ -1368,7 +1369,7 @@ describe('deriveStateFromMetadata', () => {
},
{
txMeta: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
Expand All @@ -1390,7 +1391,7 @@ describe('deriveStateFromMetadata', () => {
},
{
count: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
Expand All @@ -1415,14 +1416,14 @@ describe('deriveStateFromMetadata', () => {
// @ts-expect-error Intentionally testing invalid state
{
privateKey: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
[property]: true,
},
network: {
anonymous: false,
includeInDebugSnapshot: false,
includeInStateLogs: false,
persist: false,
usedInUi: false,
Expand Down
8 changes: 4 additions & 4 deletions packages/base-controller/src/next/BaseController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export type StatePropertyMetadata<ControllerState extends Json> = {
* Set this to false if the state may contain personally identifiable information, or if it's
* too large to include in a debug snapshot.
*/
anonymous: boolean | StateDeriver<ControllerState>;
includeInDebugSnapshot: boolean | StateDeriver<ControllerState>;
/**
* Indicates whether this property should be included in state logs.
*
Expand All @@ -78,7 +78,7 @@ export type StatePropertyMetadata<ControllerState extends Json> = {
* diagnosing errors (e.g. transaction hashes, addresses), but we still attempt to limit the
* data we expose to what is most useful for helping users.
*/
includeInStateLogs?: boolean | StateDeriver<ControllerState>;
includeInStateLogs: boolean | StateDeriver<ControllerState>;
/**
* Indicates whether this property should be persisted.
*
Expand All @@ -98,7 +98,7 @@ export type StatePropertyMetadata<ControllerState extends Json> = {
* Note that we disallow the use of a state derivation function here to preserve type information
* for the UI (the state deriver type always returns `Json`).
*/
usedInUi?: boolean;
usedInUi: boolean;
};

/**
Expand Down Expand Up @@ -377,7 +377,7 @@ export function getAnonymizedState<ControllerState extends StateConstraint>(
state: ControllerState,
metadata: StateMetadata<ControllerState>,
): Record<keyof ControllerState, Json> {
return deriveStateFromMetadata(state, metadata, 'anonymous');
return deriveStateFromMetadata(state, metadata, 'includeInDebugSnapshot');
}

/**
Expand Down
Loading