2022-06-28 15:11:19 +02:00
|
|
|
import React, { useState } from 'react';
|
2022-04-01 17:52:22 +02:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import Box from '../../../ui/box';
|
|
|
|
import Typography from '../../../ui/typography';
|
|
|
|
import CheckBox from '../../../ui/check-box';
|
|
|
|
|
|
|
|
import {
|
|
|
|
COLORS,
|
|
|
|
DISPLAY,
|
|
|
|
TYPOGRAPHY,
|
|
|
|
} from '../../../../helpers/constants/design-system';
|
|
|
|
import { useTokenTracker } from '../../../../hooks/useTokenTracker';
|
|
|
|
import { useTokenFiatAmount } from '../../../../hooks/useTokenFiatAmount';
|
|
|
|
|
2022-06-28 15:11:19 +02:00
|
|
|
const DetectedTokenValues = ({ token }) => {
|
|
|
|
const [selectedTokens, setSelectedTokens] = useState(false);
|
2022-04-01 17:52:22 +02:00
|
|
|
const { tokensWithBalances } = useTokenTracker([token]);
|
2022-06-28 15:11:19 +02:00
|
|
|
const balanceToRender = tokensWithBalances[0]?.string;
|
|
|
|
const balance = tokensWithBalances[0]?.balance;
|
2022-04-01 17:52:22 +02:00
|
|
|
const formattedFiatBalance = useTokenFiatAmount(
|
|
|
|
token.address,
|
2022-06-28 15:11:19 +02:00
|
|
|
balanceToRender,
|
2022-04-01 17:52:22 +02:00
|
|
|
token.symbol,
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Box display={DISPLAY.INLINE_FLEX} className="detected-token-values">
|
|
|
|
<Box marginBottom={1}>
|
|
|
|
<Typography variant={TYPOGRAPHY.H4}>
|
2022-06-28 15:11:19 +02:00
|
|
|
{`${balance || '0'} ${token.symbol}`}
|
2022-04-01 17:52:22 +02:00
|
|
|
</Typography>
|
|
|
|
<Typography variant={TYPOGRAPHY.H7} color={COLORS.TEXT_ALTERNATIVE}>
|
|
|
|
{formattedFiatBalance || '$0'}
|
|
|
|
</Typography>
|
|
|
|
</Box>
|
|
|
|
<Box className="detected-token-values__checkbox">
|
2022-06-28 15:11:19 +02:00
|
|
|
<CheckBox
|
|
|
|
checked={selectedTokens}
|
|
|
|
onClick={() => setSelectedTokens((checked) => !checked)}
|
|
|
|
/>
|
2022-04-01 17:52:22 +02:00
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
DetectedTokenValues.propTypes = {
|
|
|
|
token: PropTypes.shape({
|
|
|
|
address: PropTypes.string.isRequired,
|
|
|
|
decimals: PropTypes.number,
|
|
|
|
symbol: PropTypes.string,
|
|
|
|
iconUrl: PropTypes.string,
|
|
|
|
aggregators: PropTypes.array,
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DetectedTokenValues;
|