UNPKG

@ledgerhq/live-common

Version:
46 lines 1.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.POLLING_FINISHED_DELAY_MS = void 0; exports.useSyncSources = useSyncSources; const react_1 = require("react"); const live_countervalues_react_1 = require("@ledgerhq/live-countervalues-react"); const context_1 = require("./context"); const useGlobalSyncState_1 = require("./useGlobalSyncState"); const useStablePending_1 = require("./useStablePending"); exports.POLLING_FINISHED_DELAY_MS = 200; /** * Aggregates the three sync sources (countervalues, bridge, wallet sync) into * a single unified state. This is the raw sync plumbing layer — no lifecycle * or loading semantics. * * `walletSyncState` is injected so each platform can provide its own * context-based implementation (LLD / LLM WalletSyncContext). */ function useSyncSources(walletSyncState) { const cvPolling = (0, live_countervalues_react_1.useCountervaluesPolling)(); const globalSyncState = (0, useGlobalSyncState_1.useGlobalSyncState)(); const bridgeSync = (0, context_1.useBridgeSync)(); const isPending = cvPolling.pending || globalSyncState.pending || walletSyncState.visualPending; const stablePending = (0, useStablePending_1.useStablePending)(isPending, exports.POLLING_FINISHED_DELAY_MS); const hasCvOrBridgeError = !isPending && (!!cvPolling.error || !!globalSyncState.error); const hasWalletSyncError = !!walletSyncState.walletSyncError; const { onUserRefresh } = walletSyncState; const { poll } = cvPolling; const triggerRefresh = (0, react_1.useCallback)(() => { onUserRefresh(); poll(); bridgeSync({ type: "SYNC_ALL_ACCOUNTS", priority: 5, reason: "user-click", }); }, [onUserRefresh, poll, bridgeSync]); return { isPending, stablePending, hasCvOrBridgeError, hasWalletSyncError, triggerRefresh, }; } //# sourceMappingURL=useSyncSources.js.map