UNPKG

@ledgerhq/live-common

Version:
24 lines 1.06 kB
import { useBatchAccountsSyncState } from "./useAccountSyncState"; export function useAccountsSyncStatus(accountsWithUpToDateCheck) { const allAccounts = accountsWithUpToDateCheck.map(item => item.account); const isUpToDateByAccountId = new Map(accountsWithUpToDateCheck.map(item => [item.account.id, item.isUpToDate ?? true])); const batchState = useBatchAccountsSyncState({ accounts: allAccounts }); const accountsWithError = []; for (const { syncState, account } of batchState) { if (syncState.pending) continue; const isUpToDate = isUpToDateByAccountId.get(account.id); if (syncState.error || !isUpToDate) { accountsWithError.push(account); } } const areAllAccountsUpToDate = accountsWithError.length === 0; const lastSyncMs = Math.max(...allAccounts.map(a => a.lastSyncDate?.getTime() ?? 0), 0); return { allAccounts, accountsWithError, areAllAccountsUpToDate, lastSyncMs, }; } //# sourceMappingURL=useAccountsSyncStatus.js.map