@metamask/snaps-sdk
Version:
A library containing the core functionality for building MetaMask Snaps
59 lines • 2.29 kB
JavaScript
import { number, assign, literal, nullable, object, optional, record, string, union, boolean } from "@metamask/superstruct";
import { CaipAssetTypeStruct } from "@metamask/utils";
/**
* The type of user input event fired.
* 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.
* - `FileUploadEvent` - A file has been uploaded in the UI.
*/
export var UserInputEventType;
(function (UserInputEventType) {
UserInputEventType["ButtonClickEvent"] = "ButtonClickEvent";
UserInputEventType["FormSubmitEvent"] = "FormSubmitEvent";
UserInputEventType["InputChangeEvent"] = "InputChangeEvent";
UserInputEventType["FileUploadEvent"] = "FileUploadEvent";
})(UserInputEventType || (UserInputEventType = {}));
export const GenericEventStruct = object({
type: string(),
name: optional(string()),
});
export const ButtonClickEventStruct = assign(GenericEventStruct, object({
type: literal(UserInputEventType.ButtonClickEvent),
name: optional(string()),
}));
export const FileStruct = object({
name: string(),
size: number(),
contentType: string(),
contents: string(),
});
export const AssetSelectorStateStruct = object({
asset: CaipAssetTypeStruct,
name: string(),
symbol: string(),
});
export const FormSubmitEventStruct = assign(GenericEventStruct, object({
type: literal(UserInputEventType.FormSubmitEvent),
value: record(string(), nullable(union([string(), FileStruct, boolean(), AssetSelectorStateStruct]))),
name: string(),
}));
export const InputChangeEventStruct = assign(GenericEventStruct, object({
type: literal(UserInputEventType.InputChangeEvent),
name: string(),
value: union([string(), boolean(), AssetSelectorStateStruct]),
}));
export const FileUploadEventStruct = assign(GenericEventStruct, object({
type: literal(UserInputEventType.FileUploadEvent),
name: string(),
file: nullable(FileStruct),
}));
export const UserInputEventStruct = union([
ButtonClickEventStruct,
FormSubmitEventStruct,
InputChangeEventStruct,
FileUploadEventStruct,
]);
//# sourceMappingURL=user-input.mjs.map