UNPKG

@ledgerhq/live-common

Version:
37 lines 1.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useBalanceSyncState = useBalanceSyncState; const react_1 = require("react"); /** * Shared balance-display logic consumed by both desktop and mobile during sync. * * - **Sticky balanceAvailable**: stays `false` while syncing so the skeleton * covers the entire cycle (Skeleton → Animate balance, no shimmer gap). * - **Frozen balance**: holds the pre-sync value so `AmountDisplay` can * animate the delta once the sync settles. * - **isLoading**: true while `syncPhase` is `"syncing"`. */ function useBalanceSyncState({ rawBalanceAvailable, syncPhase, latestBalance, shouldFreezeOnSync, }) { const [balanceUnavailable, setBalanceUnavailable] = (0, react_1.useState)(!rawBalanceAvailable); (0, react_1.useEffect)(() => { if (!rawBalanceAvailable) { setBalanceUnavailable(true); } else if (syncPhase !== "syncing") { setBalanceUnavailable(false); } }, [rawBalanceAvailable, syncPhase]); const frozenBalanceRef = (0, react_1.useRef)(latestBalance); (0, react_1.useEffect)(() => { if (syncPhase !== "syncing") { frozenBalanceRef.current = latestBalance; } }, [syncPhase, latestBalance]); const shouldFreeze = shouldFreezeOnSync && syncPhase === "syncing"; return { balanceAvailable: !balanceUnavailable, displayedBalance: shouldFreeze ? frozenBalanceRef.current : latestBalance, isLoading: syncPhase === "syncing", }; } //# sourceMappingURL=useBalanceSyncState.js.map