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.js' export default function ExchangeRateDisplay ({ primaryTokenValue, primaryTokenDecimals = 18, primaryTokenSymbol, secondaryTokenValue, secondaryTokenDecimals = 18, secondaryTokenSymbol, arrowColor = 'black', className, }) { const [showPrimaryToSecondary, setShowPrimaryToSecondary] = useState(true) const [arrowsRotation, setArrowRotation] = useState(0) const primaryTokenAmount = calcTokenAmount(primaryTokenValue, primaryTokenDecimals) const secondaryTokenAmount = calcTokenAmount(secondaryTokenValue, secondaryTokenDecimals) const conversionRateFromPrimaryToSecondary = (new BigNumber(secondaryTokenAmount)).div(primaryTokenAmount).round(6).toString(10) const conversionRateFromSecondaryToPrimary = (new BigNumber(primaryTokenAmount)).div(secondaryTokenAmount).round(6).toString(10) const baseSymbol = showPrimaryToSecondary ? primaryTokenSymbol : secondaryTokenSymbol const ratiodSymbol = showPrimaryToSecondary ? secondaryTokenSymbol : primaryTokenSymbol const rate = showPrimaryToSecondary ? conversionRateFromPrimaryToSecondary : conversionRateFromSecondaryToPrimary return (