Skip to content

refactor!: remove InternalAccount.metadata.snap.{name,enabled} #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
37 changes: 1 addition & 36 deletions packages/keyring-internal-api/src/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('InternalAccount', () => {
);
});

it('should contain snap name, id and enabled if the snap metadata exists', () => {
it('should contain snap id if the snap metadata exists', () => {
const account: InternalAccount = {
id: '606a7759-b0fb-48e4-9874-bab62ff8e7eb',
address: '0x000',
Expand All @@ -138,45 +138,10 @@ describe('InternalAccount', () => {
importTime: 1713153716,
snap: {
id: 'test-snap',
enabled: true,
name: 'Test Snap',
},
},
};

expect(() => assert(account, InternalAccountStruct)).not.toThrow();
});

it.each([['name', 'enabled', 'id']])(
'should throw if snap.%s is not set',
(key: string) => {
const account: InternalAccount = {
id: '606a7759-b0fb-48e4-9874-bab62ff8e7eb',
address: '0x000',
options: {},
methods: [],
scopes: ['eip155:0'],
type: 'eip155:eoa',
metadata: {
keyring: {
type: 'Test Keyring',
},
name: 'Account 1',
importTime: 1713153716,
snap: {
id: 'test-snap',
enabled: true,
name: 'Test Snap',
},
},
};

// On `InternalAccount` the `metadata.snap` is optional, hence the `?.` here.
delete account.metadata.snap?.[key as keyof typeof account.metadata.snap];

const regex = new RegExp(`At path: metadata.snap.${key}`, 'u');

expect(() => assert(account, InternalAccountStruct)).toThrow(regex);
},
);
});
4 changes: 1 addition & 3 deletions packages/keyring-internal-api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@metamask/keyring-api';
import { exactOptional, object } from '@metamask/keyring-utils';
import type { Infer, Struct } from '@metamask/superstruct';
import { boolean, string, number } from '@metamask/superstruct';
import { string, number } from '@metamask/superstruct';

export type InternalAccountType =
| EthAccountType
Expand All @@ -29,8 +29,6 @@ export const InternalAccountMetadataStruct = object({
snap: exactOptional(
object({
id: string(),
enabled: boolean(),
name: string(),
}),
),
lastSelected: exactOptional(number()),
Expand Down
4 changes: 1 addition & 3 deletions packages/keyring-snap-bridge/src/SnapKeyring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2045,8 +2045,6 @@ describe('SnapKeyring', () => {
it('returns the list of accounts', async () => {
const snapMetadata = {
id: snapId,
name: 'Snap Name',
enabled: true,
};
const snapObject = {
id: snapId,
Expand Down Expand Up @@ -2095,7 +2093,7 @@ describe('SnapKeyring', () => {
metadata: {
name: '',
importTime: 0,
snap: { id: snapId, name: 'snap-name', enabled: true },
snap: { id: snapId },
keyring: { type: 'Snap Keyring' },
},
},
Expand Down
4 changes: 1 addition & 3 deletions packages/keyring-snap-bridge/src/SnapKeyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1395,9 +1395,7 @@ export class SnapKeyring extends EventEmitter {
snapId: SnapId,
): InternalAccount['metadata']['snap'] | undefined {
const snap = this.#getSnap(snapId);
return snap
? { id: snapId, name: snap.manifest.proposedName, enabled: snap.enabled }
: undefined;
return snap ? { id: snapId } : undefined;
}

/**
Expand Down
Loading