UNPKG

@reown/appkit-controllers

Version:

The full stack toolkit to build onchain app UX.

38 lines 1.35 kB
import { proxy } from 'valtio/vanilla'; import { subscribeKey as subKey } from 'valtio/vanilla/utils'; import { withErrorBoundary } from '../utils/withErrorBoundary.js'; import { OptionsController } from './OptionsController.js'; // -- State --------------------------------------------- // const state = proxy({ message: '', variant: 'info', open: false }); // -- Controller ---------------------------------------- // const controller = { state, subscribeKey(key, callback) { return subKey(state, key, callback); }, open(message, variant) { const { debug } = OptionsController.state; const { code, displayMessage, debugMessage } = message; if (displayMessage && debug) { state.message = displayMessage; state.variant = variant; state.open = true; } if (debugMessage) { // eslint-disable-next-line no-console console.error(typeof debugMessage === 'function' ? debugMessage() : debugMessage, code ? { code } : undefined); } }, close() { state.open = false; state.message = ''; state.variant = 'info'; } }; // Export the controller wrapped with our error boundary export const AlertController = withErrorBoundary(controller); //# sourceMappingURL=AlertController.js.map