import React, { useState } from 'react'; import PropTypes from 'prop-types'; import BigNumber from 'bignumber.js'; import classnames from 'classnames'; import { calcTokenAmount } from '../../../helpers/utils/token-util'; import { formatSwapsValueForDisplay } from '../swaps.util'; export default function ExchangeRateDisplay({ primaryTokenValue, primaryTokenDecimals = 18, primaryTokenSymbol, secondaryTokenValue, secondaryTokenDecimals = 18, secondaryTokenSymbol, arrowColor = 'black', boldSymbols = true, className, }) { const [showPrimaryToSecondary, setShowPrimaryToSecondary] = useState(true); const [rotating, setRotating] = useState(false); const primaryTokenAmount = calcTokenAmount( primaryTokenValue, primaryTokenDecimals, ); const secondaryTokenAmount = calcTokenAmount( secondaryTokenValue, secondaryTokenDecimals, ); const conversionRateFromPrimaryToSecondary = new BigNumber( secondaryTokenAmount, ) .div(primaryTokenAmount) .round(9) .toString(10); const conversionRateFromSecondaryToPrimary = new BigNumber(primaryTokenAmount) .div(secondaryTokenAmount) .round(9) .toString(10); const baseSymbol = showPrimaryToSecondary ? primaryTokenSymbol : secondaryTokenSymbol; const ratiodSymbol = showPrimaryToSecondary ? secondaryTokenSymbol : primaryTokenSymbol; const rate = showPrimaryToSecondary ? conversionRateFromPrimaryToSecondary : conversionRateFromSecondaryToPrimary; let rateToDisplay; let comparisonSymbol = '='; if (new BigNumber(rate, 10).lt('0.00000001', 10)) { rateToDisplay = '0.000000001'; comparisonSymbol = '<'; } else if (new BigNumber(rate, 10).lt('0.000001', 10)) { rateToDisplay = rate; } else { rateToDisplay = formatSwapsValueForDisplay(rate); } return (