forked from RabbitDoge/pancake-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfoDataHelpers.ts
More file actions
26 lines (25 loc) · 789 Bytes
/
infoDataHelpers.ts
File metadata and controls
26 lines (25 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/**
* Get increase/decrease of value compared to the previous value (e.g. 24h volume compared to 24h volume the day before )
* @param valueNow - more recent value
* @param valueBefore - value to compare with
*/
export const getAmountChange = (valueNow?: number, valueBefore?: number) => {
if (valueNow && valueBefore) {
return valueNow - valueBefore
}
if (valueNow) {
return valueNow
}
return 0
}
/**
* Get increase/decrease of value compared to the previous value as a percentage
* @param valueNow - more recent value
* @param valueBefore - value to compare with
*/
export const getPercentChange = (valueNow?: number, valueBefore?: number): number => {
if (valueNow && valueBefore) {
return ((valueNow - valueBefore) / valueBefore) * 100
}
return 0
}