forked from trezor/trezor-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(total stake pending align): added tooltip and trimmed amount
- Loading branch information
1 parent
7ef4a6b
commit 4f1514d
Showing
2 changed files
with
58 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...rc/views/wallet/staking/components/EthStakingDashboard/components/TrimmedCryptoAmount.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { FormattedCryptoAmount } from 'src/components/suite'; | ||
import styled from 'styled-components'; | ||
import { spacingsPx } from '@trezor/theme'; | ||
import { Tooltip, variables } from '@trezor/components'; | ||
import BigNumber from 'bignumber.js'; | ||
|
||
const StyledFormattedCryptoAmount = styled(FormattedCryptoAmount)<{ | ||
$isRewards?: boolean; | ||
$isSmall?: boolean; | ||
}>` | ||
display: block; | ||
margin-top: ${spacingsPx.xs}; | ||
font-size: ${({ $isSmall }) => ($isSmall ? variables.FONT_SIZE.SMALL : variables.FONT_SIZE.H2)}; | ||
color: ${({ $isRewards = false, theme }) => ($isRewards ? theme.textPrimaryDefault : '')}; | ||
`; | ||
|
||
const DEFAULT_MAX_DECIMAL_PLACES = 5; | ||
|
||
interface TrimmedCryptoAmountProps { | ||
value: string | number; | ||
symbol: string; | ||
maxDecimalPlaces?: number; | ||
isRewards?: boolean; | ||
} | ||
|
||
export const TrimmedCryptoAmount = ({ | ||
value, | ||
symbol, | ||
maxDecimalPlaces = DEFAULT_MAX_DECIMAL_PLACES, | ||
isRewards, | ||
}: TrimmedCryptoAmountProps) => { | ||
const hasDecimals = value.toString().includes('.'); | ||
|
||
if (!hasDecimals) { | ||
return <StyledFormattedCryptoAmount value={value} symbol={symbol} $isRewards={isRewards} />; | ||
} | ||
|
||
const valueBig = new BigNumber(value); | ||
const trimmedAmount = valueBig.toFixed(maxDecimalPlaces, 1); | ||
|
||
return ( | ||
<Tooltip content={<StyledFormattedCryptoAmount value={value} symbol={symbol} $isSmall />}> | ||
<StyledFormattedCryptoAmount | ||
value={trimmedAmount} | ||
symbol={symbol} | ||
$isRewards={isRewards} | ||
/> | ||
</Tooltip> | ||
); | ||
}; |