-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(earn): add safety card to pool info screen (#6162)
### Description Part 1 of adding safety score section, showing details / bottom sheet will be in a follow up ### Test plan unit tests, manually by opening beefy pool <img src="https://github.com/user-attachments/assets/a9bd00c5-737d-42f8-94a0-7d3266ce8f84" width="250" /> ### Related issues - Part of ACT-1405 ### Backwards compatibility Yes ### Network scalability If a new NetworkId and/or Network are added in the future, the changes in this PR will: - [x] Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added)
- Loading branch information
1 parent
419f30d
commit 8db264a
Showing
7 changed files
with
218 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { render } from '@testing-library/react-native' | ||
import React from 'react' | ||
import { SafetyCard } from 'src/earn/SafetyCard' | ||
import Colors from 'src/styles/colors' | ||
|
||
describe('SafetyCard', () => { | ||
it('renders correctly', () => { | ||
const { getByTestId, getAllByTestId } = render( | ||
<SafetyCard safety={{ level: 'low', risks: [] }} /> | ||
) | ||
|
||
expect(getByTestId('SafetyCard')).toBeDefined() | ||
expect(getByTestId('SafetyCardInfoIcon')).toBeDefined() | ||
expect(getAllByTestId('SafetyCard/Bar')).toHaveLength(3) | ||
expect(getByTestId('SafetyCard/ViewDetails')).toBeDefined() | ||
}) | ||
|
||
it.each([ | ||
{ level: 'low', colors: [Colors.primary, Colors.gray2, Colors.gray2] }, | ||
{ level: 'medium', colors: [Colors.primary, Colors.primary, Colors.gray2] }, | ||
{ level: 'high', colors: [Colors.primary, Colors.primary, Colors.primary] }, | ||
] as const)('should render correct triple bars for safety level $level', ({ level, colors }) => { | ||
const { getAllByTestId } = render(<SafetyCard safety={{ level, risks: [] }} />) | ||
|
||
const bars = getAllByTestId('SafetyCard/Bar') | ||
expect(bars.length).toBe(3) | ||
expect(bars[0]).toHaveStyle({ backgroundColor: colors[0] }) | ||
expect(bars[1]).toHaveStyle({ backgroundColor: colors[1] }) | ||
expect(bars[2]).toHaveStyle({ backgroundColor: colors[2] }) | ||
}) | ||
}) |
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,102 @@ | ||
import React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { StyleSheet, Text, View } from 'react-native' | ||
import { LabelWithInfo } from 'src/components/LabelWithInfo' | ||
import Touchable from 'src/components/Touchable' | ||
import { Safety } from 'src/positions/types' | ||
import Colors from 'src/styles/colors' | ||
import { typeScale } from 'src/styles/fonts' | ||
import { Spacing } from 'src/styles/styles' | ||
|
||
const BAR_HEIGHTS = [8, 13, 18] | ||
|
||
const LEVEL_TO_MAX_HIGHLIGHTED_BAR: Record<Safety['level'], 1 | 2 | 3> = { | ||
low: 1, | ||
medium: 2, | ||
high: 3, | ||
} | ||
|
||
export function SafetyCard({ safety }: { safety: Safety }) { | ||
const { t } = useTranslation() | ||
return ( | ||
<View style={styles.card} testID="SafetyCard"> | ||
<View style={styles.cardLineContainer}> | ||
<View style={styles.cardLineLabel}> | ||
<LabelWithInfo | ||
onPress={() => { | ||
// todo(act-1405): open bottom sheet | ||
}} | ||
label={t('earnFlow.poolInfoScreen.safetyScore')} | ||
labelStyle={styles.cardTitleText} | ||
testID="SafetyCardInfoIcon" | ||
/> | ||
</View> | ||
<View style={styles.tripleBarContainer}> | ||
{BAR_HEIGHTS.map((height, index) => ( | ||
<View | ||
testID="SafetyCard/Bar" | ||
key={index} | ||
style={[ | ||
styles.bar, | ||
{ height }, | ||
index < LEVEL_TO_MAX_HIGHLIGHTED_BAR[safety.level] && styles.barHighlighted, | ||
]} | ||
/> | ||
))} | ||
</View> | ||
</View> | ||
<Touchable | ||
testID="SafetyCard/ViewDetails" | ||
style={styles.cardLineContainer} | ||
onPress={() => { | ||
// todo(act-1405): expand and display risks | ||
}} | ||
> | ||
<Text style={styles.viewDetailsText}>{t('earnFlow.poolInfoScreen.viewMoreDetails')}</Text> | ||
</Touchable> | ||
</View> | ||
) | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
card: { | ||
padding: Spacing.Regular16, | ||
borderColor: Colors.gray2, | ||
borderWidth: 1, | ||
borderRadius: 12, | ||
gap: Spacing.Regular16, | ||
}, | ||
cardLineContainer: { | ||
flex: 1, | ||
flexDirection: 'row', | ||
}, | ||
cardTitleText: { | ||
...typeScale.labelSemiBoldMedium, | ||
color: Colors.black, | ||
}, | ||
cardLineLabel: { | ||
paddingRight: 20, // Prevents Icon from being cut off on long labels | ||
}, | ||
tripleBarContainer: { | ||
flex: 1, | ||
gap: 2, | ||
flexDirection: 'row', | ||
paddingHorizontal: Spacing.Tiny4, | ||
alignItems: 'flex-end', | ||
paddingBottom: 3, | ||
justifyContent: 'flex-end', | ||
}, | ||
bar: { | ||
width: 4, | ||
backgroundColor: Colors.gray2, | ||
}, | ||
barHighlighted: { | ||
backgroundColor: Colors.primary, | ||
}, | ||
viewDetailsText: { | ||
...typeScale.labelSemiBoldSmall, | ||
color: Colors.gray3, | ||
textAlign: 'center', | ||
flex: 1, | ||
}, | ||
}) |
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