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

chore: add feature gate for hide balances, fix eye icon alignment #4431

Merged
merged 10 commits into from
Nov 8, 2023

Conversation

finnian0826
Copy link
Contributor

@finnian0826 finnian0826 commented Nov 3, 2023

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_false

Feature gate true:
feature_gate_true

Eye icon for single token (now aligned with total):
single token

Eye icon for multiple balances combined into total (same as before):
multiple tokens

Related issues

N/A

Backwards compatibility

Yes

Copy link

codecov bot commented Nov 3, 2023

Codecov Report

Merging #4431 (d6bd7d2) into main (6c99205) will increase coverage by 0.02%.
The diff coverage is 96.87%.

Impacted file tree graph

@@            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              
Files Coverage Δ
src/app/actions.ts 96.25% <100.00%> (ø)
src/components/TokenBalance.tsx 96.62% <100.00%> (+0.09%) ⬆️
src/statsig/constants.ts 100.00% <ø> (ø)
src/statsig/types.ts 100.00% <100.00%> (ø)
src/transactions/feed/SwapFeedItem.tsx 94.11% <100.00%> (+0.56%) ⬆️
src/transactions/feed/TransferFeedItem.tsx 94.73% <100.00%> (+0.45%) ⬆️
src/app/reducers.ts 20.27% <0.00%> (ø)

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6c99205...d6bd7d2. Read the comment docs.

@finnian0826 finnian0826 marked this pull request as ready for review November 3, 2023 15:46
MuckT
MuckT previously approved these changes Nov 3, 2023
Copy link
Contributor

@cajubelt cajubelt left a 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.

@@ -285,11 +289,13 @@ export function HomeTokenBalance() {
? styles.totalBalance
: styles.balance
}
hideBalance={hideBalance}
hideBalance={showHideHomeBalancesToggle ? hideBalance : false}
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
hideBalance={showHideHomeBalancesToggle ? hideBalance : false}
hideBalance={showHideHomeBalancesToggle && hideBalance}

code golf

Comment on lines 35 to 38
const hideBalanceSelectorReturn = useSelector(hideHomeBalancesSelector)
const hideBalance = getFeatureGate(StatsigFeatureGates.SHOW_HIDE_HOME_BALANCES_TOGGLE)
? hideBalanceSelectorReturn
: false
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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

Comment on lines 44 to 46
const hideBalance = getFeatureGate(StatsigFeatureGates.SHOW_HIDE_HOME_BALANCES_TOGGLE)
? hideBalanceSelectorReturn
: false
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const hideBalance = getFeatureGate(StatsigFeatureGates.SHOW_HIDE_HOME_BALANCES_TOGGLE)
? hideBalanceSelectorReturn
: false
const hideBalance = getFeatureGate(StatsigFeatureGates.SHOW_HIDE_HOME_BALANCES_TOGGLE) && hideBalanceSelectorReturn

code golf

@finnian0826 finnian0826 changed the title chore: add feature gate for hide balances chore: add feature gate for hide balances, fix eye icon alignment Nov 6, 2023
@@ -77,6 +77,9 @@ function TokenBalance({
: undefined
const { decimalSeparator } = getNumberFormatSettings()

const hideBalanceSelectorReturn = useSelector(hideHomeBalancesSelector)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const hideBalanceSelectorReturn = useSelector(hideHomeBalancesSelector)
const hideHomeBalanceState = useSelector(hideHomeBalancesSelector)

?
here and other places.

Comment on lines 120 to 126
<View style={styles.row}>
<Text style={style} testID={'TotalTokenBalance'}>
{!hideBalance && localCurrencySymbol}
{balanceDisplay ?? new BigNumber(0).toFormat(2)}
</Text>
{showHideHomeBalancesToggle && <HideBalanceButton hideBalance={hideBalance} />}
</View>
Copy link
Contributor

@satish-ravi satish-ravi Nov 6, 2023

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)
Copy link
Contributor

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.

@MuckT MuckT self-requested a review November 7, 2023 16:36
@MuckT MuckT dismissed their stale review November 7, 2023 16:36

Changes since last review

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 }) => {
Copy link
Contributor

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

@finnian0826 finnian0826 merged commit 8242a73 into main Nov 8, 2023
16 checks passed
@finnian0826 finnian0826 deleted the finnian0826/hide-balances-feature-gate branch November 8, 2023 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants