Skip to content
Open
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
62 changes: 38 additions & 24 deletions apps/wallet/src/components/TotalPnL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,51 @@ interface Props {
value: number;
percentage: number;
isDarkTheme: boolean;
numDigit: number;
}

const TotalPnL: FC<Props> = ({ value, percentage, isDarkTheme = false }) => {
const TotalPnL: FC<Props> = ({
value,
percentage,
isDarkTheme = false,
numDigit = 2,
}) => {
if (numDigit <= 0) {
numDigit = 2;
}
const baseDigit = 10 ** numDigit;
value = Math.round(value * baseDigit) / baseDigit;
percentage = Math.round(percentage * baseDigit) / baseDigit;
const isLost = value < 0;
const isProfit = value > 0;

return (
<View style={styles.container}>
<Text
style={[
styles.pnlTextBase,
styles.pnlValueBase,
isDarkTheme ? styles.darkThemePnLText : styles.lightThemePnLText,
]}
>
{isLost ? `≈ -$${-value}` : isProfit ? `≈ +$${value}` : null}
</Text>
<View
style={[
styles.percentageContainerBase,
isLost
? styles.LostPercentageContainer
: styles.ProfitPercentageContainer,
]}
>
<Text style={[styles.pnlTextBase]}>
{isLost ? `${percentage}%` : isProfit ? `+${percentage}%` : null}
if (percentage !== 0) {
return (
<View style={styles.container}>
<Text
style={[
styles.pnlTextBase,
styles.pnlValueBase,
isDarkTheme ? styles.darkThemePnLText : styles.lightThemePnLText,
]}
>
{isLost ? `≈ -$${-value}` : isProfit ? `≈ +$${value}` : null}
</Text>
<View
style={[
styles.percentageContainerBase,
isLost
? styles.LostPercentageContainer
: styles.ProfitPercentageContainer,
]}
>
<Text style={[styles.pnlTextBase]}>
{isLost ? `${percentage}%` : isProfit ? `+${percentage}%` : null}
</Text>
</View>
</View>
</View>
);
);
}
};

export default TotalPnL;
Expand Down
5 changes: 3 additions & 2 deletions apps/wallet/src/features/Home/TokenValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ const TokenValue: FC<Props> = ({ value }) => {
</Hoverable>
</View>
<TotalPnL
value={Math.round(pnl * 100) / 100}
percentage={Math.round(pnlRates * 100) / 100}
value={pnl}
percentage={pnlRates}
isDarkTheme={true}
numDigit={2}
/>
</View>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ export const WalletBalance: FC<Props> = ({
</View>
<View style={styles.pnLContainer}>
<TotalPnL
value={Math.round(pnl * 100) / 100}
percentage={Math.round(pnlRates * 100) / 100}
isDarkTheme={false}
value={pnl}
percentage={pnlRates}
isDarkTheme={true}
numDigit={4}
/>
</View>
</View>
Expand Down