Skip to content

Commit

Permalink
Feat: owned Safes in the welcome page sidebar (#943)
Browse files Browse the repository at this point in the history
* Feat: owned Safes in the welcome page sidebar

* Increase title bottom margin
  • Loading branch information
katspaugh authored Oct 25, 2022
1 parent daee428 commit 54ea708
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 36 deletions.
45 changes: 28 additions & 17 deletions src/components/sidebar/OwnedSafes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
import useChainId from '@/hooks/useChainId'
import { useCurrentChain } from '@/hooks/useChains'
import useOwnedSafes from '@/hooks/useOwnedSafes'
import { List } from '@mui/material'
import { List, Typography } from '@mui/material'
import { type ReactElement } from 'react'
import SafeListItem from '../SafeListItem'

const OwnedSafes = (): ReactElement | null => {
const chainId = useChainId()
const chain = useCurrentChain()
const allOwnedSafes = useOwnedSafes()
const ownedSafesOnChain = allOwnedSafes[chainId]
const ownedSafesOnChain = chain ? allOwnedSafes[chain.chainId] : undefined

return ownedSafesOnChain?.length > 0 ? (
<List sx={{ py: 0 }}>
{ownedSafesOnChain?.map((address) => (
<SafeListItem
key={address}
address={address}
chainId={chainId}
closeDrawer={() => void null}
shouldScrollToSafe={false}
/>
))}
</List>
) : null
if (!chain || !ownedSafesOnChain?.length) {
return null
}

return (
<>
<Typography variant="body2" display="inline" color="primary.light" textAlign="center" mt={1} mb={2}>
Safes owned on {chain.chainName}
</Typography>

<List sx={{ py: 0 }}>
{ownedSafesOnChain?.map((address) => (
<SafeListItem
key={address}
address={address}
chainId={chain.chainId}
closeDrawer={() => void null}
shouldScrollToSafe={false}
noActions
/>
))}
</List>
</>
)
}

export default OwnedSafes
30 changes: 17 additions & 13 deletions src/components/sidebar/SafeListItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const SafeListItem = ({
chainId,
closeDrawer,
shouldScrollToSafe,
noActions = false,
...rest
}: {
address: string
Expand All @@ -33,6 +34,7 @@ const SafeListItem = ({
shouldScrollToSafe: boolean
threshold?: string | number
owners?: string | number
noActions?: boolean
}): ReactElement => {
const safeRef = useRef<HTMLDivElement>(null)
const safeAddress = useSafeAddress()
Expand All @@ -55,18 +57,20 @@ const SafeListItem = ({
className={css.container}
disablePadding
secondaryAction={
<Box display="flex" alignItems="center" gap={1}>
<SafeListItemSecondaryAction
chainId={chainId}
address={address}
onClick={closeDrawer}
href={{
pathname: AppRoutes.load,
query: { chain: shortName, address },
}}
/>
<SafeListContextMenu name={name} address={address} chainId={chainId} />
</Box>
noActions ? undefined : (
<Box display="flex" alignItems="center" gap={1}>
<SafeListItemSecondaryAction
chainId={chainId}
address={address}
onClick={closeDrawer}
href={{
pathname: AppRoutes.load,
query: { chain: shortName, address },
}}
/>
<SafeListContextMenu name={name} address={address} chainId={chainId} />
</Box>
)
}
>
<Link href={{ pathname: AppRoutes.home, query: { safe: `${shortName}:${address}` } }} passHref>
Expand All @@ -81,7 +85,7 @@ const SafeListItem = ({
<SafeIcon address={address} {...rest} />
</ListItemIcon>
<ListItemText
sx={{ pr: 10 }}
sx={noActions ? undefined : { pr: 10 }}
primaryTypographyProps={{
variant: 'body2',
component: 'div',
Expand Down
1 change: 0 additions & 1 deletion src/components/sidebar/SafeListItem/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

.safe {
border-radius: 8px;
padding-left: 22px;
}

.open {
Expand Down
11 changes: 8 additions & 3 deletions src/components/sidebar/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SidebarFooter from '@/components/sidebar/SidebarFooter'
import css from './styles.module.css'
import { trackEvent, OVERVIEW_EVENTS } from '@/services/analytics'
import KeyholeIcon from '@/components/common/icons/KeyholeIcon'
import OwnedSafes from '../OwnedSafes'

const Sidebar = (): ReactElement => {
const router = useRouter()
Expand Down Expand Up @@ -39,9 +40,13 @@ const Sidebar = (): ReactElement => {
<SidebarNavigation />
</>
) : (
<div className={css.noSafeHeader}>
<KeyholeIcon />
</div>
<>
<div className={css.noSafeHeader}>
<KeyholeIcon />
</div>

<OwnedSafes />
</>
)}

<div style={{ flexGrow: 1 }} />
Expand Down
5 changes: 3 additions & 2 deletions src/components/sidebar/Sidebar/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@

.noSafeHeader {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 10px;
min-height: 80px;
align-items: flex-start;
min-height: 100px;
}

.drawerButton {
Expand Down

0 comments on commit 54ea708

Please sign in to comment.