@metamask/lifecycle-hooks-example-snap
Version:
MetaMask example snap demonstrating the use of the `onStart`, `onInstall`, and `onUpdate` lifecycle hooks
1 lines • 1.94 kB
JavaScript
(()=>{var e={d:(n,t)=>{for(var a in t)e.o(t,a)&&!e.o(n,a)&&Object.defineProperty(n,a,{enumerable:!0,get:t[a]})},o:(e,n)=>Object.prototype.hasOwnProperty.call(e,n),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},n={};(()=>{"use strict";function t(e,n,t){if("string"==typeof e)throw new Error(`An HTML element ("${String(e)}") was used in a Snap component, which is not supported by Snaps UI. Please use one of the supported Snap components.`);if(!e)throw new Error("A JSX fragment was used in a Snap component, which is not supported by Snaps UI. Please use one of the supported Snap components.");return e({...n,key:t})}function a(e){return Object.fromEntries(Object.entries(e).filter((([,e])=>void 0!==e)))}function s(e){return n=>{const{key:t=null,...s}=n;return{type:e,props:a(s),key:t}}}e.r(n),e.d(n,{onActive:()=>c,onInactive:()=>i,onInstall:()=>p,onStart:()=>l,onUpdate:()=>d});const o=s("Box"),r=s("Text"),l=async()=>await snap.request({method:"snap_dialog",params:{type:"alert",content:t(o,{children:t(r,{children:'The client was started successfully, and the "onStart" handler was called.'})})}}),p=async()=>await snap.request({method:"snap_dialog",params:{type:"alert",content:t(o,{children:t(r,{children:'The Snap was installed successfully, and the "onInstall" handler was called.'})})}}),d=async()=>await snap.request({method:"snap_dialog",params:{type:"alert",content:t(o,{children:t(r,{children:'The Snap was updated successfully, and the "onUpdate" handler was called.'})})}}),c=async()=>await snap.request({method:"snap_notify",params:{type:"inApp",message:'The client was activated, and the "onActive" handler was called.'}}),i=async()=>await snap.request({method:"snap_notify",params:{type:"inApp",message:'The client was deactivated, and the "onInactive" handler was called.'}})})(),module.exports=n})();