-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(points): points entry point and intro screen (#5406)
### Description * Add points card to the "Discover" screen * Add an intro screen to the points home page (shown only once) https://github.com/valora-inc/wallet/assets/2737872/ef769852-a628-4e4c-8ce1-63ffcbb0345b ### Test plan Updated unit tests ### Related issues - Fixes RET-1077 ### Backwards compatibility NA ### 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
Showing
26 changed files
with
408 additions
and
42 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { fireEvent, render } from '@testing-library/react-native' | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { PointsEvents } from 'src/analytics/Events' | ||
import ValoraAnalytics from 'src/analytics/ValoraAnalytics' | ||
import { navigate } from 'src/navigator/NavigationService' | ||
import { Screens } from 'src/navigator/Screens' | ||
import PointsDiscoverCard from 'src/points/PointsDiscoverCard' | ||
import { RootState } from 'src/redux/store' | ||
import { getFeatureGate } from 'src/statsig/index' | ||
import { RecursivePartial, createMockStore } from 'test/utils' | ||
|
||
jest.mock('src/analytics/ValoraAnalytics') | ||
jest.mock('src/statsig') | ||
|
||
const renderPointsDiscoverCard = (storeOverrides?: RecursivePartial<RootState>) => { | ||
const store = createMockStore(storeOverrides) | ||
|
||
const tree = render( | ||
<Provider store={store}> | ||
<PointsDiscoverCard /> | ||
</Provider> | ||
) | ||
|
||
return { | ||
store, | ||
...tree, | ||
} | ||
} | ||
|
||
describe('PointsDiscoverCard', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
|
||
jest.mocked(getFeatureGate).mockReturnValue(true) | ||
}) | ||
|
||
it('renders when feature gate is enabled', () => { | ||
const { getByText } = renderPointsDiscoverCard({ points: { pointsBalance: 'BALANCE_AMOUNT' } }) | ||
|
||
expect(getByText('points.discoverCard.title')).toBeTruthy() | ||
expect(getByText('points.discoverCard.description')).toBeTruthy() | ||
expect(getByText('BALANCE_AMOUNT')).toBeTruthy() | ||
}) | ||
|
||
it('does not render when feature gate is disabled', () => { | ||
jest.mocked(getFeatureGate).mockReturnValue(false) | ||
|
||
const { queryByText } = renderPointsDiscoverCard() | ||
|
||
expect(queryByText('points.discoverCard.title')).toBeFalsy() | ||
expect(queryByText('points.discoverCard.description')).toBeFalsy() | ||
}) | ||
|
||
it('tracks analytics event when pressed', () => { | ||
const { getByText } = renderPointsDiscoverCard() | ||
|
||
fireEvent.press(getByText('points.discoverCard.title')) | ||
expect(ValoraAnalytics.track).toHaveBeenCalledWith(PointsEvents.points_discover_press) | ||
}) | ||
|
||
it('takes to the points intro screen if it has not been dismissed', () => { | ||
const { getByText } = renderPointsDiscoverCard() | ||
|
||
fireEvent.press(getByText('points.discoverCard.title')) | ||
expect(navigate).toHaveBeenCalledWith(Screens.PointsIntro) | ||
}) | ||
|
||
it('takes to the points home screen if intro has been dismissed', () => { | ||
const { getByText } = renderPointsDiscoverCard({ points: { introHasBeenDismissed: true } }) | ||
|
||
fireEvent.press(getByText('points.discoverCard.title')) | ||
expect(navigate).toHaveBeenCalledWith(Screens.PointsHome) | ||
}) | ||
}) |
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,98 @@ | ||
import React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { StyleSheet, Text, View } from 'react-native' | ||
import { PointsEvents } from 'src/analytics/Events' | ||
import ValoraAnalytics from 'src/analytics/ValoraAnalytics' | ||
import Touchable from 'src/components/Touchable' | ||
import LogoHeart from 'src/icons/LogoHeart' | ||
import { navigate } from 'src/navigator/NavigationService' | ||
import { Screens } from 'src/navigator/Screens' | ||
import { pointsBalanceSelector, pointsIntroHasBeenDismissedSelector } from 'src/points/selectors' | ||
import { useSelector } from 'src/redux/hooks' | ||
import { getFeatureGate } from 'src/statsig' | ||
import { StatsigFeatureGates } from 'src/statsig/types' | ||
import { Colors } from 'src/styles/colors' | ||
import { typeScale } from 'src/styles/fonts' | ||
import { Spacing } from 'src/styles/styles' | ||
|
||
export default function PointsDiscoverCard() { | ||
const showPoints = getFeatureGate(StatsigFeatureGates.SHOW_POINTS) | ||
|
||
const { t } = useTranslation() | ||
const pointsBalance = useSelector(pointsBalanceSelector) | ||
const pointsIntroHasBeenDismissed = useSelector(pointsIntroHasBeenDismissedSelector) | ||
|
||
const handlePress = () => { | ||
ValoraAnalytics.track(PointsEvents.points_discover_press) | ||
if (pointsIntroHasBeenDismissed) { | ||
navigate(Screens.PointsHome) | ||
} else { | ||
navigate(Screens.PointsIntro) | ||
} | ||
} | ||
|
||
if (!showPoints) { | ||
return null | ||
} | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<Touchable | ||
style={styles.touchable} | ||
borderRadius={Spacing.Smallest8} | ||
onPress={handlePress} | ||
testID="PointsDiscoverCard" | ||
> | ||
<> | ||
<View style={styles.header}> | ||
<Text style={styles.title}>{t('points.discoverCard.title')}</Text> | ||
<View style={styles.pill}> | ||
<Text style={styles.balance}>{pointsBalance}</Text> | ||
<LogoHeart size={Spacing.Regular16} /> | ||
</View> | ||
</View> | ||
<Text style={styles.description}>{t('points.discoverCard.description')}</Text> | ||
</> | ||
</Touchable> | ||
</View> | ||
) | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
marginBottom: Spacing.Thick24, | ||
}, | ||
touchable: { | ||
padding: Spacing.Regular16, | ||
gap: Spacing.Smallest8, | ||
borderColor: Colors.gray2, | ||
borderWidth: 1, | ||
borderRadius: Spacing.Smallest8, | ||
}, | ||
header: { | ||
flexDirection: 'row', | ||
alignItems: 'flex-start', | ||
justifyContent: 'space-between', | ||
}, | ||
pill: { | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
paddingHorizontal: Spacing.Small12, | ||
paddingVertical: Spacing.Tiny4, | ||
gap: Spacing.Tiny4, | ||
backgroundColor: Colors.successLight, | ||
borderRadius: 100, | ||
}, | ||
title: { | ||
...typeScale.labelSemiBoldMedium, | ||
color: Colors.black, | ||
}, | ||
description: { | ||
...typeScale.bodyXSmall, | ||
color: Colors.gray4, | ||
}, | ||
balance: { | ||
...typeScale.labelSemiBoldXSmall, | ||
color: Colors.successDark, | ||
}, | ||
}) |
Oops, something went wrong.