<commit_before>import React from 'react'
import PropTypes from 'prop-types'
import { FormattedNumber } from 'react-intl'
import { convert } from '@zap/utils/btc'

/**
 * Value - Renders a satoshi amount into a specific currency/unit.
 *
 * @param {object} options Options
 * @param {number} options.value Amount in satoshis.
 * @param {string} options.currency Currency to display as (btc, bits, sats, msats, fiat).
 * @param {object} options.currentTicker Current fiat ticker info.
 * @param {object} options.fiatTicker Key of fiat ticker to use for fiat conversions.
 * @returns {object} Component
 */
const Value = ({ value, currency, currentTicker, fiatTicker, style }) => {
  const price = currency === 'fiat' ? currentTicker[fiatTicker] : null

  // Convert the satoshi amount to the requested currency.
  const convertedAmount = convert('sats', currency, value, price)

  // Truncate the amount to the most relevant number of decimal places.
  let dp
  switch (currency) {
    case 'btc':
      dp = 8
      break
    case 'bits':
      dp = 5
      break
    case 'sats':
      dp = 3
      break
    case 'msats':
      dp = 0
      break
    case 'fiat':
      dp = 2
      break
    default:
      dp = 11
  }

  return (
    <FormattedNumber
      currency={fiatTicker}
      maximumFractionDigits={dp}
      style={style}
      value={convertedAmount}
    />
  )
}

Value.propTypes = {
  currency: PropTypes.string.isRequired,
  currentTicker: PropTypes.object,
  fiatTicker: PropTypes.string,
  style: PropTypes.oneOf(['decimal', 'currency']),
  value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
}

Value.defaultProps = {
  style: 'decimal',
}

export default Value<commit_msg>fix(ui): always display crypto amounts as positve numbers<commit_after>import React from 'react'
import PropTypes from 'prop-types'
import { FormattedNumber } from 'react-intl'
import { convert } from '@zap/utils/btc'
import { CoinBig } from '@zap/utils/coin'

/**
 * Value - Renders a satoshi amount into a specific currency/unit.
 *
 * @param {object} options Options
 * @param {number} options.value Amount in satoshis.
 * @param {string} options.currency Currency to display as (btc, bits, sats, msats, fiat).
 * @param {object} options.currentTicker Current fiat ticker info.
 * @param {object} options.fiatTicker Key of fiat ticker to use for fiat conversions.
 * @returns {object} Component
 */
const Value = ({ value, currency, currentTicker, fiatTicker, style }) => {
  const price = currency === 'fiat' ? currentTicker[fiatTicker] : null

  // Convert the satoshi amount to the requested currency.
  const convertedAmount = convert('sats', currency, value, price)

  const absAmount = CoinBig(convertedAmount)
    .abs()
    .toString()

  // Truncate the amount to the most relevant number of decimal places.
  let dp
  switch (currency) {
    case 'btc':
      dp = 8
      break
    case 'bits':
      dp = 5
      break
    case 'sats':
      dp = 3
      break
    case 'msats':
      dp = 0
      break
    case 'fiat':
      dp = 2
      break
    default:
      dp = 11
  }

  return (
    <FormattedNumber
      currency={fiatTicker}
      maximumFractionDigits={dp}
      style={style}
      value={absAmount}
    />
  )
}

Value.propTypes = {
  currency: PropTypes.string.isRequired,
  currentTicker: PropTypes.object,
  fiatTicker: PropTypes.string,
  style: PropTypes.oneOf(['decimal', 'currency']),
  value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
}

Value.defaultProps = {
  style: 'decimal',
}

export default Value
{'fraction_non_alphanumeric': 0.11298009531819456, 'fraction_numerical': 0.003924866834875245, 'mean_word_length': 3.1730994152046783, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4417085', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1112, 'n_words': 343}