1
1
// Third party dependencies.
2
2
import React , { useCallback , useRef } from 'react' ;
3
3
import { Alert , View , ViewStyle } from 'react-native' ;
4
- import { useSelector } from 'react-redux' ;
4
+ import { useSelector , shallowEqual } from 'react-redux' ;
5
5
import { useNavigation } from '@react-navigation/native' ;
6
6
import { KeyringTypes } from '@metamask/keyring-controller' ;
7
7
@@ -39,6 +39,7 @@ import { AccountListBottomSheetSelectorsIDs } from '../../../../e2e/selectors/wa
39
39
import { WalletViewSelectorsIDs } from '../../../../e2e/selectors/wallet/WalletView.selectors' ;
40
40
import { ESTIMATED_CELL_ITEM_HEIGHT } from '../../Views/AccountSelector/AccountSelector.styles' ;
41
41
import { ScrollView } from 'react-native-gesture-handler' ;
42
+ import { RootState } from '../../../reducers' ;
42
43
43
44
const AccountSelectorList = ( {
44
45
onSelectAccount,
@@ -60,12 +61,12 @@ const AccountSelectorList = ({
60
61
const accountListRef = useRef < FlashList < Account > > ( null ) ;
61
62
const accountsLengthRef = useRef < number > ( 0 ) ;
62
63
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 ,
69
70
) ;
70
71
71
72
const internalAccounts = useSelector ( selectInternalAccounts ) ;
@@ -291,23 +292,12 @@ const AccountSelectorList = ({
291
292
) ;
292
293
293
294
const onContentSizeChanged = useCallback ( ( ) => {
294
- // Handle auto scroll to account
295
+ // Handle auto scroll to account - only needed for when accounts change after initial render
295
296
if ( ! accounts . length || ! isAutoScrollEnabled ) return ;
296
297
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
- } ) ;
308
298
accountsLengthRef . current = accounts . length ;
309
299
}
310
- } , [ accounts , selectedAddresses , isAutoScrollEnabled ] ) ;
300
+ } , [ accounts , isAutoScrollEnabled ] ) ;
311
301
312
302
return (
313
303
< FlashList
@@ -317,8 +307,6 @@ const AccountSelectorList = ({
317
307
keyExtractor = { getKeyExtractor }
318
308
renderItem = { renderAccountItem }
319
309
estimatedItemSize = { ESTIMATED_CELL_ITEM_HEIGHT }
320
- // Increasing number of items at initial render fixes scroll issue.
321
- // initialNumToRender={999}
322
310
renderScrollComponent = { ScrollView }
323
311
{ ...props }
324
312
/>
0 commit comments