-
Notifications
You must be signed in to change notification settings - Fork 97
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
chore: add feature gate for hide balances, fix eye icon alignment #4431
Conversation
Codecov Report
@@ Coverage Diff @@
## main #4431 +/- ##
==========================================
+ Coverage 85.08% 85.10% +0.02%
==========================================
Files 711 711
Lines 26389 26400 +11
Branches 3577 3580 +3
==========================================
+ Hits 22453 22468 +15
+ Misses 3873 3869 -4
Partials 63 63
... and 2 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there should be tests that verify the toggle goes away and balances are shown if the feature flag is shut off, even if the hide home balances selector gives a falsy result (so users don't get stuck with their assets hidden if we turn off the hide home balances button for some reason).
Also, right now it looks like there aren't tests for the case where the feature flag is turned off.
src/components/TokenBalance.tsx
Outdated
@@ -285,11 +289,13 @@ export function HomeTokenBalance() { | |||
? styles.totalBalance | |||
: styles.balance | |||
} | |||
hideBalance={hideBalance} | |||
hideBalance={showHideHomeBalancesToggle ? hideBalance : false} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok this was clever, I'm not sure I would've thought of that. If we turn off the hide home balances toggle, we need to avoid getting some users into a state where they can't un-hide their balances. Nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hideBalance={showHideHomeBalancesToggle ? hideBalance : false} | |
hideBalance={showHideHomeBalancesToggle && hideBalance} |
code golf
const hideBalanceSelectorReturn = useSelector(hideHomeBalancesSelector) | ||
const hideBalance = getFeatureGate(StatsigFeatureGates.SHOW_HIDE_HOME_BALANCES_TOGGLE) | ||
? hideBalanceSelectorReturn | ||
: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const hideBalanceSelectorReturn = useSelector(hideHomeBalancesSelector) | |
const hideBalance = getFeatureGate(StatsigFeatureGates.SHOW_HIDE_HOME_BALANCES_TOGGLE) | |
? hideBalanceSelectorReturn | |
: false | |
const hideBalanceSelectorReturn = useSelector(hideHomeBalancesSelector) | |
const hideBalance = getFeatureGate(StatsigFeatureGates.SHOW_HIDE_HOME_BALANCES_TOGGLE) && hideBalanceSelectorReturn |
code golf
const hideBalance = getFeatureGate(StatsigFeatureGates.SHOW_HIDE_HOME_BALANCES_TOGGLE) | ||
? hideBalanceSelectorReturn | ||
: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const hideBalance = getFeatureGate(StatsigFeatureGates.SHOW_HIDE_HOME_BALANCES_TOGGLE) | |
? hideBalanceSelectorReturn | |
: false | |
const hideBalance = getFeatureGate(StatsigFeatureGates.SHOW_HIDE_HOME_BALANCES_TOGGLE) && hideBalanceSelectorReturn |
code golf
src/components/TokenBalance.tsx
Outdated
@@ -77,6 +77,9 @@ function TokenBalance({ | |||
: undefined | |||
const { decimalSeparator } = getNumberFormatSettings() | |||
|
|||
const hideBalanceSelectorReturn = useSelector(hideHomeBalancesSelector) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const hideBalanceSelectorReturn = useSelector(hideHomeBalancesSelector) | |
const hideHomeBalanceState = useSelector(hideHomeBalancesSelector) |
?
here and other places.
src/components/TokenBalance.tsx
Outdated
<View style={styles.row}> | ||
<Text style={style} testID={'TotalTokenBalance'}> | ||
{!hideBalance && localCurrencySymbol} | ||
{balanceDisplay ?? new BigNumber(0).toFormat(2)} | ||
</Text> | ||
{showHideHomeBalancesToggle && <HideBalanceButton hideBalance={hideBalance} />} | ||
</View> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like a lot of boolean expressions are duplicated. Maybe you can make this DRY by having an inner render instead of just balance display?
E.g.,
const renderTotalTokenBalance(default: string) = (
<View style={styles.row}>
<Text style={style} testID={'TotalTokenBalance'}>
{!hideBalance && localCurrencySymbol}
{hideBalance ? `XX${decimalSeparator}XX` : totalBalanceLocal?.toFormat(2) ?? default}
</Text>
{showHideHomeBalancesToggle && <HideBalanceButton hideBalance={hideBalance} />}
</View>
)
and then do renderTotalTokenBalance('-')
and renderTotalTokenBalance(new BigNumber(0).toFormat(2))
in the two places. Also not sure why one uses 0 and other -
for the default.
@@ -32,7 +35,13 @@ jest.mock('src/web3/networkConfig', () => { | |||
} | |||
}) | |||
|
|||
jest.mocked(getFeatureGate).mockReturnValue(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this required? Looks like the one in beforeEach should suffice.
src/components/TokenBalance.tsx
Outdated
const balanceDisplay = hideBalance ? `XX${decimalSeparator}XX` : totalBalanceLocal?.toFormat(2) | ||
|
||
if (tokenFetchError || tokenFetchLoading || tokensAreStale) { | ||
// Show '-' if we haven't fetched the tokens yet or prices are stale | ||
const RenderTotalTokenBalance = ({ balanceDisplay }: { balanceDisplay: string }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non blocking naming nit: I think we use render prefix if we call this as a function. Since its used as a component, you can drop the Render prefix
Description
Add feature gate for the hide balances toggle, also make naming consistent and fix alignment issue with eye icon.
Test plan
Updated unit tests
Feature gate false:
Feature gate true:
Eye icon for single token (now aligned with total):
Eye icon for multiple balances combined into total (same as before):
Related issues
N/A
Backwards compatibility
Yes