All files / src/services/ProviderTracker TrackedRewardsProvider.ts

80% Statements 20/25
100% Branches 0/0
70% Functions 7/10
85.71% Lines 18/21

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 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 4342x 42x     42x 134x 134x 134x     121x 121x 121x                     42x 134x           134x 134x   134x   134x 103x   134x 123x      
import { BehaviorSubject } from 'rxjs';
import { CLEAN_FN_STATS, ProviderFnStats, ProviderTracker } from './ProviderTracker';
import { RewardsProvider } from '@cardano-sdk/core';
 
export class RewardsProviderStats {
  readonly healthCheck$ = new BehaviorSubject<ProviderFnStats>(CLEAN_FN_STATS);
  readonly rewardsHistory$ = new BehaviorSubject<ProviderFnStats>(CLEAN_FN_STATS);
  readonly rewardAccountBalance$ = new BehaviorSubject<ProviderFnStats>(CLEAN_FN_STATS);
 
  shutdown() {
    this.healthCheck$.complete();
    this.rewardsHistory$.complete();
    this.rewardAccountBalance$.complete();
  }
 
  reset() {
    this.healthCheck$.next(CLEAN_FN_STATS);
    this.rewardsHistory$.next(CLEAN_FN_STATS);
    this.rewardAccountBalance$.next(CLEAN_FN_STATS);
  }
}
 
/** Wraps a RewardsProvider, tracking # of calls of each function */
export class TrackedRewardsProvider extends ProviderTracker implements RewardsProvider {
  readonly stats = new RewardsProviderStats();
  readonly healthCheck: RewardsProvider['healthCheck'];
  readonly rewardsHistory: RewardsProvider['rewardsHistory'];
  readonly rewardAccountBalance: RewardsProvider['rewardAccountBalance'];
 
  constructor(rewardsProvider: RewardsProvider) {
    super();
    rewardsProvider = rewardsProvider;
 
    this.healthCheck = () => this.trackedCall(() => rewardsProvider.healthCheck(), this.stats.healthCheck$);
 
    this.rewardsHistory = (fragments) =>
      this.trackedCall(() => rewardsProvider.rewardsHistory(fragments), this.stats.rewardsHistory$);
 
    this.rewardAccountBalance = (fragments) =>
      this.trackedCall(() => rewardsProvider.rewardAccountBalance(fragments), this.stats.rewardAccountBalance$);
  }
}