-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(earn): Review & Deposit updates - APY and earn up to amount (#5449)
### Description Review and deposit fast follows - Generalizes the APY and earn up to component - Uses it in the Review and Deposit screen ### Test plan Unit tests added/updated. Enter amount (looks same as before): ![enter-amount](https://github.com/valora-inc/wallet/assets/140328381/7416db76-246c-486b-bc76-090d013b3873) Deposit: ![deposit](https://github.com/valora-inc/wallet/assets/140328381/db121d61-a8e3-446b-83f8-fe6dd2fdceee) ### Related issues - Fixes #ACT-1195 ### 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
ed44f1f
commit 48373ce
Showing
5 changed files
with
132 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import BigNumber from 'bignumber.js' | ||
import React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { StyleSheet, Text, View } from 'react-native' | ||
import { Colors } from 'react-native/Libraries/NewAppScreen' | ||
import { useSelector } from 'react-redux' | ||
import TokenIcon, { IconSize } from 'src/components/TokenIcon' | ||
import { useAavePoolInfo } from 'src/earn/hooks' | ||
import { LocalCurrencySymbol } from 'src/localCurrency/consts' | ||
import { getLocalCurrencySymbol } from 'src/localCurrency/selectors' | ||
import { typeScale } from 'src/styles/fonts' | ||
import { Spacing } from 'src/styles/styles' | ||
import { TokenBalance } from 'src/tokens/slice' | ||
|
||
export function EarnApyAndAmount({ | ||
tokenAmount, | ||
token, | ||
testIDPrefix = 'Earn', | ||
}: { | ||
tokenAmount: BigNumber | null | ||
token: TokenBalance | ||
testIDPrefix?: string | ||
}) { | ||
const { t } = useTranslation() | ||
|
||
const localCurrencySymbol = useSelector(getLocalCurrencySymbol) ?? LocalCurrencySymbol.USD | ||
|
||
const asyncPoolInfo = useAavePoolInfo({ depositTokenId: token.tokenId }) | ||
const apy = asyncPoolInfo?.result?.apy | ||
|
||
const apyString = apy ? (apy * 100).toFixed(2) : '--' | ||
const earnUpTo = | ||
apy && tokenAmount?.gt(0) ? tokenAmount.multipliedBy(new BigNumber(apy)).toFormat(2) : '--' | ||
|
||
return ( | ||
<> | ||
<View style={styles.line}> | ||
<Text style={styles.label}>{t('earnFlow.enterAmount.earnUpToLabel')}</Text> | ||
<Text style={styles.label}>{t('earnFlow.enterAmount.rateLabel')}</Text> | ||
</View> | ||
<View style={styles.line}> | ||
<Text style={styles.valuesText} testID={`${testIDPrefix}/EarnApyAndAmount/EarnUpTo`}> | ||
{t('earnFlow.enterAmount.earnUpTo', { | ||
fiatSymbol: localCurrencySymbol, | ||
amount: earnUpTo, | ||
})} | ||
</Text> | ||
<View style={styles.apy}> | ||
<TokenIcon token={token} size={IconSize.XSMALL} /> | ||
<Text style={styles.valuesText} testID={`${testIDPrefix}/EarnApyAndAmount/Apy`}> | ||
{t('earnFlow.enterAmount.rate', { | ||
rate: apyString, | ||
})} | ||
</Text> | ||
</View> | ||
</View> | ||
</> | ||
) | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
apy: { | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
gap: Spacing.Tiny4, | ||
}, | ||
label: { | ||
...typeScale.bodySmall, | ||
color: Colors.gray4, | ||
}, | ||
line: { | ||
flexDirection: 'row', | ||
alignSelf: 'flex-end', | ||
justifyContent: 'space-between', | ||
width: '100%', | ||
gap: Spacing.Smallest8, | ||
}, | ||
valuesText: { | ||
...typeScale.labelSemiBoldSmall, | ||
marginVertical: Spacing.Tiny4, | ||
}, | ||
}) |
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