@metamask/snaps-sdk
Version:
A library containing the core functionality for building MetaMask Snaps
37 lines • 1.65 kB
JavaScript
import { boolean, nullable, record, string, union } from "@metamask/superstruct";
import { CaipAccountIdStruct, JsonStruct, hasProperty, isObject } from "@metamask/utils";
import { AssetSelectorStateStruct, FileStruct, AccountSelectorStateStruct } from "./handlers/index.mjs";
import { selectiveUnion } from "../internals/index.mjs";
import { RootJSXElementStruct } from "../jsx/index.mjs";
import { ComponentStruct } from "../ui/index.mjs";
/**
* To avoid typing problems with the interface state when manipulating it we
* have to differentiate the state of a form (that will be contained inside the
* root state) and the root state since a key in the root stat can contain
* either the value of an input or a sub-state of a form.
*/
export const StateStruct = union([
AccountSelectorStateStruct,
AssetSelectorStateStruct,
FileStruct,
string(),
boolean(),
CaipAccountIdStruct,
]);
export const FormStateStruct = record(string(), nullable(StateStruct));
export const InterfaceStateStruct = record(string(), union([FormStateStruct, nullable(StateStruct)]));
export const ComponentOrElementStruct = selectiveUnion((value) => {
if (isObject(value) && !hasProperty(value, 'props')) {
return ComponentStruct;
}
return RootJSXElementStruct;
});
export const InterfaceContextStruct = record(string(), JsonStruct);
export var ContentType;
(function (ContentType) {
ContentType["Insight"] = "Insight";
ContentType["Dialog"] = "Dialog";
ContentType["Notification"] = "Notification";
ContentType["HomePage"] = "HomePage";
})(ContentType || (ContentType = {}));
//# sourceMappingURL=interface.mjs.map