All files / src/services EpochTracker.ts

100% Statements 10/10
100% Branches 0/0
100% Functions 3/3
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1942x 42x 42x 42x   42x       125x     125x 128x          
import { Cardano, EpochInfo, EraSummary, createSlotEpochInfoCalc } from '@cardano-sdk/core';
import { Observable, distinctUntilChanged, map, switchMap } from 'rxjs';
import { TrackerSubject } from '@cardano-sdk/util-rxjs';
import { epochInfoEquals } from './util';
 
export const currentEpochTracker = (
  tip$: Observable<Cardano.Tip>,
  eraSummaries$: Observable<EraSummary[]>
): TrackerSubject<EpochInfo> =>
  new TrackerSubject(
    eraSummaries$.pipe(
      switchMap((eraSummaries) => {
        const slotEpochInfoCalc = createSlotEpochInfoCalc(eraSummaries);
        return tip$.pipe(map(({ slot }) => slotEpochInfoCalc(slot)));
      }),
      distinctUntilChanged(epochInfoEquals)
    )
  );