Skip to content

Commit 2221419

Browse files
committed
memoize icon type
1 parent 1155fc9 commit 2221419

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

app/components/UI/AccountSelectorList/AccountSelectorList.tsx

+10-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Third party dependencies.
22
import React, { useCallback, useRef } from 'react';
33
import { Alert, View, ViewStyle } from 'react-native';
4-
import { useSelector } from 'react-redux';
4+
import { useSelector, shallowEqual } from 'react-redux';
55
import { useNavigation } from '@react-navigation/native';
66
import { KeyringTypes } from '@metamask/keyring-controller';
77

@@ -39,6 +39,7 @@ import { AccountListBottomSheetSelectorsIDs } from '../../../../e2e/selectors/wa
3939
import { WalletViewSelectorsIDs } from '../../../../e2e/selectors/wallet/WalletView.selectors';
4040
import { ESTIMATED_CELL_ITEM_HEIGHT } from '../../Views/AccountSelector/AccountSelector.styles';
4141
import { ScrollView } from 'react-native-gesture-handler';
42+
import { RootState } from '../../../reducers';
4243

4344
const AccountSelectorList = ({
4445
onSelectAccount,
@@ -60,12 +61,12 @@ const AccountSelectorList = ({
6061
const accountListRef = useRef<FlashList<Account>>(null);
6162
const accountsLengthRef = useRef<number>(0);
6263
const { styles } = useStyles(styleSheet, {});
63-
// TODO: Replace "any" with type
64-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
65-
const accountAvatarType = useSelector((state: any) =>
66-
state.settings.useBlockieIcon
67-
? AvatarAccountType.Blockies
68-
: AvatarAccountType.JazzIcon,
64+
const accountAvatarType = useSelector(
65+
(state: RootState) =>
66+
state.settings.useBlockieIcon
67+
? AvatarAccountType.Blockies
68+
: AvatarAccountType.JazzIcon,
69+
shallowEqual,
6970
);
7071

7172
const internalAccounts = useSelector(selectInternalAccounts);
@@ -291,23 +292,12 @@ const AccountSelectorList = ({
291292
);
292293

293294
const onContentSizeChanged = useCallback(() => {
294-
// Handle auto scroll to account
295+
// Handle auto scroll to account - only needed for when accounts change after initial render
295296
if (!accounts.length || !isAutoScrollEnabled) return;
296297
if (accountsLengthRef.current !== accounts.length) {
297-
const selectedAddressOverride = selectedAddresses?.[0];
298-
const account = accounts.find(({ isSelected, address }) =>
299-
selectedAddressOverride
300-
? safeToChecksumAddress(selectedAddressOverride) ===
301-
safeToChecksumAddress(address)
302-
: isSelected,
303-
);
304-
accountListRef?.current?.scrollToOffset({
305-
offset: account?.yOffset ?? 0,
306-
animated: false,
307-
});
308298
accountsLengthRef.current = accounts.length;
309299
}
310-
}, [accounts, selectedAddresses, isAutoScrollEnabled]);
300+
}, [accounts, isAutoScrollEnabled]);
311301

312302
return (
313303
<FlashList
@@ -317,8 +307,6 @@ const AccountSelectorList = ({
317307
keyExtractor={getKeyExtractor}
318308
renderItem={renderAccountItem}
319309
estimatedItemSize={ESTIMATED_CELL_ITEM_HEIGHT}
320-
// Increasing number of items at initial render fixes scroll issue.
321-
// initialNumToRender={999}
322310
renderScrollComponent={ScrollView}
323311
{...props}
324312
/>

0 commit comments

Comments
 (0)