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

fix(12945): privacy mode and account selection bottom sheet #12989

Merged
merged 1 commit into from
Jan 15, 2025
Merged
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
6 changes: 5 additions & 1 deletion app/components/UI/Ramp/components/AccountSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ const AccountSelector = () => {
const selectedInternalAccount = useSelector(selectSelectedInternalAccount);

const openAccountSelector = () =>
navigation.navigate(...createAccountSelectorNavDetails());
navigation.navigate(
...createAccountSelectorNavDetails({
disablePrivacyMode: true,
}),
);

return (
<SelectorButton onPress={openAccountSelector} style={styles.selector}>
Expand Down
57 changes: 0 additions & 57 deletions app/components/UI/WalletAccount/WalletAccount.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import renderWithProvider, {
DeepPartial,
} from '../../../util/test/renderWithProvider';
import ClipboardManager from '../../../core/ClipboardManager';
import { createAccountSelectorNavDetails } from '../../../components/Views/AccountSelector';
import { backgroundState } from '../../../util/test/initial-root-state';
import { Account } from '../../hooks/useAccounts';
import {
Expand Down Expand Up @@ -134,19 +133,6 @@ describe('WalletAccount', () => {
fireEvent.press(getByTestId(WalletViewSelectorsIDs.ACCOUNT_COPY_BUTTON));
expect(ClipboardManager.setString).toHaveBeenCalledTimes(1);
});

it('should navigate to the account selector screen on account press', () => {
vinnyhoward marked this conversation as resolved.
Show resolved Hide resolved
const { getByTestId } = renderWithProvider(<WalletAccount />, {
state: mockInitialState,
});

fireEvent.press(getByTestId(WalletViewSelectorsIDs.ACCOUNT_ICON));
expect(mockNavigate).toHaveBeenCalledWith(
...createAccountSelectorNavDetails({
privacyMode: false,
}),
);
});
it('displays the correct account name', () => {
const { getByText } = renderWithProvider(<WalletAccount />, {
state: mockInitialState,
Expand Down Expand Up @@ -176,47 +162,4 @@ describe('WalletAccount', () => {
expect(getByText(customAccountName)).toBeDefined();
});
});

it('should navigate to account selector with privacy mode disabled', () => {
const { getByTestId } = renderWithProvider(<WalletAccount />, {
state: mockInitialState,
});

fireEvent.press(getByTestId(WalletViewSelectorsIDs.ACCOUNT_ICON));
expect(mockNavigate).toHaveBeenCalledWith(
...createAccountSelectorNavDetails({
privacyMode: false,
}),
);
});

it('should navigate to account selector with privacy mode enabled', () => {
const stateWithPrivacyMode = {
...mockInitialState,
engine: {
...mockInitialState.engine,
backgroundState: {
...mockInitialState.engine?.backgroundState,
PreferencesController: {
privacyMode: true,
},
},
},
};

mockSelector.mockImplementation((callback) =>
callback(stateWithPrivacyMode),
);

const { getByTestId } = renderWithProvider(<WalletAccount />, {
state: stateWithPrivacyMode,
});

fireEvent.press(getByTestId(WalletViewSelectorsIDs.ACCOUNT_ICON));
expect(mockNavigate).toHaveBeenCalledWith(
...createAccountSelectorNavDetails({
privacyMode: true,
}),
);
});
});
8 changes: 1 addition & 7 deletions app/components/UI/WalletAccount/WalletAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useNavigation } from '@react-navigation/native';
import { View } from 'react-native';

// External dependencies
import { selectPrivacyMode } from '../../../selectors/preferencesController';
import { IconName } from '../../../component-library/components/Icons/Icon';
import PickerAccount from '../../../component-library/components/Pickers/PickerAccount';
import { AvatarAccountType } from '../../../component-library/components/Avatars/Avatar/variants/AvatarAccount';
Expand Down Expand Up @@ -38,7 +37,6 @@ const WalletAccount = ({ style }: WalletAccountProps, ref: React.Ref<any>) => {
const yourAccountRef = useRef(null);
const accountActionsRef = useRef(null);
const selectedAccount = useSelector(selectSelectedInternalAccount);
const privacyMode = useSelector(selectPrivacyMode);
const { ensName } = useEnsNameByAddress(selectedAccount?.address);
const defaultName = selectedAccount?.metadata?.name;
const accountName = useMemo(
Expand Down Expand Up @@ -88,11 +86,7 @@ const WalletAccount = ({ style }: WalletAccountProps, ref: React.Ref<any>) => {
tags: getTraceTags(store.getState()),
op: TraceOperation.AccountList,
});
navigate(
vinnyhoward marked this conversation as resolved.
Show resolved Hide resolved
...createAccountSelectorNavDetails({
privacyMode,
}),
);
navigate(...createAccountSelectorNavDetails());
}}
accountTypeLabel={
getLabelTextByAddress(selectedAccount?.address) || undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const mockInitialState = {
},
},
},
PreferencesController: {
privacyMode: false,
},
},
},
accounts: {
Expand Down Expand Up @@ -101,7 +104,7 @@ const mockRoute: AccountSelectorProps['route'] = {
params: {
onSelectAccount: jest.fn((address: string) => address),
checkBalanceError: (balance: string) => balance,
privacyMode: false,
disablePrivacyMode: false,
} as AccountSelectorParams,
};

Expand Down
12 changes: 9 additions & 3 deletions app/components/Views/AccountSelector/AccountSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import Button, {
} from '../../../component-library/components/Buttons/Button';
import AddAccountActions from '../AddAccountActions';
import { AccountListBottomSheetSelectorsIDs } from '../../../../e2e/selectors/wallet/AccountListBottomSheet.selectors';
import { selectPrivacyMode } from '../../../selectors/preferencesController';

// Internal dependencies.
import {
AccountSelectorProps,
Expand All @@ -40,13 +42,14 @@ import { TraceName, endTrace } from '../../../util/trace';
const AccountSelector = ({ route }: AccountSelectorProps) => {
const dispatch = useDispatch();
const { trackEvent, createEventBuilder } = useMetrics();
const { onSelectAccount, checkBalanceError, privacyMode } =
const { onSelectAccount, checkBalanceError, disablePrivacyMode } =
route.params || {};

const { reloadAccounts } = useSelector((state: RootState) => state.accounts);
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const Engine = UntypedEngine as any;
const privacyMode = useSelector(selectPrivacyMode);
const sheetRef = useRef<BottomSheetRef>(null);
const { accounts, ensByAccountAddress } = useAccounts({
checkBalanceError,
Expand Down Expand Up @@ -100,7 +103,7 @@ const AccountSelector = ({ route }: AccountSelectorProps) => {
accounts={accounts}
ensByAccountAddress={ensByAccountAddress}
isRemoveAccountEnabled
privacyMode={privacyMode}
privacyMode={privacyMode && !disablePrivacyMode}
testID={AccountListBottomSheetSelectorsIDs.ACCOUNT_LIST_ID}
/>
<View style={styles.sheet}>
Expand All @@ -110,7 +113,9 @@ const AccountSelector = ({ route }: AccountSelectorProps) => {
width={ButtonWidthTypes.Full}
size={ButtonSize.Lg}
onPress={() => setScreen(AccountSelectorScreens.AddAccountActions)}
testID={AccountListBottomSheetSelectorsIDs.ACCOUNT_LIST_ADD_BUTTON_ID}
testID={
AccountListBottomSheetSelectorsIDs.ACCOUNT_LIST_ADD_BUTTON_ID
}
/>
</View>
</Fragment>
Expand All @@ -121,6 +126,7 @@ const AccountSelector = ({ route }: AccountSelectorProps) => {
ensByAccountAddress,
onRemoveImportedAccount,
privacyMode,
disablePrivacyMode,
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export interface AccountSelectorParams {
*/
checkBalanceError?: UseAccountsParams['checkBalanceError'];
/**
* Optional boolean to indicate if privacy mode is enabled.
* Optional boolean to indicate if privacy mode is disabled.
*/
privacyMode?: boolean;
disablePrivacyMode?: boolean;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const SendFlowAddressFrom = ({
params: {
isSelectOnly: true,
onSelectAccount,
disablePrivacyMode: true,
vinnyhoward marked this conversation as resolved.
Show resolved Hide resolved
},
});
};
Expand Down
Loading