Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(earn): Show daily yield rate on the pool info screen if available #6159

Merged
merged 5 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion locales/base/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -2695,6 +2695,7 @@
"chainName": "Chain: <0>{{networkName}}</0>",
"protocolName": "Protocol: <0>{{providerName}}</0>",
"yieldRate": "Yield Rate",
"dailyYieldRate": "Daily Rate",
"ratePercent": "{{rate}}%",
"rewards": "Rewards",
"noRewards": "No rewards",
Expand All @@ -2716,7 +2717,10 @@
"ageTitle": "Age of Pool",
"ageDescription": "Older liquidity pools can indicate a solid track record and a history of building community trust. Because of this, some may consider these pools to be safer.\n\nThere is no perfect way to determine risk, so use this info as part of your overall research to make the decision that is best for you.",
"yieldRateTitle": "Yield Rate",
"yieldRateDescription": "While most pools offer earnings in the form of a liquidity pool token, some give additional token(s) as a reward or added incentive.\n\nSince {{appName}} aggregates pools across multiple protocols, we have combined all the earning and reward rates into a single, overall yield rate to help easily evaluate your earning potential. This number is an estimate since the earning and reward values fluctuate constantly.\n\nFor further information about earning breakdowns you can visit <0>{{providerName}}</0>."
"yieldRateDescription": "While most pools offer earnings in the form of a liquidity pool token, some give additional token(s) as a reward or added incentive.\n\nSince {{appName}} aggregates pools across multiple protocols, we have combined all the earning and reward rates into a single, overall yield rate to help easily evaluate your earning potential. This number is an estimate since the earning and reward values fluctuate constantly.\n\nFor further information about earning breakdowns you can visit <0>{{providerName}}</0>.",
"dailyYieldRateTitle": "Daily Rate",
"dailyYieldRateDescription": "The daily rate displayed reflects the daily rate provided by {{providerName}}.",
"dailyYieldRateLink": "View More Daily Rate Details On {{providerName}}"
}
},
"beforeDepositBottomSheet": {
Expand Down
2 changes: 1 addition & 1 deletion src/analytics/Properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,7 @@ interface EarnEventsProperties {
[EarnEvents.earn_home_error_try_again]: undefined
[EarnEvents.earn_pool_info_view_pool]: EarnCommonProperties
[EarnEvents.earn_pool_info_tap_info_icon]: {
type: 'tvl' | 'age' | 'yieldRate' | 'deposit'
type: 'tvl' | 'age' | 'yieldRate' | 'deposit' | 'dailyYieldRate'
} & EarnCommonProperties
[EarnEvents.earn_pool_info_tap_withdraw]: {
poolAmount: string
Expand Down
24 changes: 24 additions & 0 deletions src/earn/EarnPoolInfoScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -623,4 +623,28 @@ describe('EarnPoolInfoScreen', () => {
})
// TODO (ACT-1343): check that navigate is called with correct params
})
it('shows the daily yield rate when it is available', () => {
const { getByTestId } = renderEarnPoolInfoScreen({
...mockEarnPositions[0],
dataProps: {
...mockEarnPositions[0].dataProps,
dailyYieldRatePercentage: 0.0452483,
},
})
expect(
within(getByTestId('DailyYieldRateCard')).getAllByText(
'earnFlow.poolInfoScreen.ratePercent, {"rate":"0.0452"}'
)
).toBeTruthy()
})
it.each([0, undefined])('does not show the daily yield rate when it is %s', (dailyYieldRate) => {
const { queryByTestId } = renderEarnPoolInfoScreen({
...mockEarnPositions[0],
dataProps: {
...mockEarnPositions[0].dataProps,
dailyYieldRatePercentage: dailyYieldRate,
},
})
expect(queryByTestId('DailyYieldRateCard')).toBeFalsy()
})
})
83 changes: 79 additions & 4 deletions src/earn/EarnPoolInfoScreen.tsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is nearing 1000 lines.. I was thinking of breaking this up, I am already putting the safety card in a different file

Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
/>
</View>
<Text style={styles.cardTitleText}>
{yieldRateSum > 0
{yieldRateSum > 0.00005
? t('earnFlow.poolInfoScreen.ratePercent', { rate: yieldRateSum.toFixed(2) })
: '--'}
</Text>
Expand Down Expand Up @@ -320,6 +320,33 @@
)
}

function DailyYieldRateCard({
dailyYieldRate,
onInfoIconPress,
}: {
dailyYieldRate: number
onInfoIconPress: () => void
}) {
const { t } = useTranslation()
return (
<View style={styles.card} testID="DailyYieldRateCard">
<View style={styles.cardLineContainer}>
<View style={styles.cardLineLabel}>
<LabelWithInfo
onPress={onInfoIconPress}
label={t('earnFlow.poolInfoScreen.dailyYieldRate')}
labelStyle={styles.cardTitleText}
testID="DailyYieldRateInfoIcon"
/>
</View>
<Text style={styles.cardTitleText}>
{t('earnFlow.poolInfoScreen.ratePercent', { rate: dailyYieldRate.toFixed(4) })}
</Text>
</View>
</View>
)
}

