Skip to content

Commit

Permalink
feat: calc tokenPnL
Browse files Browse the repository at this point in the history
  • Loading branch information
hnimtadd committed Aug 8, 2024
1 parent f7aa19d commit f295234
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions apps/wallet/src/features/Home/TokenValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import { StyleSheet, View } from 'react-native';
import { Hoverable, Text } from '@walless/gui';
import { Eye, EyeOff } from '@walless/icons';
import TotalPnL from 'components/TotalPnL';
import { useSettings } from 'utils/hooks';
import { useSettings, useTokens } from 'utils/hooks';

interface Props {
value: number;
}

const TokenValue: FC<Props> = ({ value }) => {
const { setting, setPrivacy } = useSettings();
const { valuation, pnl } = useTokens();

const handleToggleTokenValue = async () => {
setPrivacy(!setting.hideBalance);
};
const pnlRates = (pnl / (valuation != 0 ? valuation : 1)) * 100;

return (
<View style={styles.container}>
Expand All @@ -32,7 +34,11 @@ const TokenValue: FC<Props> = ({ value }) => {
)}
</Hoverable>
</View>
<TotalPnL value={-123} percentage={11.34} isDarkTheme={false} />
<TotalPnL
value={Math.round(pnl * 100) / 100}
percentage={Math.round(pnlRates * 100) / 100}
isDarkTheme={true}
/>
</View>
</View>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export const WalletBalance: FC<Props> = ({
</View>
<View style={styles.pnLContainer}>
<TotalPnL
value={Math.round(pnl * 10000) / 10000}
value={Math.round(pnl * 100) / 100}
percentage={Math.round(pnlRates * 100) / 100}
isDarkTheme={true}
isDarkTheme={false}
/>
</View>
</View>
Expand Down Expand Up @@ -71,6 +71,6 @@ const styles = StyleSheet.create({
marginLeft: 34,
},
pnLContainer: {
paddingLeft: 15,
paddingLeft: 10,
},
});

0 comments on commit f295234

Please sign in to comment.