All files / src/StakePool/HttpStakePoolMetadata mappers.ts

100% Statements 9/9
100% Branches 2/2
100% Functions 3/3
100% Lines 6/6

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  36x   36x   36x                       36x                                         36x 8x  
import { APExtMetadataResponse, Cip6ExtMetadataResponse } from './types';
import { Cardano } from '@cardano-sdk/core';
import { StakePoolExtMetadataResponse } from '../types';
import { isCip6Format } from './util';
 
const mapFromCip6Format = ({ serial, pool }: Cip6ExtMetadataResponse): Cardano.ExtendedStakePoolMetadata => ({
  pool: {
    contact: pool.contact,
    id: Cardano.PoolIdHex(pool.id),
    itn: pool.itn,
    location: pool.country,
    media_assets: pool.media_assets,
    status: pool.status
  },
  serial
});
 
const mapFromAdaPoolsFormat = ({ info }: APExtMetadataResponse): Cardano.ExtendedStakePoolMetadata => ({
  pool: {
    about: info.about,
    company: info.company,
    contact: {
      discord: info.social?.discord_handle,
      facebook: info.social?.facebook_handle,
      github: info.social?.github_handle,
      telegram: info.social?.telegram_handle,
      twitch: info.social?.twitch_handle,
      twitter: info.social?.twitter_handle,
      youtube: info.social?.youtube_handle
    },
    location: info.location,
    media_assets: {
      icon_png_64x64: info.url_png_icon_64x64,
      logo_png: info.url_png_logo
    }
  }
});
 
export const mapToExtendedMetadata = (metadata: StakePoolExtMetadataResponse) =>
  isCip6Format(metadata) ? mapFromCip6Format(metadata) : mapFromAdaPoolsFormat(metadata);