Skip to content

Commit 8ce35f5

Browse files
committed
wip
1 parent b6f46ea commit 8ce35f5

File tree

2 files changed

+71
-7
lines changed

2 files changed

+71
-7
lines changed

app/components/Views/MultichainAccounts/WalletDetails/BaseWalletDetails/index.tsx

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback } from 'react';
1+
import React, { useCallback, useMemo } from 'react';
22
import { useNavigation } from '@react-navigation/native';
33
import { useStyles } from '../../../../hooks/useStyles';
44
import styleSheet from './styles';
@@ -13,17 +13,45 @@ import Icon, {
1313
IconName,
1414
} from '../../../../../component-library/components/Icons/Icon';
1515
import { AccountWallet } from '../WalletDetails';
16-
import { TouchableOpacity, View } from 'react-native';
16+
import { TouchableOpacity, View, FlatList } from 'react-native';
1717
import { WalletDetailsIds } from '../../../../../../e2e/selectors/MultichainAccounts/WalletDetails';
1818
import { AlignItems, FlexDirection } from '../../../../UI/Box/box.types';
1919
import { Box } from '../../../../UI/Box/Box';
2020
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';
2124

2225
interface BaseWalletDetailsProps {
2326
wallet: AccountWallet;
2427
children?: React.ReactNode;
2528
}
2629

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+
2755
export const BaseWalletDetails = ({
2856
wallet,
2957
children,
@@ -36,6 +64,22 @@ export const BaseWalletDetails = ({
3664
// TODO: Implement edit wallet name
3765
}, []);
3866

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+
3983
return (
4084
<SafeAreaView style={styles.safeArea}>
4185
<HeaderBase
@@ -93,6 +137,18 @@ export const BaseWalletDetails = ({
93137
</Text>
94138
</Box>
95139
</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>
96152
{children}
97153
</View>
98154
</SafeAreaView>

app/components/Views/MultichainAccounts/WalletDetails/BaseWalletDetails/styles.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,19 @@ const styleSheet = (params: { theme: Theme }) => {
5252
borderBottomLeftRadius: 8,
5353
borderBottomRightRadius: 8,
5454
},
55-
accounts: {
56-
...baseRowStyle,
57-
marginBottom: 16,
58-
borderBottomLeftRadius: 8,
59-
borderBottomRightRadius: 8,
55+
accountsList: {
56+
marginTop: 16,
57+
flex: 1,
58+
},
59+
accountsTitle: {
60+
marginBottom: 12,
61+
color: colors.text.default,
62+
},
63+
accountBox: {
64+
marginBottom: 8,
65+
backgroundColor: colors.background.alternative,
66+
borderRadius: 8,
67+
padding: 16,
6068
},
6169
text: {
6270
color: colors.text.alternative,

0 commit comments

Comments
 (0)