@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
58 lines • 1.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.serviceStatusMachine = void 0;
const xstate_1 = require("xstate");
const initialState = {
incidents: [],
error: null,
lastUpdateTime: null,
isLoading: false,
context: { tickers: [] },
};
exports.serviceStatusMachine = (0, xstate_1.createMachine)({
id: "serviceStatus",
initial: "updating",
context: initialState,
states: {
idle: {
after: {
AUTO_UPDATE_DELAY: {
target: "updating",
},
},
on: {
UPDATE_DATA: {
target: "updating",
actions: (0, xstate_1.assign)({
isLoading: true,
error: null,
}),
},
},
},
updating: {
invoke: {
src: "fetchData",
onDone: {
target: "idle",
actions: (0, xstate_1.assign)(({ event }) => {
const { incidents, updateTime } = event.output;
return {
incidents,
lastUpdateTime: updateTime,
isLoading: false,
error: null,
};
}),
},
onError: {
target: "idle",
actions: (0, xstate_1.assign)(({ event }) => ({
error: event.error,
})),
},
},
},
},
});
//# sourceMappingURL=machine.js.map