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

Commit

Permalink
feat: add display confirmation option to AccountCreatedEvent (#307)
Browse files Browse the repository at this point in the history
* feat: added optional 'displayConfirmation' to AccountCreatedEventStruct

* fix: added '.idea' folder to gitignore

* feat: changed from 'optional' to 'exactOptional' type and updated jsdoc comment

* feat: update KeyringAccountStruct to match other definitions

Co-authored-by: Daniel Rocha <[email protected]>

* feat: put markdown bolding for JSDOC in 'displayConfirmation'

---------

Co-authored-by: Daniel Rocha <[email protected]>
  • Loading branch information
k-g-j and danroc authored May 17, 2024
1 parent f4027b0 commit add765b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
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', () => {
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';
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

0 comments on commit add765b

Please sign in to comment.