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

fix(earn-cards): handle large font sizes #6308

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
4 changes: 3 additions & 1 deletion src/components/LabelWithInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ export function LabelWithInfo({
iconSize = 16,
testID,
style,
numberOfLines,
}: {
label: string
onPress?: () => void
labelStyle?: StyleProp<TextStyle>
iconSize?: number
numberOfLines?: number | undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it's better to have 1 or undefined as the default

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When I tried to set the default to 1 I ran into an issue where setting it to undefined wasn't overriding the default value. I can try setting the default to undefined and see how that works.

testID?: string
style?: StyleProp<ViewStyle>
}) {
Expand All @@ -30,7 +32,7 @@ export function LabelWithInfo({
disabled={!onPress}
>
<>
<Text style={[styles.labelText, labelStyle]} numberOfLines={1}>
<Text style={[styles.labelText, labelStyle]} numberOfLines={numberOfLines}>
{label}
</Text>
{onPress && <InfoIcon size={iconSize} color={Colors.gray3} />}
Expand Down
7 changes: 6 additions & 1 deletion src/earn/EarnEnterAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ function TransactionWithdrawDetails({
<LabelWithInfo
label={t('earnFlow.enterAmount.available')}
testID="LabelWithInfo/AvailableLabel"
numberOfLines={1}
/>
<View style={styles.txDetailsValue}>
<TokenDisplay
Expand Down Expand Up @@ -651,6 +652,7 @@ function TransactionWithdrawDetails({
<LabelWithInfo
label={t('earnFlow.enterAmount.claimingReward')}
testID={`LabelWithInfo/ClaimingReward-${index}`}
numberOfLines={1}
/>
<View style={{ ...styles.txDetailsValue, flex: 1 }}>
<TokenDisplay
Expand Down Expand Up @@ -680,6 +682,7 @@ function TransactionWithdrawDetails({
feeDetailsBottomSheetRef?.current?.snapToIndex(0)
}}
testID="LabelWithInfo/FeeLabel"
numberOfLines={1}
/>
<View style={styles.txDetailsValue}>
<TokenDisplay
Expand Down Expand Up @@ -735,6 +738,7 @@ function TransactionDepositDetails({
swapDetailsBottomSheetRef?.current?.snapToIndex(0)
}}
testID="LabelWithInfo/SwapLabel"
numberOfLines={1}
/>
<View style={styles.txDetailsValue}>
<TokenDisplay
Expand All @@ -756,7 +760,7 @@ function TransactionDepositDetails({
</View>
)}
<View style={styles.txDetailsLineItem}>
<LabelWithInfo label={t('earnFlow.enterAmount.deposit')} />
<LabelWithInfo label={t('earnFlow.enterAmount.deposit')} numberOfLines={1} />
<View style={styles.txDetailsValue}>
<TokenDisplay
tokenId={pool.dataProps.depositTokenId}
Expand Down Expand Up @@ -784,6 +788,7 @@ function TransactionDepositDetails({
feeDetailsBottomSheetRef?.current?.snapToIndex(0)
}}
testID="LabelWithInfo/FeeLabel"
numberOfLines={1}
/>
<View style={styles.txDetailsValue}>
<TokenDisplay
Expand Down
94 changes: 60 additions & 34 deletions src/earn/poolInfoScreen/Cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@

return (
<View testID="EarningItemLineItem" style={styles.cardLineContainer}>
<View style={styles.cardLineLabel}>
<View style={styles.flexLabel}>
<Text numberOfLines={1} style={styles.depositAndEarningsCardLabelText}>
{earnItem.label}
</Text>
</View>
<View style={styles.flexShrink}>
<View style={styles.flexValue}>
<Text style={styles.depositAndEarningsCardValueText}>
{t('earnFlow.poolInfoScreen.lineItemAmountDisplay', {
localCurrencySymbol,
Expand Down Expand Up @@ -126,6 +126,7 @@
label={t('earnFlow.poolInfoScreen.totalDepositAndEarnings')}
labelStyle={styles.cardTitleText}
testID={'DepositInfoIcon'}
numberOfLines={1}
/>
<View>
<Text style={styles.depositAndEarningCardTitleText}>
Expand All @@ -139,7 +140,7 @@

<View style={styles.depositAndEarningCardSubtitleContainer}>
<View style={styles.cardLineContainer}>
<View style={styles.cardLineLabel}>
<View style={styles.flexLabel}>
{cantSeparateCompoundedInterest ? (
<Text style={styles.depositAndEarningsCardLabelText}>
{t('earnFlow.poolInfoScreen.depositAndEarnings')}
Expand All @@ -150,7 +151,7 @@
</Text>
)}
</View>
<View style={styles.flexShrink}>
<View style={styles.flexValue}>
<Text style={styles.depositAndEarningsCardValueText}>
{t('earnFlow.poolInfoScreen.lineItemAmountDisplay', {
localCurrencySymbol,
Expand Down Expand Up @@ -186,41 +187,43 @@
return (
<View style={styles.card} testID="YieldCard">
<View style={styles.cardLineContainer}>
<View style={styles.cardLineLabel}>
<View style={styles.flexLabel}>
<LabelWithInfo
onPress={onInfoIconPress}
label={t('earnFlow.poolInfoScreen.yieldRate')}
labelStyle={styles.cardTitleText}
labelStyle={styles.lineLabel}
testID="YieldRateInfoIcon"
/>
</View>
<Text style={styles.cardTitleText}>
{yieldRateSum > 0.00005
? t('earnFlow.poolInfoScreen.ratePercent', { rate: yieldRateSum.toFixed(2) })
: '--'}
</Text>
<View style={styles.flexValue}>
<Text style={styles.lineValue}>
{yieldRateSum > 0.00005
? t('earnFlow.poolInfoScreen.ratePercent', { rate: yieldRateSum.toFixed(2) })
: '--'}

Check warning on line 202 in src/earn/poolInfoScreen/Cards.tsx

View check run for this annotation

Codecov / codecov/patch

src/earn/poolInfoScreen/Cards.tsx#L202

Added line #L202 was not covered by tests
</Text>
</View>
</View>
<View style={{ gap: Spacing.Smallest8 }}>
{earnPosition.dataProps.yieldRates.map((rate, index) => {
// TODO: investigate how to do when there are multiple tokens in a yield rate
const tokenInfo = tokensInfo.filter((token) => token.tokenId === rate.tokenId)
return (
<View style={styles.cardLineContainer} key={index}>
<View style={styles.cardLineLabel}>
<View style={styles.flexLabel}>
<View style={styles.yieldRateLabelContainer}>
<Text numberOfLines={1} style={styles.cardLabelText}>
{rate.label}
</Text>
<Text style={styles.cardLabelText}>{rate.label}</Text>
<TokenIcons
tokensInfo={tokenInfo}
size={IconSize.XXSMALL}
showNetworkIcon={false}
/>
</View>
</View>
<Text style={styles.cardLabelText}>
{t('earnFlow.poolInfoScreen.ratePercent', { rate: rate.percentage.toFixed(2) })}
</Text>
<View style={styles.flexValue}>
<Text style={styles.cardValueText}>
{t('earnFlow.poolInfoScreen.ratePercent', { rate: rate.percentage.toFixed(2) })}
</Text>
</View>
</View>
)
})}
Expand All @@ -240,17 +243,19 @@
return (
<View style={styles.card} testID="DailyYieldRateCard">
<View style={styles.cardLineContainer}>
<View style={styles.cardLineLabel}>
<View style={styles.flexLabel}>
<LabelWithInfo
onPress={onInfoIconPress}
label={t('earnFlow.poolInfoScreen.dailyYieldRate')}
labelStyle={styles.cardTitleText}
labelStyle={styles.lineLabel}
testID="DailyYieldRateInfoIcon"
/>
</View>
<Text style={styles.cardTitleText}>
{t('earnFlow.poolInfoScreen.ratePercent', { rate: dailyYieldRate.toFixed(4) })}
</Text>
<View style={styles.flexValue}>
<Text style={styles.lineValue}>
{t('earnFlow.poolInfoScreen.ratePercent', { rate: dailyYieldRate.toFixed(4) })}
</Text>
</View>
</View>
</View>
)
Expand All @@ -274,15 +279,17 @@
return (
<View style={styles.card} testID="TvlCard">
<View style={styles.cardLineContainer}>
<View style={styles.cardLineLabel}>
<View style={styles.flexLabel}>
<LabelWithInfo
onPress={onInfoIconPress}
label={t('earnFlow.poolInfoScreen.tvl')}
labelStyle={styles.cardTitleText}
labelStyle={styles.lineLabel}
testID="TvlInfoIcon"
/>
</View>
<Text style={styles.cardTitleText}>{tvlString}</Text>
<View style={styles.flexValue}>
<Text style={styles.lineValue}>{tvlString}</Text>
</View>
</View>
</View>
)
Expand All @@ -304,23 +311,29 @@
return (
<View style={styles.card} testID="AgeCard">
<View style={styles.cardLineContainer}>
<View style={styles.cardLineLabel}>
<View style={styles.flexLabel}>
<LabelWithInfo
onPress={onInfoIconPress}
label={t('earnFlow.poolInfoScreen.ageOfPool')}
labelStyle={styles.cardTitleText}
labelStyle={styles.lineLabel}
testID="AgeInfoIcon"
numberOfLines={undefined}
MuckT marked this conversation as resolved.
Show resolved Hide resolved
/>
</View>
<Text style={styles.cardTitleText}>{formattedDuration(dateInterval)}</Text>
<View style={styles.flexValue}>
MuckT marked this conversation as resolved.
Show resolved Hide resolved
<Text style={styles.lineValue}>{formattedDuration(dateInterval)}</Text>
</View>
</View>
</View>
)
}

export const styles = StyleSheet.create({
flexShrink: {
flexShrink: 1,
flexLabel: {
flex: 1.2,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the non-standard flex value here? Is this to make up for the lack of the paddingRight that we used to have?

Copy link
Collaborator Author

@MuckT MuckT Dec 9, 2024

Choose a reason for hiding this comment

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

This is just for spacing, as having the columns of flex 1 and 1 values appear a bit cramped and gives a bit too much room to the labels; it is the same as flex: 6 to 5, with an 11 column 11-column layout.

},
flexValue: {
flex: 1,
},
card: {
padding: Spacing.Regular16,
Expand All @@ -334,20 +347,33 @@
flexDirection: 'row',
justifyContent: 'space-between',
},
cardLineLabel: {
paddingRight: 20, // Prevents Icon from being cut off on long labels
},
yieldRateLabelContainer: {
flexDirection: 'row',
gap: Spacing.Tiny4,
},
lineLabel: {
...typeScale.labelSemiBoldMedium,
color: Colors.black,
textAlign: 'left',
},
lineValue: {
...typeScale.labelSemiBoldMedium,
color: Colors.black,
textAlign: 'right',
},
cardTitleText: {
...typeScale.labelSemiBoldMedium,
color: Colors.black,
},
cardLabelText: {
...typeScale.bodyMedium,
color: Colors.gray3,
textAlign: 'left',
},
cardValueText: {
...typeScale.bodyMedium,
color: Colors.black,
textAlign: 'right',
},
depositAndEarningCard: {
backgroundColor: Colors.gray1,
Expand Down
7 changes: 4 additions & 3 deletions src/earn/poolInfoScreen/SafetyCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@ export function SafetyCard({
const [expanded, setExpanded] = React.useState(false)
return (
<View style={cardStyles.card} testID="SafetyCard">
<View style={cardStyles.cardLineContainer}>
<View style={cardStyles.cardLineLabel}>
<View style={[cardStyles.cardLineContainer, { alignItems: 'center' }]}>
<View style={{ flex: 4 }}>
<LabelWithInfo
onPress={onInfoIconPress}
label={t('earnFlow.poolInfoScreen.safetyScore')}
labelStyle={cardStyles.cardTitleText}
testID="SafetyCardInfoIcon"
numberOfLines={1}
/>
</View>
<View style={styles.tripleBarContainer}>
<View style={[styles.tripleBarContainer, { flex: 1 }]}>
{BAR_HEIGHTS.map((height, index) => (
<View
testID="SafetyCard/Bar"
Expand Down
1 change: 1 addition & 0 deletions src/send/EnterAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export default function EnterAmount({
labelStyle={{ color: Colors.gray3 }}
testID="SendEnterAmount/FeeLabel"
style={styles.feeLabelContainer}
numberOfLines={1}
/>
<View testID="SendEnterAmount/FeeInCrypto" style={styles.feeInCryptoContainer}>
<TokenDisplay
Expand Down
Loading