UNPKG

@ledgerhq/live-common

Version:
48 lines 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useSendFlowOperationState = useSendFlowOperationState; const react_1 = require("react"); function operationReducer(state, action) { switch (action.type) { case "SET_OPERATION": return { optimisticOperation: action.operation, transactionError: null, signed: true }; case "SET_ERROR": return { ...state, transactionError: action.error, signed: false }; case "SET_SIGNED": return { ...state, signed: true }; case "RESET": return { optimisticOperation: null, transactionError: null, signed: false }; default: return state; } } function createInitialState() { return { optimisticOperation: null, transactionError: null, signed: false }; } /** * Pure operation state management without platform-specific side effects * Desktop and mobile wrap this with their own side-effects (Redux dispatch) */ function useSendFlowOperationState() { const [state, dispatch] = (0, react_1.useReducer)(operationReducer, undefined, createInitialState); const dispatchSetOperation = (0, react_1.useCallback)((operation) => { dispatch({ type: "SET_OPERATION", operation }); }, []); const dispatchSetError = (0, react_1.useCallback)((error) => { dispatch({ type: "SET_ERROR", error }); }, []); const dispatchSetSigned = (0, react_1.useCallback)(() => { dispatch({ type: "SET_SIGNED" }); }, []); const dispatchReset = (0, react_1.useCallback)(() => { dispatch({ type: "RESET" }); }, []); const actions = (0, react_1.useMemo)(() => ({ dispatchSetOperation, dispatchSetError, dispatchSetSigned, dispatchReset, }), [dispatchSetOperation, dispatchSetError, dispatchSetSigned, dispatchReset]); return { state, actions }; } //# sourceMappingURL=useSendFlowOperationState.js.map