-
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
Changes from 4 commits
fba2f80
36bd0bc
a9e27d1
0c25669
523980b
b6334b3
39209b7
f324d38
559eadb
d6bd7d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ import { useDispatch, useSelector } from 'react-redux' | |
import { hideAlert, showToast } from 'src/alert/actions' | ||
import { AssetsEvents, FiatExchangeEvents, HomeEvents } from 'src/analytics/Events' | ||
import ValoraAnalytics from 'src/analytics/ValoraAnalytics' | ||
import { toggleHideBalances } from 'src/app/actions' | ||
import { toggleHideHomeBalances } from 'src/app/actions' | ||
import { hideHomeBalancesSelector } from 'src/app/selectors' | ||
import Dialog from 'src/components/Dialog' | ||
import { formatValueToDisplay } from 'src/components/TokenDisplay' | ||
|
@@ -55,11 +55,11 @@ import { getSupportedNetworkIdsForTokenBalances } from 'src/tokens/utils' | |
function TokenBalance({ | ||
style = styles.balance, | ||
singleTokenViewEnabled = true, | ||
hideBalance = false, | ||
showHideHomeBalancesToggle = false, | ||
}: { | ||
style?: StyleProp<TextStyle> | ||
singleTokenViewEnabled?: boolean | ||
hideBalance?: boolean | ||
showHideHomeBalancesToggle?: boolean | ||
}) { | ||
const supportedNetworkIds = getSupportedNetworkIdsForTokenBalances() | ||
const tokensWithUsdValue = useTokensWithUsdValue(supportedNetworkIds) | ||
|
@@ -77,6 +77,9 @@ function TokenBalance({ | |
: undefined | ||
const { decimalSeparator } = getNumberFormatSettings() | ||
|
||
const hideBalanceSelectorReturn = useSelector(hideHomeBalancesSelector) | ||
const hideBalance = showHideHomeBalancesToggle && hideBalanceSelectorReturn | ||
|
||
const balanceDisplay = hideBalance ? `XX${decimalSeparator}XX` : totalBalanceLocal?.toFormat(2) | ||
|
||
if (tokenFetchError || tokenFetchLoading || tokensAreStale) { | ||
|
@@ -97,10 +100,13 @@ function TokenBalance({ | |
<View style={styles.oneBalance}> | ||
<Image source={{ uri: tokensWithUsdValue[0].imageUrl }} style={styles.tokenImg} /> | ||
<View style={styles.column}> | ||
<Text style={style} testID={'TotalTokenBalance'}> | ||
{!hideBalance && localCurrencySymbol} | ||
{balanceDisplay ?? '-'} | ||
</Text> | ||
<View style={styles.row}> | ||
<Text style={style} testID={'TotalTokenBalance'}> | ||
{!hideBalance && localCurrencySymbol} | ||
{balanceDisplay ?? '-'} | ||
</Text> | ||
{showHideHomeBalancesToggle && <HideBalanceButton hideBalance={hideBalance} />} | ||
</View> | ||
{!hideBalance && ( | ||
<Text style={styles.tokenBalance}> | ||
{formatValueToDisplay(tokenBalance)} {tokensWithUsdValue[0].symbol} | ||
|
@@ -111,14 +117,30 @@ function TokenBalance({ | |
) | ||
} else { | ||
return ( | ||
<Text style={style} testID={'TotalTokenBalance'}> | ||
{!hideBalance && localCurrencySymbol} | ||
{balanceDisplay ?? new BigNumber(0).toFormat(2)} | ||
</Text> | ||
<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 commentThe 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?
and then do |
||
) | ||
} | ||
} | ||
|
||
function HideBalanceButton({ hideBalance }: { hideBalance: boolean }) { | ||
const dispatch = useDispatch() | ||
const eyeIconOnPress = () => { | ||
ValoraAnalytics.track(hideBalance ? HomeEvents.show_balances : HomeEvents.hide_balances) | ||
dispatch(toggleHideHomeBalances()) | ||
} | ||
return ( | ||
<Touchable onPress={eyeIconOnPress} hitSlop={variables.iconHitslop}> | ||
{hideBalance ? <HiddenEyeIcon /> : <EyeIcon />} | ||
</Touchable> | ||
) | ||
} | ||
|
||
function useErrorMessageWithRefresh() { | ||
const { t } = useTranslation() | ||
|
||
|
@@ -218,7 +240,6 @@ export function AssetsTokenBalance({ showInfo }: { showInfo: boolean }) { | |
|
||
export function HomeTokenBalance() { | ||
const { t } = useTranslation() | ||
const dispatch = useDispatch() | ||
|
||
const totalBalance = useTotalTokenBalance() | ||
const tokenBalances = useTokensWithTokenBalance() | ||
|
@@ -242,13 +263,6 @@ export function HomeTokenBalance() { | |
|
||
const [infoVisible, setInfoVisible] = useState(false) | ||
|
||
const hideBalance = useSelector(hideHomeBalancesSelector) | ||
|
||
const eyeIconOnPress = () => { | ||
ValoraAnalytics.track(hideBalance ? HomeEvents.show_balances : HomeEvents.hide_balances) | ||
dispatch(toggleHideBalances()) | ||
} | ||
|
||
return ( | ||
<View style={styles.container} testID="HomeTokenBalance"> | ||
<View style={styles.title}> | ||
|
@@ -278,19 +292,16 @@ export function HomeTokenBalance() { | |
</TouchableOpacity> | ||
)} | ||
</View> | ||
<View style={styles.row}> | ||
<TokenBalance | ||
style={ | ||
getFeatureGate(StatsigFeatureGates.SHOW_ASSET_DETAILS_SCREEN) | ||
? styles.totalBalance | ||
: styles.balance | ||
} | ||
hideBalance={hideBalance} | ||
/> | ||
<Touchable onPress={eyeIconOnPress} hitSlop={variables.iconHitslop}> | ||
{hideBalance ? <HiddenEyeIcon /> : <EyeIcon />} | ||
</Touchable> | ||
</View> | ||
<TokenBalance | ||
style={ | ||
getFeatureGate(StatsigFeatureGates.SHOW_ASSET_DETAILS_SCREEN) | ||
? styles.totalBalance | ||
: styles.balance | ||
} | ||
showHideHomeBalancesToggle={getFeatureGate( | ||
StatsigFeatureGates.SHOW_HIDE_HOME_BALANCES_TOGGLE | ||
)} | ||
/> | ||
</View> | ||
) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import { render } from '@testing-library/react-native' | |
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { RootState } from 'src/redux/reducers' | ||
import { getFeatureGate } from 'src/statsig' | ||
import SwapFeedItem from 'src/transactions/feed/SwapFeedItem' | ||
import { | ||
Fee, | ||
|
@@ -16,6 +17,8 @@ import { mockCeurTokenId, mockCusdTokenId } from 'test/values' | |
|
||
const MOCK_TX_HASH = '0x006b866d20452a24d1d90c7514422188cc7c5d873e2f1ed661ec3f810ad5331c' | ||
|
||
jest.mock('src/statsig') | ||
|
||
jest.mock('src/web3/networkConfig', () => { | ||
const originalModule = jest.requireActual('src/web3/networkConfig') | ||
return { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. is this required? Looks like the one in beforeEach should suffice. |
||
|
||
describe('SwapFeedItem', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
jest.mocked(getFeatureGate).mockReturnValue(true) | ||
}) | ||
function renderScreen({ | ||
storeOverrides = {}, | ||
inAmount, | ||
|
@@ -117,7 +126,28 @@ describe('SwapFeedItem', () => { | |
expect(getElementText(getByTestId('SwapFeedItem/outgoingAmount'))).toEqual('-17.54 cEUR') | ||
}) | ||
|
||
it('hides balance when flag is set', async () => { | ||
it('still shows balances when feature gate false, hide balances root state true', async () => { | ||
jest.mocked(getFeatureGate).mockReturnValue(false) | ||
const { getByTestId } = renderScreen({ | ||
inAmount: { | ||
tokenId: mockCeurTokenId, | ||
value: 2.93, | ||
}, | ||
outAmount: { | ||
tokenId: mockCusdTokenId, | ||
value: 2.87, | ||
}, | ||
}) | ||
|
||
expect(getElementText(getByTestId('SwapFeedItem/title'))).toEqual('swapScreen.title') | ||
expect(getElementText(getByTestId('SwapFeedItem/subtitle'))).toEqual( | ||
'feedItemSwapPath, {"token1":"cUSD","token2":"cEUR"}' | ||
) | ||
expect(getElementText(getByTestId('SwapFeedItem/incomingAmount'))).toEqual('+2.93 cEUR') | ||
expect(getElementText(getByTestId('SwapFeedItem/outgoingAmount'))).toEqual('-2.87 cUSD') | ||
}) | ||
|
||
it('hides balance when feature gate true, root state hide home balances flag is set', async () => { | ||
const { queryByTestId } = renderScreen({ | ||
inAmount: { | ||
tokenId: mockCeurTokenId, | ||
|
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.
?
here and other places.