2021-02-04 19:15:23 +01:00
|
|
|
import React, { useMemo } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2023-01-25 16:47:02 +01:00
|
|
|
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common';
|
2021-02-04 19:15:23 +01:00
|
|
|
import CurrencyDisplay from '../../ui/currency-display';
|
|
|
|
import { useUserPreferencedCurrency } from '../../../hooks/useUserPreferencedCurrency';
|
2023-01-25 16:47:02 +01:00
|
|
|
import { EtherDenomination } from '../../../../shared/constants/common';
|
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,
|
2022-03-25 18:35:11 +01:00
|
|
|
ethLogoHeight = 14,
|
2020-07-09 22:33:37 +02:00
|
|
|
ethNumberOfDecimals,
|
|
|
|
fiatNumberOfDecimals,
|
2021-12-09 20:06:24 +01:00
|
|
|
numberOfDecimals: propsNumberOfDecimals,
|
2020-07-09 22:33:37 +02:00
|
|
|
showEthLogo,
|
|
|
|
type,
|
2022-03-29 21:21:45 +02:00
|
|
|
showFiat,
|
2022-08-03 21:35:34 +02:00
|
|
|
showCurrencySuffix,
|
2020-07-09 22:33:37 +02:00
|
|
|
...restProps
|
|
|
|
}) {
|
2020-11-03 00:41:28 +01:00
|
|
|
const { currency, numberOfDecimals } = useUserPreferencedCurrency(type, {
|
|
|
|
ethNumberOfDecimals,
|
|
|
|
fiatNumberOfDecimals,
|
|
|
|
numberOfDecimals: propsNumberOfDecimals,
|
2022-03-29 21:21:45 +02:00
|
|
|
showFiatOverride: showFiat,
|
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 (
|
2023-01-25 16:47:02 +01:00
|
|
|
currency === EtherDenomination.ETH &&
|
2021-05-25 02:20:09 +02:00
|
|
|
showEthLogo && (
|
2022-03-25 18:35:11 +01:00
|
|
|
<i
|
|
|
|
className="fab fa-ethereum"
|
|
|
|
style={{
|
|
|
|
color: 'var(--color-icon-default)',
|
|
|
|
fontSize: ethLogoHeight,
|
|
|
|
}}
|
|
|
|
/>
|
2021-05-25 02:20:09 +02:00
|
|
|
)
|
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}
|
2022-08-03 21:35:34 +02:00
|
|
|
suffix={showCurrencySuffix && !showEthLogo && currency}
|
2020-05-12 21:07:35 +02:00
|
|
|
/>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-05-12 21:07:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UserPreferencedCurrencyDisplay.propTypes = {
|
2021-12-09 20:06:24 +01:00
|
|
|
className: PropTypes.string,
|
2020-07-09 22:33:37 +02:00
|
|
|
'data-testid': PropTypes.string,
|
2021-12-09 20:06:24 +01: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,
|
2022-03-25 18:35:11 +01:00
|
|
|
ethLogoHeight: PropTypes.number,
|
2021-12-09 20:06:24 +01:00
|
|
|
type: PropTypes.oneOf([PRIMARY, SECONDARY]),
|
|
|
|
ethNumberOfDecimals: PropTypes.oneOfType([
|
2020-11-03 00:41:28 +01:00
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.number,
|
|
|
|
]),
|
2021-12-09 20:06:24 +01:00
|
|
|
fiatNumberOfDecimals: PropTypes.oneOfType([
|
2020-11-03 00:41:28 +01:00
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.number,
|
|
|
|
]),
|
2022-05-10 18:57:11 +02:00
|
|
|
showFiat: PropTypes.bool,
|
2022-08-03 21:35:34 +02:00
|
|
|
showCurrencySuffix: PropTypes.bool,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|