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

feat(3420): privacy mode toggle #11961

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const FORMATTED_VALUE_PRICE_TEST_ID = 'formatted-value-price-test-id';
export const FORMATTED_PERCENTAGE_TEST_ID = 'formatted-percentage-test-id';
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import AggregatedPercentage from './AggregatedPercentage';
import { mockTheme } from '../../../../util/theme';
import { useSelector } from 'react-redux';
import { selectCurrentCurrency } from '../../../../selectors/currencyRateController';
import {
FORMATTED_VALUE_PRICE_TEST_ID,
FORMATTED_PERCENTAGE_TEST_ID,
} from './AggregatedPercentage.constants';

jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
Expand Down Expand Up @@ -65,4 +69,22 @@ describe('AggregatedPercentage', () => {
color: mockTheme.colors.error.default,
});
});

it('renders correctly with privacy mode on', () => {
const { getByTestId } = render(
<AggregatedPercentage
ethFiat={150}
tokenFiat={200}
tokenFiat1dAgo={300}
ethFiat1dAgo={200}
privacyMode
/>,
);

const formattedPercentage = getByTestId(FORMATTED_PERCENTAGE_TEST_ID);
const formattedValuePrice = getByTestId(FORMATTED_VALUE_PRICE_TEST_ID);

expect(formattedPercentage.props.children).toBe('••••••••••');
expect(formattedValuePrice.props.children).toBe('••••••••••');
});
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import React from 'react';
import Text, {
import {
TextColor,
TextVariant,
} from '../../../../component-library/components/Texts/Text';
import SensitiveText from '../../../../component-library/components/Texts/SensitiveText';
import { View } from 'react-native';
import { renderFiat } from '../../../../util/number';
import { useSelector } from 'react-redux';
import { selectCurrentCurrency } from '../../../../selectors/currencyRateController';
import styleSheet from './AggregatedPercentage.styles';
import { useStyles } from '../../../hooks';
import {
FORMATTED_VALUE_PRICE_TEST_ID,
FORMATTED_PERCENTAGE_TEST_ID,
} from './AggregatedPercentage.constants';

export interface AggregatedPercentageProps {
ethFiat: number;
Expand All @@ -25,11 +30,13 @@ const AggregatedPercentage = ({
tokenFiat,
tokenFiat1dAgo,
ethFiat1dAgo,
privacyMode = false,
}: {
ethFiat: number;
tokenFiat: number;
tokenFiat1dAgo: number;
ethFiat1dAgo: number;
privacyMode?: boolean;
}) => {
const { styles } = useStyles(styleSheet, {});

Expand All @@ -46,12 +53,16 @@ const AggregatedPercentage = ({

let percentageTextColor = TextColor.Default;

if (percentageChange === 0) {
percentageTextColor = TextColor.Default;
} else if (percentageChange > 0) {
percentageTextColor = TextColor.Success;
if (!privacyMode) {
if (percentageChange === 0) {
percentageTextColor = TextColor.Default;
} else if (percentageChange > 0) {
percentageTextColor = TextColor.Success;
} else {
percentageTextColor = TextColor.Error;
}
} else {
percentageTextColor = TextColor.Error;
percentageTextColor = TextColor.Alternative;
}

const formattedPercentage = isValidAmount(percentageChange)
Expand All @@ -70,12 +81,24 @@ const AggregatedPercentage = ({

return (
<View style={styles.wrapper}>
<Text color={percentageTextColor} variant={TextVariant.BodyMDMedium}>
<SensitiveText
isHidden={privacyMode}
length="10"
color={percentageTextColor}
variant={TextVariant.BodyMDMedium}
testID={FORMATTED_VALUE_PRICE_TEST_ID}
>
{formattedValuePrice}
</Text>
<Text color={percentageTextColor} variant={TextVariant.BodyMDMedium}>
</SensitiveText>
<SensitiveText
isHidden={privacyMode}
length="10"
color={percentageTextColor}
variant={TextVariant.BodyMDMedium}
testID={FORMATTED_PERCENTAGE_TEST_ID}
>
{formattedPercentage}
</Text>
</SensitiveText>
</View>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ exports[`AggregatedPercentage should render correctly 1`] = `
"lineHeight": 22,
}
}
testID="formatted-value-price-test-id"
>
+20 USD
</Text>
Expand All @@ -36,6 +37,7 @@ exports[`AggregatedPercentage should render correctly 1`] = `
"lineHeight": 22,
}
}
testID="formatted-percentage-test-id"
>
(+11.11%)
</Text>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// External dependencies.
import React from 'react';
import { TextProps } from '../Text/Text.types';

/**
Expand Down Expand Up @@ -42,5 +43,5 @@ export interface SensitiveTextProps extends TextProps {
/**
* The text content to be displayed or hidden.
*/
children: string;
children: string | React.ReactNode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const styleSheet = () =>
StyleSheet.create({
balancesContainer: {
alignItems: 'flex-end',
flexDirection: 'column',
},
balanceLabel: { textAlign: 'right' },
});
Expand Down
68 changes: 46 additions & 22 deletions app/components/UI/AccountSelectorList/AccountSelectorList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import Cell, {
CellVariant,
} from '../../../component-library/components/Cells/Cell';
import { useStyles } from '../../../component-library/hooks';
import Text from '../../../component-library/components/Texts/Text';
import { selectPrivacyMode } from '../../../selectors/preferencesController';
import { TextColor } from '../../../component-library/components/Texts/Text';
import SensitiveText, {
SensitiveTextLength,
} from '../../../component-library/components/Texts/SensitiveText';
import AvatarGroup from '../../../component-library/components/Avatars/AvatarGroup';
import {
formatAddress,
Expand Down Expand Up @@ -61,30 +65,50 @@ const AccountSelectorList = ({
? AvatarAccountType.Blockies
: AvatarAccountType.JazzIcon,
);

const privacyMode = useSelector(selectPrivacyMode);
const getKeyExtractor = ({ address }: Account) => address;

const renderAccountBalances = useCallback(
({ fiatBalance, tokens }: Assets, address: string) => (
<View
style={styles.balancesContainer}
{...generateTestId(
Platform,
`${ACCOUNT_BALANCE_BY_ADDRESS_TEST_ID}-${address}`,
)}
>
<Text style={styles.balanceLabel}>{fiatBalance}</Text>
{tokens && (
<AvatarGroup
avatarPropsList={tokens.map((tokenObj) => ({
...tokenObj,
variant: AvatarVariant.Token,
}))}
/>
)}
</View>
),
[styles.balancesContainer, styles.balanceLabel],
({ fiatBalance, tokens }: Assets, address: string) => {
const fiatBalanceStrSplit = fiatBalance.split('\n');
const fiatBalanceAmount = fiatBalanceStrSplit[0] || '';
const tokenTicker = fiatBalanceStrSplit[1] || '';

return (
<View
style={styles.balancesContainer}
{...generateTestId(
Platform,
`${ACCOUNT_BALANCE_BY_ADDRESS_TEST_ID}-${address}`,
)}
>
<SensitiveText
length={SensitiveTextLength.Long}
style={styles.balanceLabel}
isHidden={privacyMode}
>
{fiatBalanceAmount}
</SensitiveText>
<SensitiveText
length={SensitiveTextLength.Short}
style={styles.balanceLabel}
isHidden={privacyMode}
color={privacyMode ? TextColor.Alternative : TextColor.Default}
>
{tokenTicker}
</SensitiveText>
{tokens && (
<AvatarGroup
avatarPropsList={tokens.map((tokenObj) => ({
...tokenObj,
variant: AvatarVariant.Token,
}))}
/>
)}
</View>
);
},
[styles.balancesContainer, styles.balanceLabel, privacyMode],
);

const onLongPress = useCallback(
Expand Down
Loading
Loading