@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
35 lines • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.initialState = void 0;
exports.getDeviceInfoAction = getDeviceInfoAction;
const operators_1 = require("rxjs/operators");
const core_1 = require("./core");
const getDeviceInfo_1 = require("../tasks/getDeviceInfo");
exports.initialState = {
deviceInfo: null,
...core_1.initialSharedActionState,
};
function getDeviceInfoAction({ deviceId, deviceName, }) {
// TODO: to decide: should we push an event if the state is not changing?
// For ex: when the device is locked with 0x5515: an event with lockedDevice: true is pushed for each retry
return (0, getDeviceInfo_1.getDeviceInfoTask)({ deviceId, deviceName }).pipe((0, operators_1.scan)((currentState, event) => {
switch (event.type) {
case "taskError":
return { ...exports.initialState, error: { type: event.error } };
case "data":
return {
...currentState,
error: null,
deviceInfo: event.deviceInfo,
};
case "error":
return {
...currentState,
...(0, core_1.sharedReducer)({
event,
}),
};
}
}, exports.initialState));
}
//# sourceMappingURL=getDeviceInfo.js.map