All files / src/Rewards/DbSyncRewardProvider mappers.ts

100% Statements 12/12
75% Branches 3/4
100% Functions 2/2
100% Lines 11/11

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 2140x     40x 9x 38x 38x 38x 38x         38x 31x   7x   38x    
import { Cardano, Reward } from '@cardano-sdk/core';
import { RewardEpochModel } from './types';
 
export const rewardsToCore = (rewards: RewardEpochModel[]): Map<Cardano.RewardAccount, Reward[]> =>
  rewards.reduce((_rewards, current) => {
    const coreReward = current.address as unknown as Cardano.RewardAccount;
    const poolId = current.pool_id ? (current.pool_id as unknown as Cardano.PoolId) : undefined;
    const epochRewards = _rewards.get(coreReward);
    const currentEpochReward = {
      epoch: Cardano.EpochNo(current.epoch),
      poolId,
      rewards: BigInt(current.quantity)
    };
    if (epochRewards) {
      _rewards.set(coreReward, [...epochRewards, currentEpochReward]);
    } else {
      _rewards.set(coreReward, [currentEpochReward]);
    }
    return _rewards;
  }, new Map<Cardano.RewardAccount, Reward[]>());