UNPKG

@ledgerhq/live-common

Version:
43 lines 1.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.initialSharedActionState = exports.sharedReducer = void 0; const errors_1 = require("@ledgerhq/errors"); /** * Handles SharedTaskEvent that are not handled by specific action * * @param event The event not handled by the specific action * @returns An updated partial SharedActionState, the shared state of the state */ function sharedReducer({ event }) { switch (event.type) { // Handles shared errors coming from a task case "error": { const { error, retrying } = event; const { name, message } = error; if (error instanceof errors_1.LockedDeviceError || error instanceof errors_1.UnresponsiveDeviceError) { // Propagates the error so the consumer can distinguish locked (from error response) and unresponsive error. return { lockedDevice: true, error: { type: "SharedError", name, message, retrying } }; } // Maps any other unhandled error to a SharedError with a specific message return { error: { type: "SharedError", name, message, retrying, }, lockedDevice: false, }; } default: return {}; } } exports.sharedReducer = sharedReducer; // Instantiates the shared initial state exports.initialSharedActionState = { lockedDevice: false, error: null, }; //# sourceMappingURL=core.js.map