From f850a17f630d53dd93667338e03786c2b26dfd64 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Mon, 13 Jan 2020 11:42:26 -0330 Subject: [PATCH] Convert FiatValue component to ES6 class (#7786) Co-authored-by: Mark Stacey --- ui/app/components/ui/fiat-value.js | 48 +++++++++++++++--------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/ui/app/components/ui/fiat-value.js b/ui/app/components/ui/fiat-value.js index bd217dc47..a029b2559 100644 --- a/ui/app/components/ui/fiat-value.js +++ b/ui/app/components/ui/fiat-value.js @@ -1,36 +1,36 @@ +import PropTypes from 'prop-types' import React, { Component } from 'react' -import { inherits } from 'util' import { formatBalance } from '../../helpers/utils/util' -export default FiatValue +export default class FiatValue extends Component { + static propTypes = { + conversionRate: PropTypes.number.isRequired, + currentCurrency: PropTypes.string, + style: PropTypes.object, + value: PropTypes.string.isRequired, + } -inherits(FiatValue, Component) -function FiatValue () { - Component.call(this) -} + render () { + const { conversionRate, currentCurrency, style } = this.props + const renderedCurrency = currentCurrency || '' -FiatValue.prototype.render = function () { - const props = this.props - const { conversionRate, currentCurrency, style } = props - const renderedCurrency = currentCurrency || '' + const value = formatBalance(this.props.value, 6) - const value = formatBalance(props.value, 6) + if (value === 'None') { + return value + } + let fiatDisplayNumber, fiatTooltipNumber + const splitBalance = value.split(' ') - if (value === 'None') { - return value - } - let fiatDisplayNumber, fiatTooltipNumber - const splitBalance = value.split(' ') + if (conversionRate !== 0) { + fiatTooltipNumber = Number(splitBalance[0]) * conversionRate + fiatDisplayNumber = fiatTooltipNumber.toFixed(2) + } else { + fiatDisplayNumber = 'N/A' + } - if (conversionRate !== 0) { - fiatTooltipNumber = Number(splitBalance[0]) * conversionRate - fiatDisplayNumber = fiatTooltipNumber.toFixed(2) - } else { - fiatDisplayNumber = 'N/A' - fiatTooltipNumber = 'Unknown' + return fiatDisplay(fiatDisplayNumber, renderedCurrency.toUpperCase(), style) } - - return fiatDisplay(fiatDisplayNumber, renderedCurrency.toUpperCase(), style) } function fiatDisplay (fiatDisplayNumber, fiatSuffix, styleOveride = {}) {