1
+ import ChainIndicator from '@/components/common/ChainIndicator'
2
+ import FiatValue from '@/components/common/FiatValue'
3
+ import SafeIcon from '@/components/common/SafeIcon'
4
+ import MultiAccountContextMenu from '@/components/sidebar/SafeListContextMenu/MultiAccountContextMenu'
5
+ import { AppRoutes } from '@/config/routes'
1
6
import { selectUndeployedSafes } from '@/features/counterfactual/store/undeployedSafesSlice'
7
+ import { isPredictedSafeProps } from '@/features/counterfactual/utils'
2
8
import NetworkLogosList from '@/features/multichain/components/NetworkLogosList'
3
- import { showNotification } from '@/store/notificationsSlice '
9
+ import { getSafeSetups , getSharedSetup , hasMultiChainAddNetworkFeature } from '@/features/multichain/utils/utils '
4
10
import SingleAccountItem from '@/features/myAccounts/components/AccountItems/SingleAccountItem'
5
- import type { SafeOverview } from '@safe-global/safe-gateway-typescript-sdk'
6
- import { useCallback , useMemo , useState } from 'react'
11
+ import { type SafeItem } from '@/features/myAccounts/hooks/useAllSafes'
12
+ import { type MultiChainSafeItem } from '@/features/myAccounts/hooks/useAllSafesGrouped'
13
+ import { getComparator } from '@/features/myAccounts/utils/utils'
14
+ import useHasSafenetFeature from '@/features/safenet/hooks/useHasSafenetFeature'
15
+ import useSafeAddress from '@/hooks/useSafeAddress'
16
+ import useWallet from '@/hooks/wallets/useWallet'
17
+ import BookmarkIcon from '@/public/images/apps/bookmark.svg'
18
+ import BookmarkedIcon from '@/public/images/apps/bookmarked.svg'
19
+ import SafenetLogo from '@/public/images/safenet/logo-safenet.svg'
20
+ import { OVERVIEW_EVENTS , OVERVIEW_LABELS , PIN_SAFE_LABELS , trackEvent } from '@/services/analytics'
21
+ import { useAppDispatch , useAppSelector } from '@/store'
22
+ import { addOrUpdateSafe , pinSafe , selectAllAddedSafes , unpinSafe } from '@/store/addedSafesSlice'
23
+ import { useGetMultipleSafeOverviewsQuery } from '@/store/api/gateway'
24
+ import { selectChains } from '@/store/chainsSlice'
25
+ import { showNotification } from '@/store/notificationsSlice'
26
+ import { selectOrderByPreference } from '@/store/orderByPreferenceSlice'
27
+ import { defaultSafeInfo } from '@/store/safeInfoSlice'
28
+ import { useGetSafenetAccountQuery } from '@/store/safenet'
29
+ import { selectCurrency } from '@/store/settingsSlice'
30
+ import { sameAddress } from '@/utils/addresses'
31
+ import { shortenAddress } from '@/utils/formatters'
7
32
import {
8
- ListItemButton ,
9
- Box ,
10
- Typography ,
11
- Skeleton ,
12
33
Accordion ,
13
34
AccordionDetails ,
14
35
AccordionSummary ,
36
+ Box ,
15
37
Divider ,
16
- Tooltip ,
17
- SvgIcon ,
18
38
IconButton ,
39
+ ListItemButton ,
40
+ Skeleton ,
41
+ SvgIcon ,
42
+ Tooltip ,
43
+ Typography ,
19
44
} from '@mui/material'
20
- import SafeIcon from '@/components/common/SafeIcon'
21
- import { OVERVIEW_EVENTS , OVERVIEW_LABELS , PIN_SAFE_LABELS , trackEvent } from '@/services/analytics'
22
- import { AppRoutes } from '@/config/routes'
23
- import { useAppDispatch , useAppSelector } from '@/store'
24
- import css from './styles.module.css'
25
- import useSafeAddress from '@/hooks/useSafeAddress'
26
- import { sameAddress } from '@/utils/addresses'
45
+ import type { SafeOverview } from '@safe-global/safe-gateway-typescript-sdk'
27
46
import classnames from 'classnames'
28
47
import { useRouter } from 'next/router'
29
- import FiatValue from '@/components/common/FiatValue'
30
- import { type MultiChainSafeItem } from '@/features/myAccounts/hooks/useAllSafesGrouped'
31
- import { shortenAddress } from '@/utils/formatters'
32
- import { type SafeItem } from '@/features/myAccounts/hooks/useAllSafes'
33
- import { getSafeSetups , getSharedSetup , hasMultiChainAddNetworkFeature } from '@/features/multichain/utils/utils'
48
+ import { useCallback , useMemo , useState } from 'react'
34
49
import { AddNetworkButton } from '../AddNetworkButton'
35
- import { isPredictedSafeProps } from '@/features/counterfactual/utils'
36
- import ChainIndicator from '@/components/common/ChainIndicator'
37
- import MultiAccountContextMenu from '@/components/sidebar/SafeListContextMenu/MultiAccountContextMenu'
38
- import { useGetMultipleSafeOverviewsQuery } from '@/store/api/gateway'
39
- import useWallet from '@/hooks/wallets/useWallet'
40
- import { selectCurrency } from '@/store/settingsSlice'
41
- import { selectChains } from '@/store/chainsSlice'
42
- import BookmarkIcon from '@/public/images/apps/bookmark.svg'
43
- import BookmarkedIcon from '@/public/images/apps/bookmarked.svg'
44
- import { addOrUpdateSafe , pinSafe , selectAllAddedSafes , unpinSafe } from '@/store/addedSafesSlice'
45
- import { defaultSafeInfo } from '@/store/safeInfoSlice'
46
- import { selectOrderByPreference } from '@/store/orderByPreferenceSlice'
47
- import { getComparator } from '@/features/myAccounts/utils/utils'
48
- import dynamic from 'next/dynamic'
49
-
50
- const GradientBoxSafenet = dynamic ( ( ) => import ( '@/features/safenet/components/GradientBoxSafenet' ) )
50
+ import css from './styles.module.css'
51
51
52
52
type MultiAccountItemProps = {
53
53
multiSafeAccountItem : MultiChainSafeItem
54
54
safeOverviews ?: SafeOverview [ ]
55
55
onLinkClick ?: ( ) => void
56
- isSafenetEnabled ?: boolean
56
+ hasSafenetFeature ?: boolean
57
57
}
58
58
59
- const MultichainIndicator = ( { safes } : { safes : SafeItem [ ] } ) => {
59
+ const MultichainIndicator = ( { safes, showHasSafenet = false } : { safes : SafeItem [ ] ; showHasSafenet ?: boolean } ) => {
60
60
return (
61
61
< Tooltip
62
62
title = {
@@ -72,7 +72,7 @@ const MultichainIndicator = ({ safes }: { safes: SafeItem[] }) => {
72
72
arrow
73
73
>
74
74
< Box className = { css . multiChains } >
75
- < NetworkLogosList networks = { safes } showHasMore />
75
+ < NetworkLogosList networks = { safes } showHasMore showHasSafenet = { showHasSafenet } />
76
76
</ Box >
77
77
</ Tooltip >
78
78
)
@@ -127,10 +127,26 @@ function useMultiAccountItemData(multiSafeAccountItem: MultiChainSafeItem) {
127
127
128
128
const deployedChainIds = useMemo ( ( ) => sortedSafes . map ( ( safe ) => safe . chainId ) , [ sortedSafes ] )
129
129
130
+ const hasSafenetFeature = useHasSafenetFeature ( )
131
+ const { data : safenetConfig } = useGetSafenetAccountQuery ( { safeAddress : address } , { skip : ! hasSafenetFeature } )
132
+
133
+ const usedSafenetChainIds = useMemo (
134
+ ( ) => ( safenetConfig ? safenetConfig . safes . map ( ( safe ) => safe . chainId . toString ( ) ) : [ ] ) ,
135
+ [ safenetConfig ] ,
136
+ )
137
+ const safenetSafes = useMemo (
138
+ ( ) => ( safenetConfig ? sortedSafes . filter ( ( safe ) => usedSafenetChainIds . includes ( safe . chainId ) ) : [ ] ) ,
139
+ [ safenetConfig , sortedSafes , usedSafenetChainIds ] ,
140
+ )
141
+ const nonSafenetSafes = useMemo (
142
+ ( ) => ( safenetConfig ? sortedSafes . filter ( ( safe ) => ! usedSafenetChainIds . includes ( safe . chainId ) ) : [ ] ) ,
143
+ [ safenetConfig , sortedSafes , usedSafenetChainIds ] ,
144
+ )
145
+
130
146
return {
131
147
address,
132
148
name,
133
- sortedSafes,
149
+ sortedSafes : safenetConfig ? nonSafenetSafes : sortedSafes ,
134
150
safeOverviews,
135
151
sharedSetup,
136
152
totalFiatValue,
@@ -140,6 +156,7 @@ function useMultiAccountItemData(multiSafeAccountItem: MultiChainSafeItem) {
140
156
isReadOnly,
141
157
isWelcomePage,
142
158
deployedChainIds,
159
+ safenetSafes,
143
160
}
144
161
}
145
162
@@ -217,7 +234,7 @@ function usePinActions(
217
234
return { addToPinnedList, removeFromPinnedList }
218
235
}
219
236
220
- const MultiAccountItem = ( { onLinkClick, multiSafeAccountItem, isSafenetEnabled } : MultiAccountItemProps ) => {
237
+ const MultiAccountItem = ( { onLinkClick, multiSafeAccountItem } : MultiAccountItemProps ) => {
221
238
const {
222
239
address,
223
240
name,
@@ -231,6 +248,7 @@ const MultiAccountItem = ({ onLinkClick, multiSafeAccountItem, isSafenetEnabled
231
248
isReadOnly,
232
249
isWelcomePage,
233
250
deployedChainIds,
251
+ safenetSafes,
234
252
} = useMultiAccountItemData ( multiSafeAccountItem )
235
253
const { addToPinnedList, removeFromPinnedList } = usePinActions ( address , name , sortedSafes , safeOverviews )
236
254
@@ -246,7 +264,7 @@ const MultiAccountItem = ({ onLinkClick, multiSafeAccountItem, isSafenetEnabled
246
264
} )
247
265
}
248
266
249
- const listItem = (
267
+ return (
250
268
< ListItemButton
251
269
data-testid = "safe-list-item"
252
270
selected = { isCurrentSafe }
@@ -283,7 +301,7 @@ const MultiAccountItem = ({ onLinkClick, multiSafeAccountItem, isSafenetEnabled
283
301
{ shortenAddress ( address ) }
284
302
</ Typography >
285
303
</ Typography >
286
- < MultichainIndicator safes = { sortedSafes } />
304
+ < MultichainIndicator safes = { sortedSafes } showHasSafenet = { safenetSafes . length > 0 } />
287
305
< Typography
288
306
data-testid = "group-balance"
289
307
variant = "body2"
@@ -325,6 +343,22 @@ const MultiAccountItem = ({ onLinkClick, multiSafeAccountItem, isSafenetEnabled
325
343
/>
326
344
</ AccordionSummary >
327
345
< AccordionDetails sx = { { padding : '0px 12px' } } >
346
+ { safenetSafes . length > 0 && (
347
+ < Box className = { css . safenetList } data-testid = "safenet-subacounts-container" >
348
+ < Box className = { css . safenetListHeader } >
349
+ < SafenetLogo height = "12" />
350
+ </ Box >
351
+ { safenetSafes . map ( ( safeItem ) => (
352
+ < SingleAccountItem
353
+ onLinkClick = { onLinkClick }
354
+ safeItem = { safeItem }
355
+ key = { `${ safeItem . chainId } :${ safeItem . address } ` }
356
+ isMultiChainItem
357
+ isSafenetItem
358
+ />
359
+ ) ) }
360
+ </ Box >
361
+ ) }
328
362
< Box data-testid = "subacounts-container" >
329
363
{ sortedSafes . map ( ( safeItem ) => (
330
364
< SingleAccountItem
@@ -359,11 +393,6 @@ const MultiAccountItem = ({ onLinkClick, multiSafeAccountItem, isSafenetEnabled
359
393
</ Accordion >
360
394
</ ListItemButton >
361
395
)
362
- return isSafenetEnabled ? (
363
- < GradientBoxSafenet className = { css . safenetListItem } > { listItem } </ GradientBoxSafenet >
364
- ) : (
365
- listItem
366
- )
367
396
}
368
397
369
398
export default MultiAccountItem
0 commit comments