@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
39 lines • 1.44 kB
JavaScript
import { LockedDeviceError, UnresponsiveDeviceError } from "@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
*/
export 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 LockedDeviceError ||
error instanceof 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 {};
}
}
// Instantiates the shared initial state
export const initialSharedActionState = {
lockedDevice: false,
error: null,
};
//# sourceMappingURL=core.js.map