-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
429 additions
and
59 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
app/component-library/components-temp/Price/AggregatedPercentage/AgregatedPercentage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React from 'react'; | ||
import { fontStyles } from '../../../../styles/common'; | ||
import Text from '../../../../component-library/components/Texts/Text'; | ||
import { View, StyleSheet } from 'react-native'; | ||
import { useTheme } from '../../../../util/theme'; | ||
import { Colors } from '../../../../util/theme/models'; | ||
import { renderFiat } from '../../../../util/number'; | ||
import { useSelector } from 'react-redux'; | ||
import { selectCurrentCurrency } from '../../../../selectors/currencyRateController'; | ||
|
||
const createStyles = (colors: Colors) => | ||
StyleSheet.create({ | ||
wrapper: { | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}, | ||
balancePositiveStyle: { | ||
color: colors.success.default, | ||
...fontStyles.normal, | ||
textTransform: 'uppercase', | ||
}, | ||
balanceNegativeStyle: { | ||
color: colors.error.default, | ||
...fontStyles.normal, | ||
textTransform: 'uppercase', | ||
}, | ||
}); | ||
|
||
const isValidAmount = (amount: number | null | undefined): boolean => | ||
amount !== null && amount !== undefined && !Number.isNaN(amount); | ||
|
||
const AggregatedPercentage = ({ | ||
ethFiat, | ||
tokenFiat, | ||
tokenFiat1dAgo, | ||
ethFiat1dAgo, | ||
}: { | ||
ethFiat: number; | ||
tokenFiat: number; | ||
tokenFiat1dAgo: number; | ||
ethFiat1dAgo: number; | ||
}) => { | ||
const { colors } = useTheme(); | ||
const styles = createStyles(colors); | ||
const currentCurrency = useSelector(selectCurrentCurrency); | ||
const DECIMALS_TO_SHOW = 2; | ||
|
||
const totalBalance = ethFiat + tokenFiat; | ||
const totalBalance1dAgo = ethFiat1dAgo + tokenFiat1dAgo; | ||
|
||
const amountChange = totalBalance - totalBalance1dAgo; | ||
const percentageChange = | ||
((totalBalance - totalBalance1dAgo) / totalBalance1dAgo) * 100; | ||
|
||
const percentageStyle = | ||
amountChange && amountChange >= 0 | ||
? styles.balancePositiveStyle | ||
: styles.balanceNegativeStyle; | ||
|
||
const formattedPercentage = isValidAmount(percentageChange) | ||
? `${(percentageChange as number) >= 0 ? '+' : ''}${( | ||
percentageChange as number | ||
).toFixed(2)}%` | ||
: ''; | ||
|
||
const formattedValuePrice = isValidAmount(amountChange) | ||
? `${(amountChange as number) >= 0 ? '+' : ''}(${renderFiat( | ||
amountChange, | ||
currentCurrency, | ||
DECIMALS_TO_SHOW, | ||
)}) ` | ||
: ''; | ||
|
||
return ( | ||
<View style={styles.wrapper}> | ||
<Text style={percentageStyle}>{formattedValuePrice}</Text> | ||
<Text style={percentageStyle}>{formattedPercentage}</Text> | ||
</View> | ||
); | ||
}; | ||
|
||
export default AggregatedPercentage; |
1 change: 1 addition & 0 deletions
1
app/component-library/components-temp/Price/AggregatedPercentage/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './AgregatedPercentage'; |
261 changes: 219 additions & 42 deletions
261
app/components/UI/Tokens/__snapshots__/index.test.tsx.snap
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.