|
| 1 | +import React from 'react'; |
| 2 | + |
| 3 | +import BigNumber from 'bignumber.js'; |
| 4 | + |
| 5 | +import { Box } from '@components'; |
| 6 | +import { ETHUUID } from '@config'; |
| 7 | +import { useRates } from '@services/Rates'; |
| 8 | +import { getBaseFee, getFiatInformation, useSelector } from '@store'; |
| 9 | +import { getAssetByUUID } from '@store/asset.slice'; |
| 10 | +import { translateRaw } from '@translations'; |
| 11 | +import { TUuid } from '@types'; |
| 12 | +import { bigify, formatCurrency, fromWei } from '@utils'; |
| 13 | + |
| 14 | +import ActionTile from './ActionTile'; |
| 15 | + |
| 16 | +export const DashboardGas = () => { |
| 17 | + const baseFee = useSelector(getBaseFee); |
| 18 | + const ethAsset = useSelector(getAssetByUUID(ETHUUID as TUuid))!; |
| 19 | + const { getAssetRate } = useRates(); |
| 20 | + const fiat = useSelector(getFiatInformation); |
| 21 | + |
| 22 | + const baseFeeGwei = |
| 23 | + baseFee && bigify(fromWei(baseFee, 'gwei')).integerValue(BigNumber.ROUND_HALF_UP); |
| 24 | + const baseFeeEther = baseFee && bigify(fromWei(baseFee, 'ether')); |
| 25 | + |
| 26 | + const baseAssetRate = getAssetRate(ethAsset); |
| 27 | + const fiatValue = |
| 28 | + baseFeeEther && |
| 29 | + baseFeeEther |
| 30 | + .multipliedBy(21000) |
| 31 | + .multipliedBy(baseAssetRate) |
| 32 | + .integerValue(BigNumber.ROUND_HALF_UP); |
| 33 | + |
| 34 | + return ( |
| 35 | + <Box variant="rowAlign" justifyContent="space-between"> |
| 36 | + <Box width="48%"> |
| 37 | + <ActionTile |
| 38 | + link="#" |
| 39 | + inverse={true} |
| 40 | + title={baseFeeGwei ? `${baseFeeGwei.toString(10)} ${translateRaw('GWEI')}` : '?'} |
| 41 | + description={translateRaw('CURRENT_BASE_FEE_TEXT')} |
| 42 | + /> |
| 43 | + </Box> |
| 44 | + <Box width="48%"> |
| 45 | + <ActionTile |
| 46 | + link="#" |
| 47 | + inverse={true} |
| 48 | + title={fiatValue ? `${formatCurrency(fiatValue.toString(10), 0, fiat?.ticker)}` : '?'} |
| 49 | + description={translateRaw('ETH_TRANSFER_FEE')} |
| 50 | + /> |
| 51 | + </Box> |
| 52 | + </Box> |
| 53 | + ); |
| 54 | +}; |
0 commit comments