function TvlCard({
earnPosition,
onInfoIconPress,
Expand Down Expand Up @@ -407,10 +434,10 @@
}}
>
<View style={styles.learnMoreView}>
<OpenLinkIcon color={Colors.black} size={24} />
<Text style={styles.learnMoreText}>
{t('earnFlow.poolInfoScreen.learnMoreOnProvider', { providerName })}
</Text>
<OpenLinkIcon color={Colors.black} size={16} />
</View>
</Touchable>
</View>
Expand Down Expand Up @@ -514,6 +541,7 @@
const tvlInfoBottomSheetRef = useRef<BottomSheetModalRefType>(null)
const ageInfoBottomSheetRef = useRef<BottomSheetModalRefType>(null)
const yieldRateInfoBottomSheetRef = useRef<BottomSheetModalRefType>(null)
const dailyYieldRateInfoBottomSheetRef = useRef<BottomSheetModalRefType>(null)

// Scroll Aware Header
const scrollPosition = useSharedValue(0)
Expand Down Expand Up @@ -573,6 +601,22 @@
tokensInfo={tokensInfo}
earnPosition={pool}
/>
{!!dataProps.dailyYieldRatePercentage && dataProps.dailyYieldRatePercentage > 0 && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably fine, but should we check its >= 0.00005? so we don't end up showing 0.0000 with the round with toFixed?

<DailyYieldRateCard
dailyYieldRate={dataProps.dailyYieldRatePercentage}
onInfoIconPress={() => {
AppAnalytics.track(EarnEvents.earn_pool_info_tap_info_icon, {

Check warning on line 608 in src/earn/EarnPoolInfoScreen.tsx

View check run for this annotation

Codecov / codecov/patch

src/earn/EarnPoolInfoScreen.tsx#L607-L608

Added lines #L607 - L608 were not covered by tests
providerId: appId,
poolId: positionId,
type: 'dailyYieldRate',
networkId,
depositTokenId: dataProps.depositTokenId,
})
dailyYieldRateInfoBottomSheetRef.current?.snapToIndex(0)
}}
/>
)}

<TvlCard
earnPosition={pool}
onInfoIconPress={() => {
Expand Down Expand Up @@ -647,6 +691,16 @@
providerName={appName}
testId="YieldRateInfoBottomSheet"
/>
<InfoBottomSheet
infoBottomSheetRef={dailyYieldRateInfoBottomSheetRef}
titleKey="earnFlow.poolInfoScreen.infoBottomSheet.dailyYieldRateTitle"
descriptionKey="earnFlow.poolInfoScreen.infoBottomSheet.dailyYieldRateDescription"
descriptionUrl={dataProps.manageUrl}
providerName={appName}
linkKey="earnFlow.poolInfoScreen.infoBottomSheet.dailyYieldRateLink"
linkUrl={dataProps.manageUrl}
testId="DailyYieldRateInfoBottomSheet"
/>
<BeforeDepositBottomSheet
forwardedRef={beforeDepositBottomSheetRef}
token={depositToken}
Expand All @@ -667,13 +721,17 @@
descriptionUrl,
providerName,
testId,
linkUrl,
linkKey,
}: {
infoBottomSheetRef: React.RefObject<BottomSheetModalRefType>
titleKey: string
descriptionKey: string
descriptionUrl?: string
providerName: string
testId: string
linkUrl?: string
linkKey?: string
}) {
const { t } = useTranslation()
const dispatch = useDispatch()
Expand Down Expand Up @@ -702,6 +760,23 @@
) : (
<Text style={styles.infoBottomSheetText}>{t(descriptionKey, { providerName })}</Text>
)}
{!!linkUrl && !!linkKey && (
<View style={styles.learnMoreContainer}>
<Touchable
borderRadius={8}
onPress={() => {
navigateToURI(linkUrl)

Check warning on line 768 in src/earn/EarnPoolInfoScreen.tsx

View check run for this annotation

Codecov / codecov/patch

src/earn/EarnPoolInfoScreen.tsx#L767-L768

Added lines #L767 - L768 were not covered by tests
}}
>
<View style={styles.learnMoreView}>
<Text style={styles.learnMoreText}>
<Trans i18nKey={linkKey} tOptions={{ providerName }} />
</Text>
<OpenLinkIcon color={Colors.black} size={16} />
</View>
</Touchable>
</View>
)}
<Button
onPress={onPressDismiss}
text={t('earnFlow.poolInfoScreen.infoBottomSheet.gotIt')}
Expand Down Expand Up @@ -837,10 +912,10 @@
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
padding: Spacing.Smallest8,
marginBottom: Spacing.Thick24,
},
learnMoreText: {
...typeScale.bodyMedium,
...typeScale.labelSemiBoldSmall,
color: Colors.black,
},
buttonContainer: {
Expand Down
1 change: 1 addition & 0 deletions src/positions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface EarnDataProps {
depositTokenId: string
withdrawTokenId: string
rewardsPositionIds?: string[]
dailyYieldRatePercentage?: number
// We'll add more fields here as needed
}

Expand Down
3 changes: 3 additions & 0 deletions test/RootStateSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,9 @@
"contractCreatedAt": {
"type": "string"
},
"dailyYieldRatePercentage": {
"type": "number"
},
"depositTokenId": {
"type": "string"
},
Expand Down
Loading