1
- import React , { useCallback } from 'react' ;
1
+ import React , { useCallback , useMemo } from 'react' ;
2
2
import { useNavigation } from '@react-navigation/native' ;
3
3
import { useStyles } from '../../../../hooks/useStyles' ;
4
4
import styleSheet from './styles' ;
@@ -13,17 +13,45 @@ import Icon, {
13
13
IconName ,
14
14
} from '../../../../../component-library/components/Icons/Icon' ;
15
15
import { AccountWallet } from '../WalletDetails' ;
16
- import { TouchableOpacity , View } from 'react-native' ;
16
+ import { TouchableOpacity , View , FlatList } from 'react-native' ;
17
17
import { WalletDetailsIds } from '../../../../../../e2e/selectors/MultichainAccounts/WalletDetails' ;
18
18
import { AlignItems , FlexDirection } from '../../../../UI/Box/box.types' ;
19
19
import { Box } from '../../../../UI/Box/Box' ;
20
20
import { strings } from '../../../../../../locales/i18n' ;
21
+ import { InternalAccount } from '@metamask/keyring-internal-api' ;
22
+ import { AccountId } from '@metamask/accounts-controller' ;
23
+ import Engine from '../../../../../core/Engine' ;
21
24
22
25
interface BaseWalletDetailsProps {
23
26
wallet : AccountWallet ;
24
27
children ?: React . ReactNode ;
25
28
}
26
29
30
+ /**
31
+ * Fetches internal accounts from the AccountsController based on the wallet's account IDs
32
+ * @param wallet - The wallet containing account IDs to fetch
33
+ * @returns Array of internal accounts
34
+ */
35
+ const getInternalAccountsFromWallet = (
36
+ wallet : AccountWallet ,
37
+ ) : InternalAccount [ ] => {
38
+ const { AccountsController } = Engine . context ;
39
+ const { accounts } = AccountsController . state . internalAccounts ;
40
+
41
+ // Extract all account IDs from the wallet's groups
42
+ const accountIds : AccountId [ ] = [ ] ;
43
+ Object . values ( wallet . groups ) . forEach ( ( group ) => {
44
+ accountIds . push ( ...group . accounts ) ;
45
+ } ) ;
46
+
47
+ // Fetch internal accounts for each account ID
48
+ const internalAccounts = accountIds
49
+ . map ( ( accountId ) => accounts [ accountId ] )
50
+ . filter ( ( account ) : account is InternalAccount => account !== undefined ) ;
51
+
52
+ return internalAccounts ;
53
+ } ;
54
+
27
55
export const BaseWalletDetails = ( {
28
56
wallet,
29
57
children,
@@ -36,6 +64,22 @@ export const BaseWalletDetails = ({
36
64
// TODO: Implement edit wallet name
37
65
} , [ ] ) ;
38
66
67
+ // Get internal accounts from the wallet
68
+ const accounts = useMemo (
69
+ ( ) => getInternalAccountsFromWallet ( wallet ) ,
70
+ [ wallet ] ,
71
+ ) ;
72
+
73
+ const renderAccountItem = ( { item : account } : { item : InternalAccount } ) => (
74
+ < View style = { styles . accountBox } >
75
+ < Box flexDirection = { FlexDirection . Row } alignItems = { AlignItems . center } >
76
+ < Text variant = { TextVariant . BodyMDMedium } > { account . metadata . name } </ Text >
77
+ </ Box >
78
+ </ View >
79
+ ) ;
80
+
81
+ const keyExtractor = ( item : InternalAccount ) => item . id ;
82
+
39
83
return (
40
84
< SafeAreaView style = { styles . safeArea } >
41
85
< HeaderBase
@@ -93,6 +137,18 @@ export const BaseWalletDetails = ({
93
137
</ Text >
94
138
</ Box >
95
139
</ View >
140
+ < View style = { styles . accountsList } >
141
+ < Text variant = { TextVariant . BodyMDMedium } style = { styles . accountsTitle } >
142
+ Accounts
143
+ </ Text >
144
+ < FlatList
145
+ data = { accounts }
146
+ keyExtractor = { keyExtractor }
147
+ renderItem = { renderAccountItem }
148
+ showsVerticalScrollIndicator = { false }
149
+ scrollEnabled = { false }
150
+ />
151
+ </ View >
96
152
{ children }
97
153
</ View >
98
154
</ SafeAreaView >
0 commit comments