Skip to content

Commit

Permalink
Convert Subaccount list to correct elements
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Nov 28, 2024
1 parent e5c50ac commit dc5bb92
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 29 deletions.
79 changes: 50 additions & 29 deletions src/components/sidebar/SubaccountsList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import EthHashInfo from '@/components/common/EthHashInfo'
import Track from '@/components/common/Track'
import { SUBACCOUNT_EVENTS } from '@/services/analytics/events/subaccounts'
import { SUBACCOUNT_EVENTS, SUBACCOUNT_LABELS } from '@/services/analytics/events/subaccounts'
import { ChevronRight } from '@mui/icons-material'
import { Box, Typography } from '@mui/material'
import { List, ListItem, ListItemAvatar, ListItemButton, ListItemText, Typography } from '@mui/material'
import { useState, type ReactElement } from 'react'
import Identicon from '@/components/common/Identicon'
import { shortenAddress } from '@/utils/formatters'
import useAddressBook from '@/hooks/useAddressBook'
import { trackEvent } from '@/services/analytics'

const MAX_SUBACCOUNTS = 5

Expand All @@ -16,32 +19,9 @@ export function SubaccountsList({ subaccounts }: { subaccounts: Array<string> })
}

return (
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 1, alignItems: 'center' }}>
<List sx={{ gap: 1, display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
{subaccountsToShow.map((subaccount) => {
// TODO: Turn into link to Subaccount
return (
<Box
sx={{
width: '100%',
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'space-between',
border: '1px solid var(--color-border-light)',
borderRadius: ({ shape }) => `${shape.borderRadius}px`,
cursor: 'pointer',
py: '11px',
px: 2,
'&:hover': {
backgroundColor: 'var(--color-background-light)',
borderColor: 'var(--color-secondary-light)',
},
}}
key={subaccount}
>
<EthHashInfo address={subaccount} showPrefix={false} />
<ChevronRight color="border" />
</Box>
)
return <SubaccountListItem subaccount={subaccount} key={subaccount} />
})}
{subaccounts.length > MAX_SUBACCOUNTS && !showAll && (
<Track {...SUBACCOUNT_EVENTS.SHOW_ALL}>
Expand All @@ -59,6 +39,47 @@ export function SubaccountsList({ subaccounts }: { subaccounts: Array<string> })
</Typography>
</Track>
)}
</Box>
</List>
)
}

function SubaccountListItem({ subaccount }: { subaccount: string }): ReactElement {
const addressBook = useAddressBook()
const name = addressBook[subaccount]

// Note: using the Track element breaks accessibility/styles
const onClick = () => {
trackEvent({ ...SUBACCOUNT_EVENTS.OPEN_SUBACCOUNT, label: SUBACCOUNT_LABELS.list })
}

return (
<ListItem
sx={{
border: ({ palette }) => `1px solid ${palette.border.light}`,
borderRadius: ({ shape }) => `${shape.borderRadius}px`,
p: 0,
}}
>
<ListItemButton sx={{ p: '11px 12px' }} onClick={onClick}>
<ListItemAvatar sx={{ minWidth: 'unset', pr: 1 }}>
<Identicon address={subaccount} size={32} />
</ListItemAvatar>
<ListItemText
primary={name}
primaryTypographyProps={{
fontWeight: 700,
sx: {
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
},
}}
secondary={shortenAddress(subaccount)}
secondaryTypographyProps={{ color: 'primary.light' }}
sx={{ my: 0 }}
/>
<ChevronRight color="border" />
</ListItemButton>
</ListItem>
)
}
1 change: 1 addition & 0 deletions src/services/analytics/events/subaccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export const SUBACCOUNT_EVENTS = {
export enum SUBACCOUNT_LABELS {
header = 'header',
sidebar = 'sidebar',
list = 'list',
success_screen = 'success_screen',
}

0 comments on commit dc5bb92

Please sign in to comment.