Commit 5101e054 authored by isstuev's avatar isstuev

fix rounding

parent 591e8583
...@@ -18,13 +18,20 @@ interface Props { ...@@ -18,13 +18,20 @@ interface Props {
const CurrencyValue = ({ value, currency = '', unit, exchangeRate, className, accuracy, accuracyUsd }: Props) => { const CurrencyValue = ({ value, currency = '', unit, exchangeRate, className, accuracy, accuracyUsd }: Props) => {
const valueCurr = getValueWithUnit(value, unit); const valueCurr = getValueWithUnit(value, unit);
const valueResult = parseFloat(accuracy ? valueCurr.toFixed(accuracy) : valueCurr.toFixed()); const valueResult = accuracy ? valueCurr.dp(accuracy).toFormat() : valueCurr.toFormat();
let usdContent; let usdContent;
if (exchangeRate !== undefined && exchangeRate !== null) { if (exchangeRate !== undefined && exchangeRate !== null) {
const exchangeRateBn = new BigNumber(exchangeRate); const exchangeRateBn = new BigNumber(exchangeRate);
const usdBn = valueCurr.times(exchangeRateBn); const usdBn = valueCurr.times(exchangeRateBn);
const usdResult = parseFloat(accuracyUsd ? usdBn.toFixed(accuracyUsd) : usdBn.toFixed()); let usdResult: string;
if (accuracyUsd && !usdBn.isEqualTo(0)) {
const usdBnDp = usdBn.dp(accuracyUsd);
usdResult = usdBnDp.isEqualTo(0) ? usdBn.precision(accuracyUsd).toFormat() : usdBnDp.toFormat();
} else {
usdResult = usdBn.toFormat();
}
usdContent = ( usdContent = (
<Text as="span" variant="secondary" whiteSpace="pre" fontWeight={ 400 }> (${ usdResult })</Text> <Text as="span" variant="secondary" whiteSpace="pre" fontWeight={ 400 }> (${ usdResult })</Text>
); );
...@@ -32,7 +39,7 @@ const CurrencyValue = ({ value, currency = '', unit, exchangeRate, className, ac ...@@ -32,7 +39,7 @@ const CurrencyValue = ({ value, currency = '', unit, exchangeRate, className, ac
return ( return (
<Box as="span" className={ className }> <Box as="span" className={ className }>
<Text as="span"> <Text display="inline-block">
{ valueResult }{ currency ? ` ${ currency }` : '' } { valueResult }{ currency ? ` ${ currency }` : '' }
</Text> </Text>
{ usdContent } { usdContent }
......
...@@ -57,19 +57,19 @@ const TxAdditionalInfo = ({ tx }: { tx: Transaction }) => { ...@@ -57,19 +57,19 @@ const TxAdditionalInfo = ({ tx }: { tx: Transaction }) => {
{ tx.base_fee_per_gas !== null && ( { tx.base_fee_per_gas !== null && (
<Box> <Box>
<Text as="span" fontWeight="500">Base: </Text> <Text as="span" fontWeight="500">Base: </Text>
<Text fontWeight="600" as="span">{ getValueWithUnit(tx.base_fee_per_gas, 'gwei').toFixed() }</Text> <Text fontWeight="600" as="span">{ getValueWithUnit(tx.base_fee_per_gas, 'gwei').toFormat() }</Text>
</Box> </Box>
) } ) }
{ tx.max_fee_per_gas !== null && ( { tx.max_fee_per_gas !== null && (
<Box> <Box>
<Text as="span" fontWeight="500">Max: </Text> <Text as="span" fontWeight="500">Max: </Text>
<Text fontWeight="600" as="span">{ getValueWithUnit(tx.max_fee_per_gas, 'gwei').toFixed() }</Text> <Text fontWeight="600" as="span">{ getValueWithUnit(tx.max_fee_per_gas, 'gwei').toFormat() }</Text>
</Box> </Box>
) } ) }
{ tx.max_priority_fee_per_gas !== null && ( { tx.max_priority_fee_per_gas !== null && (
<Box> <Box>
<Text as="span" fontWeight="500">Max priority: </Text> <Text as="span" fontWeight="500">Max priority: </Text>
<Text fontWeight="600" as="span">{ getValueWithUnit(tx.max_priority_fee_per_gas, 'gwei').toFixed() }</Text> <Text fontWeight="600" as="span">{ getValueWithUnit(tx.max_priority_fee_per_gas, 'gwei').toFormat() }</Text>
</Box> </Box>
) } ) }
</Box> </Box>
......
...@@ -113,11 +113,11 @@ const TxsListItem = ({ tx }: {tx: Transaction}) => { ...@@ -113,11 +113,11 @@ const TxsListItem = ({ tx }: {tx: Transaction}) => {
</Flex> </Flex>
<Box mt={ 2 }> <Box mt={ 2 }>
<Text as="span">Value { appConfig.network.currency } </Text> <Text as="span">Value { appConfig.network.currency } </Text>
<Text as="span" variant="secondary">{ parseFloat(getValueWithUnit(tx.value).toFixed()) }</Text> <Text as="span" variant="secondary">{ getValueWithUnit(tx.value).toFormat() }</Text>
</Box> </Box>
<Box mt={ 2 } mb={ 3 }> <Box mt={ 2 } mb={ 3 }>
<Text as="span">Fee { appConfig.network.currency } </Text> <Text as="span">Fee { appConfig.network.currency } </Text>
<Text as="span" variant="secondary">{ parseFloat(getValueWithUnit(tx.fee.value).toFixed()) }</Text> <Text as="span" variant="secondary">{ getValueWithUnit(tx.fee.value).toFormat() }</Text>
</Box> </Box>
</Box> </Box>
<Modal isOpen={ isOpen } onClose={ onClose } size="full"> <Modal isOpen={ isOpen } onClose={ onClose } size="full">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment