Skip to content

Commit

Permalink
Merge branch 'main' into chore/upgrade-assets-controllers-v37.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sahar-fehri authored Oct 30, 2024
2 parents dc26555 + a803756 commit 6cfc99f
Show file tree
Hide file tree
Showing 28 changed files with 518 additions and 102 deletions.
4 changes: 2 additions & 2 deletions .js.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export SEGMENT_FLUSH_INTERVAL="1"
export SEGMENT_FLUSH_EVENT_LIMIT="1"

# URL of security alerts API used to validate dApp requests.
export SECURITY_ALERTS_API_URL="http://localhost:3000"
export SECURITY_ALERTS_API_URL="https://security-alerts.api.cx.metamask.io"

# Temporary mechanism to enable security alerts API prior to release.
export SECURITY_ALERTS_API_ENABLED="true"
export MM_SECURITY_ALERTS_API_ENABLED="true"
# Firebase
export FCM_CONFIG_API_KEY=""
export FCM_CONFIG_AUTH_DOMAIN=""
Expand Down
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: 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
61 changes: 42 additions & 19 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 @@ -60,27 +64,46 @@ 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}
testID={`${AccountListViewSelectorsIDs.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}
testID={`${AccountListViewSelectorsIDs.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

0 comments on commit 6cfc99f

Please sign in to comment.