Skip to content

Commit

Permalink
Add InputChangeEvent event (#2237)
Browse files Browse the repository at this point in the history
Add an `InputChangeEvent` dynamic UI event to be triggered when an input
in a form has changed. The event may be debounced in the client
implementation and is not triggered instantly.

---------

Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
  • Loading branch information
FrederikBolding and metamaskbot authored Mar 5, 2024
1 parent e56eaf1 commit 041533f
Show file tree
Hide file tree
Showing 18 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/examples/packages/bip32/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "jXB7m0SEAB1g2n8E23KElZVG6cipIB8bk7tMInGTGHE=",
"shasum": "DtqCkGevlAXjYPpejmh0PW3OXNVm4zYi/PHYVu1U+is=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/bip44/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "C9TwxeFksZjLcFlkiee3rwbU075F10AIBrxp2B1Vc3A=",
"shasum": "lzjiI94y3QWSHvxvwWPJ3QiLoVpRoDK9aI0KfiFGaO0=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/cronjobs/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "OltG2NDvqyXlQ63rnYbgs3E04Jkp7xDfoERPYjivJoI=",
"shasum": "+RV6eu1bUJwI64Ia+87nzVt7w5hEvGG+DjvWRd1ds3E=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/dialogs/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "sJFkvJ7Hw/mL7nsUV2zacpbXagg/vbaWrlwx6m3kZv8=",
"shasum": "HrY2Q07bwZLKbP7UYbLU2fVMVMjGWgwhmlTGUgEQNMo=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/ethers-js/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "BrtFgMRty4l3lFai0ZRzvsOMi+GD35wU2L8e4rC4Pzs=",
"shasum": "75eFrFWMaWVoN+SB0Dx6zuMuW6wkW9TAyfTJ2pmkXxU=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/get-entropy/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "L5ZAAUcWucgTLY16I6pX7rzkhW/Am6eW8/6AtHQikuQ=",
"shasum": "Bk/N5TeC923rK569D6o7eEusaTZ4ENeqakMXPcAR/tY=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/home-page/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "c4TP0ESTAYG4AVILxhjNk8PfPNRZA+m1W+IF+8GIFiM=",
"shasum": "g97yy0ykpflNFVzBfFablH4DsLNr+eZKCEoDbLQpmgY=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/images/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "KZD5RWnfjvokfDoLsN3NDVZwmJ5VuhiBC9N8gOpLe48=",
"shasum": "AI+NqKyNjL6pvJv2CapYwFbHSm9EoTINoXl/ZLnZP0E=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "HAaFlDfI6+0VX5v5GtYliD2l8PRw74OgSidyU31hdYI=",
"shasum": "PPCmPNzFzjg4596Rs/LnTuHAaJq3oAqv+XMSjpTjq0w=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "2ZO74x0nI5E7je1hVrWFRbsACAuN5XAu6NSyiSnMZ5s=",
"shasum": "Af0qYFlaZB9ublbw/EdKs/zKfWsSXAG2Mi/XTRmAHOU=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "qliiMjjWRT7RkwORjS15Uhyfo5AJo3gCUIC+/z4qB5Q=",
"shasum": "DSVf2LLECYZqXVe8EInjs5uZ7Ey+UA/ANfbe+XYlCOs=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/manage-state/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "nPzGIoWTNhgD9GP8yM1jg8gQOR7LdDCXbfCiiQY6u6E=",
"shasum": "D1RxlgTDi5cCPn6Cf2hO2WzvBnn56ipuSGf6Z96HhIE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "JaGuDtOA+RSa+rMvlvVgFG/oIy7o1BafN6WEIetbKqY=",
"shasum": "HcZ87SrdWWI7kPX5pId8h8wNMgltlMXqXjGnG+7nN8k=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "z6FH7b1/dv0jY5p7EQ2TclzPjDAb3LGdGybVCK6N3AQ=",
"shasum": "yisG8u7h5r9IBpGfapBj8RM2wr5YQh5QA/3cjrBCklU=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "D9w45JEFlH+OlHKwOFPtNjBGX0d6rZPXMDnndk+zs0k=",
"shasum": "sV8xD5zSmYjW5L6L0cY7kZS3UyzlScEyk13lSkYCRhA=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ describe('assertIsOnUserInputRequestArguments', () => {
value: { foo: 'bar' },
},
},
{
id: 'foo',
event: {
type: UserInputEventType.InputChangeEvent,
name: 'input',
value: 'bar',
},
},
])('does not throw for a valid user input param object', (value) => {
expect(() => assertIsOnUserInputRequestArguments(value)).not.toThrow();
});
Expand Down
3 changes: 2 additions & 1 deletion packages/snaps-sdk/src/types/handlers/user-input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { UserInputEventType } from './user-input';

describe('UserInputEventType', () => {
it('has the correct values', () => {
expect(Object.values(UserInputEventType)).toHaveLength(2);
expect(Object.values(UserInputEventType)).toHaveLength(3);
expect(UserInputEventType.ButtonClickEvent).toBe('ButtonClickEvent');
expect(UserInputEventType.FormSubmitEvent).toBe('FormSubmitEvent');
expect(UserInputEventType.InputChangeEvent).toBe('InputChangeEvent');
});
});
15 changes: 14 additions & 1 deletion packages/snaps-sdk/src/types/handlers/user-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import {

/**
* The type of user input event fired.
* Currently only two events are supported:
* Currently only three events are supported:
*
* - `ButtonClickEvent` - A button has been clicked in the UI.
* - `FormSubmitEvent` - A Form has been submitted in the UI.
* - `InputChangeEvent` - The value of an input field has changed in the UI.
*/
export enum UserInputEventType {
ButtonClickEvent = 'ButtonClickEvent',
FormSubmitEvent = 'FormSubmitEvent',
InputChangeEvent = 'InputChangeEvent',
}

export const GenericEventStruct = object({
Expand All @@ -30,6 +32,7 @@ export const ButtonClickEventStruct = assign(
GenericEventStruct,
object({
type: literal(UserInputEventType.ButtonClickEvent),
name: optional(string()),
}),
);

Expand All @@ -42,9 +45,19 @@ export const FormSubmitEventStruct = assign(
}),
);

export const InputChangeEventStruct = assign(
GenericEventStruct,
object({
type: literal(UserInputEventType.InputChangeEvent),
name: string(),
value: string(),
}),
);

export const UserInputEventStruct = union([
ButtonClickEventStruct,
FormSubmitEventStruct,
InputChangeEventStruct,
]);

/**
Expand Down

0 comments on commit 041533f

Please sign in to comment.