2021-02-04 19:15:23 +01:00
|
|
|
import React, { useMemo } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { PRIMARY, SECONDARY, ETH } from '../../../helpers/constants/common';
|
|
|
|
import CurrencyDisplay from '../../ui/currency-display';
|
|
|
|
import { useUserPreferencedCurrency } from '../../../hooks/useUserPreferencedCurrency';
|
2018-10-17 01:03:29 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default function UserPreferencedCurrencyDisplay({
|
2020-07-09 22:33:37 +02:00
|
|
|
'data-testid': dataTestId,
|
|
|
|
ethLogoHeight = 12,
|
|
|
|
ethNumberOfDecimals,
|
|
|
|
fiatNumberOfDecimals,
|
2021-04-08 23:34:55 +02:00
|
|
|
'numberOfDecimals': propsNumberOfDecimals,
|
2020-07-09 22:33:37 +02:00
|
|
|
showEthLogo,
|
|
|
|
type,
|
|
|
|
...restProps
|
|
|
|
}) {
|
2020-11-03 00:41:28 +01:00
|
|
|
const { currency, numberOfDecimals } = useUserPreferencedCurrency(type, {
|
|
|
|
ethNumberOfDecimals,
|
|
|
|
fiatNumberOfDecimals,
|
|
|
|
numberOfDecimals: propsNumberOfDecimals,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-05-12 21:07:35 +02:00
|
|
|
const prefixComponent = useMemo(() => {
|
2020-11-03 00:41:28 +01:00
|
|
|
return (
|
|
|
|
currency === ETH &&
|
2021-05-25 02:20:09 +02:00
|
|
|
showEthLogo && (
|
|
|
|
<img src="./images/eth.svg" height={ethLogoHeight} alt="" />
|
|
|
|
)
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
}, [currency, showEthLogo, ethLogoHeight]);
|
2018-10-17 01:03:29 +02:00
|
|
|
|
2020-05-12 21:07:35 +02:00
|
|
|
return (
|
|
|
|
<CurrencyDisplay
|
|
|
|
{...restProps}
|
|
|
|
currency={currency}
|
2020-07-09 22:33:37 +02:00
|
|
|
data-testid={dataTestId}
|
2020-05-12 21:07:35 +02:00
|
|
|
numberOfDecimals={numberOfDecimals}
|
|
|
|
prefixComponent={prefixComponent}
|
|
|
|
/>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-05-12 21:07:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UserPreferencedCurrencyDisplay.propTypes = {
|
2021-04-08 23:34:55 +02:00
|
|
|
'className': PropTypes.string,
|
2020-07-09 22:33:37 +02:00
|
|
|
'data-testid': PropTypes.string,
|
2021-04-08 23:34:55 +02:00
|
|
|
'prefix': PropTypes.string,
|
|
|
|
'value': PropTypes.string,
|
|
|
|
'numberOfDecimals': PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
|
|
'hideLabel': PropTypes.bool,
|
|
|
|
'hideTitle': PropTypes.bool,
|
|
|
|
'style': PropTypes.object,
|
|
|
|
'showEthLogo': PropTypes.bool,
|
|
|
|
'ethLogoHeight': PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
|
|
'type': PropTypes.oneOf([PRIMARY, SECONDARY]),
|
|
|
|
'ethNumberOfDecimals': PropTypes.oneOfType([
|
2020-11-03 00:41:28 +01:00
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.number,
|
|
|
|
]),
|
2021-04-08 23:34:55 +02:00
|
|
|
'fiatNumberOfDecimals': PropTypes.oneOfType([
|
2020-11-03 00:41:28 +01:00
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.number,
|
|
|
|
]),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|