Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

feat: add display confirmation option to AccountCreatedEvent #307

Merged
merged 5 commits into from
May 17, 2024
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ node_modules/
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# IntelliJ
.idea/
18 changes: 18 additions & 0 deletions src/internal/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ describe('events', () => {

expect(is(event, AccountCreatedEventStruct)).toBe(false);
});

it('should be a valid accountCreated event with displayConfirmation', () => {
k-g-j marked this conversation as resolved.
Show resolved Hide resolved
const event = {
method: KeyringEvent.AccountCreated,
params: {
account: {
id: '11027d05-12f8-4ec0-b03f-151d86a8089e',
address: '0x0123',
methods: [],
options: {},
type: EthAccountType.Eoa,
},
displayConfirmation: true,
},
};

expect(is(event, AccountCreatedEventStruct)).toBe(true);
});
});

describe('AccountUpdatedEventStruct', () => {
Expand Down
9 changes: 8 additions & 1 deletion src/internal/events.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { JsonStruct } from '@metamask/utils';
import { literal, object } from 'superstruct';
k-g-j marked this conversation as resolved.
Show resolved Hide resolved
import { boolean, literal, object } from 'superstruct';

import { KeyringAccountStruct } from '../api';
import { KeyringEvent } from '../events';
import { exactOptional } from '../superstruct';
import { UuidStruct } from '../utils';

export const AccountCreatedEventStruct = object({
Expand All @@ -12,6 +13,12 @@ export const AccountCreatedEventStruct = object({
* New account object.
*/
account: KeyringAccountStruct,

/**
* Instructs MetaMask to display the add account confirmation dialog in the UI.
* **Note:** This is not guaranteed to be honored by the MetaMask client.
*/
displayConfirmation: exactOptional(boolean()),
}),
});

Expand Down
Loading