Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MembershipCard } from '@/features/rnbw-membership/screens/rnbw-membersh
import { RNBW_SYMBOL } from '@/features/rnbw-rewards/constants';
import { useRnbwStakingEarnings } from '@/features/rnbw-staking/stores/derived/useRnbwStakingEarnings';
import { useStakingPositionStore } from '@/features/rnbw-staking/stores/rnbwStakingPositionStore';
import { parseDecimalParts } from '@/framework/core/utils/parseDecimalParts';
import { isZero } from '@/helpers/utilities';
import * as i18n from '@/languages';

Expand All @@ -21,6 +22,7 @@ export const RnbwStakingEarningsCard = memo(function RnbwStakingEarningsCard() {
}

const isZeroTotalEarnings = isZero(totalEarnings);
const { whole: totalEarningsWhole, fractionalSuffix: totalEarningsFractionalSuffix } = parseDecimalParts(totalEarnings);

return (
<MembershipCard padding="24px">
Expand All @@ -32,7 +34,12 @@ export const RnbwStakingEarningsCard = memo(function RnbwStakingEarningsCard() {
<Box flexDirection="row" alignItems="center" gap={8}>
<Image source={rnbwCoinImage} style={{ width: 40, height: 40 }} />
<Text size="34pt" weight="bold" color={isZeroTotalEarnings ? 'labelQuaternary' : 'label'}>
{totalEarnings}
{totalEarningsWhole}
{totalEarningsFractionalSuffix && (
<Text size="26pt" weight="bold" color="labelQuaternary">
{totalEarningsFractionalSuffix}
</Text>
)}
</Text>
</Box>
<Separator color="separatorTertiary" thickness={1} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const useRnbwStakingEarnings = createDerivedStore<StakingEarnings>(
const exitRewardsEarnings = convertRawAmountToDecimalFormat(exitRewardsRaw, tokenDecimals);

return {
totalEarnings: isZero(totalEarnings) ? '0' : formatNumber(totalEarnings, { decimals: 4 }),
totalEarnings: isZero(totalEarnings) ? '0' : formatNumber(totalEarnings, { decimals: 5 }),
cashbackEarnings: isZero(cashbackEarnings)
? '0'
: truncateToDecimalsWithThreshold({ value: cashbackEarnings, decimals: 2, threshold: '0.01' }),
Expand Down
19 changes: 19 additions & 0 deletions src/framework/core/utils/parseDecimalParts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { parseDecimalParts } from './parseDecimalParts';

const testCases = [
{ value: '123', expected: { whole: '123', fractionalSuffix: '' } },
{ value: '-123', expected: { whole: '-123', fractionalSuffix: '' } },
{ value: '123.45', expected: { whole: '123', fractionalSuffix: '.45' } },
{ value: '-123.45', expected: { whole: '-123', fractionalSuffix: '.45' } },
{ value: '.45', expected: { whole: '', fractionalSuffix: '.45' } },
{ value: '123.', expected: { whole: '123', fractionalSuffix: '.' } },
{ value: '1.2.3', expected: { whole: '1.2', fractionalSuffix: '.3' } },
];

describe('parseDecimalParts', () => {
testCases.forEach(({ value, expected }) => {
it(`parses ${value}`, () => {
expect(parseDecimalParts(value)).toEqual(expected);
});
});
});
15 changes: 15 additions & 0 deletions src/framework/core/utils/parseDecimalParts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function parseDecimalParts(value: string): {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a couple of unit tests for this helper?

whole: string;
fractionalSuffix: string;
} {
const decimalIndex = value.lastIndexOf('.');

if (decimalIndex === -1) {
return { whole: value, fractionalSuffix: '' };
}

return {
whole: value.slice(0, decimalIndex),
fractionalSuffix: value.slice(decimalIndex),
};
}
Loading