@@ -4,15 +4,16 @@ import {
4
4
type AccountPerformanceHistoryPeriod ,
5
5
useGetAccountPerformanceHistory ,
6
6
} from 'clients/api' ;
7
- import { ButtonGroup , Card , Cell , type CellProps , ErrorState , InfoIcon } from 'components' ;
7
+ import { ButtonGroup , Card , Cell , type CellProps , ErrorState , Icon , InfoIcon } from 'components' ;
8
8
import { AreaChart } from 'components' ;
9
9
import { NULL_ADDRESS } from 'constants/address' ;
10
10
import { useBreakpointUp } from 'hooks/responsive' ;
11
11
import { useIsFeatureEnabled } from 'hooks/useIsFeatureEnabled' ;
12
12
import { useTranslation } from 'libs/translations' ;
13
13
import { useAccountAddress } from 'libs/wallet' ;
14
14
import { useState } from 'react' ;
15
- import { formatCentsToReadableValue } from 'utilities' ;
15
+ import { formatCentsToReadableValue , formatPercentageToReadableValue } from 'utilities' ;
16
+ import { DollarValueChange } from './DollarValueChange' ;
16
17
import { formatToReadableAxisDate } from './formatToReadableAxisDate' ;
17
18
import { formatToReadableTitleDate } from './formatToReadableTitleDate' ;
18
19
@@ -58,10 +59,12 @@ export const PerformanceChart: React.FC<PerformanceChartProps> = ({ className, n
58
59
period : selectedPeriod ,
59
60
} ) ;
60
61
const accountPerformanceHistory = getAccountPerformanceHistoryData ?. performanceHistory || [ ] ;
62
+
61
63
const startOfDayNetWorthCents =
62
64
getAccountPerformanceHistoryData ?. startOfDayNetWorthCents !== undefined
63
65
? getAccountPerformanceHistoryData ?. startOfDayNetWorthCents
64
66
: undefined ;
67
+
65
68
const oldestNetWorthCents =
66
69
accountPerformanceHistory . length > 0
67
70
? Number ( accountPerformanceHistory [ 0 ] . netWorthCents )
@@ -71,18 +74,14 @@ export const PerformanceChart: React.FC<PerformanceChartProps> = ({ className, n
71
74
oldestNetWorthCents !== undefined ? netWorthCents - oldestNetWorthCents : undefined ;
72
75
73
76
const dailyChangeCents =
74
- startOfDayNetWorthCents !== undefined
75
- ? accountPerformanceHistory [ accountPerformanceHistory . length - 1 ] . netWorthCents -
76
- startOfDayNetWorthCents
77
- : undefined ;
77
+ startOfDayNetWorthCents !== undefined ? netWorthCents - startOfDayNetWorthCents : undefined ;
78
78
79
- const readableAbsolutePerformance = formatCentsToReadableValue ( {
80
- value : absolutePerformanceCents ,
81
- } ) ;
79
+ const dailyChangePercentage =
80
+ dailyChangeCents !== undefined && netWorthCents !== 0
81
+ ? ( dailyChangeCents * 100 ) / netWorthCents
82
+ : undefined ;
82
83
83
- const readableDailyChange = formatCentsToReadableValue ( {
84
- value : dailyChangeCents ,
85
- } ) ;
84
+ const readableDailyChangePercentage = formatPercentageToReadableValue ( dailyChangePercentage ) ;
86
85
87
86
const [ selectedDataPoint , setSelectedDataPoint ] = useState <
88
87
AccountPerformanceHistoryDataPoint | undefined
@@ -94,20 +93,30 @@ export const PerformanceChart: React.FC<PerformanceChartProps> = ({ className, n
94
93
{
95
94
label : t ( 'account.performanceChart.todaysChange' ) ,
96
95
value : (
97
- < span className = "text-base sm:text-lg" >
98
- { dailyChangeCents !== undefined && dailyChangeCents > 0 && '+' }
99
- { readableDailyChange }
100
- </ span >
96
+ < div className = "space-x-2 flex items-center" >
97
+ < DollarValueChange value = { dailyChangeCents } />
98
+
99
+ { dailyChangeCents !== undefined && dailyChangeCents !== 0 && (
100
+ < div
101
+ className = { cn ( 'flex items-center' , dailyChangeCents > 0 ? 'text-green' : 'text-red' ) }
102
+ >
103
+ < Icon
104
+ name = "arrowUpFull2"
105
+ className = { cn (
106
+ 'w-4 h-4 text-inherit -mb-[2px]' ,
107
+ dailyChangeCents < 0 && 'rotate-180' ,
108
+ ) }
109
+ />
110
+
111
+ < span > { readableDailyChangePercentage } </ span >
112
+ </ div >
113
+ ) }
114
+ </ div >
101
115
) ,
102
116
} ,
103
117
{
104
118
label : t ( 'account.performanceChart.absolutePerformance' ) ,
105
- value : (
106
- < span className = "text-base sm:text-lg" >
107
- { absolutePerformanceCents !== undefined && absolutePerformanceCents > 0 && '+' }
108
- { readableAbsolutePerformance }
109
- </ span >
110
- ) ,
119
+ value : < DollarValueChange value = { absolutePerformanceCents } /> ,
111
120
} ,
112
121
] ;
113
122
@@ -140,9 +149,7 @@ export const PerformanceChart: React.FC<PerformanceChartProps> = ({ className, n
140
149
141
150
< p className = "text-xl sm:text-2xl sm:order-1" >
142
151
{ formatCentsToReadableValue ( {
143
- value : selectedDataPoint ?. netWorthCents
144
- ? Number ( selectedDataPoint . netWorthCents )
145
- : netWorthCents ,
152
+ value : selectedDataPoint ? Number ( selectedDataPoint . netWorthCents ) : netWorthCents ,
146
153
} ) }
147
154
</ p >
148
155
</ div >
@@ -176,6 +183,7 @@ export const PerformanceChart: React.FC<PerformanceChartProps> = ({ className, n
176
183
data = { accountPerformanceHistory }
177
184
xAxisDataKey = "blockTimestampMs"
178
185
yAxisDataKey = "netWorthCents"
186
+ yAxisTickCount = { 5 }
179
187
onDataPointHover = { payload => setSelectedDataPoint ( payload ) }
180
188
onMouseLeave = { ( ) => setSelectedDataPoint ( undefined ) }
181
189
formatXAxisValue = { formatToReadableAxisDate }
0 commit comments