-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Multichain] feat: redesign of multiaccounts and context menu for multiaccounts #4125
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cc59938
feat: redesign of multiaccounts and context menu for multiaccounts
schmanu 1c59e54
fix: introduce upsertMUltichainAddressBookEntry reducer
schmanu 8437fbc
refactor: extract component
schmanu 9020775
Merge remote-tracking branch 'origin/epic/multichain-safes' into feat…
schmanu d15bdb6
fix: show error if no chains available
schmanu 5e3bb59
fix: review issues
schmanu de3c784
Merge remote-tracking branch 'origin/epic/multichain-safes' into feat…
schmanu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/components/sidebar/SafeListContextMenu/MultiAccountContextMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,106 @@ | ||||||
import type { MouseEvent } from 'react' | ||||||
import { useState, type ReactElement } from 'react' | ||||||
import ListItemIcon from '@mui/material/ListItemIcon' | ||||||
import IconButton from '@mui/material/IconButton' | ||||||
import MoreVertIcon from '@mui/icons-material/MoreVert' | ||||||
import MenuItem from '@mui/material/MenuItem' | ||||||
import ListItemText from '@mui/material/ListItemText' | ||||||
|
||||||
import EntryDialog from '@/components/address-book/EntryDialog' | ||||||
import EditIcon from '@/public/images/common/edit.svg' | ||||||
import PlusIcon from '@/public/images/common/plus.svg' | ||||||
import ContextMenu from '@/components/common/ContextMenu' | ||||||
import { trackEvent, OVERVIEW_EVENTS, OVERVIEW_LABELS } from '@/services/analytics' | ||||||
import { SvgIcon } from '@mui/material' | ||||||
import { AppRoutes } from '@/config/routes' | ||||||
import router from 'next/router' | ||||||
import { CreateSafeOnNewChain } from '@/features/multichain/components/CreateSafeOnNewChain' | ||||||
|
||||||
enum ModalType { | ||||||
RENAME = 'rename', | ||||||
ADD_CHAIN = 'add_chain', | ||||||
} | ||||||
|
||||||
const defaultOpen = { [ModalType.RENAME]: false, [ModalType.ADD_CHAIN]: false } | ||||||
|
||||||
const MultiAccountContextMenu = ({ | ||||||
name, | ||||||
address, | ||||||
chainIds, | ||||||
}: { | ||||||
name: string | ||||||
address: string | ||||||
chainIds: string[] | ||||||
}): ReactElement => { | ||||||
const [anchorEl, setAnchorEl] = useState<HTMLElement | undefined>() | ||||||
clovisdasilvaneto marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
const [open, setOpen] = useState<typeof defaultOpen>(defaultOpen) | ||||||
|
||||||
const handleOpenContextMenu = (e: MouseEvent<HTMLButtonElement, globalThis.MouseEvent>) => { | ||||||
e.stopPropagation() | ||||||
setAnchorEl(e.currentTarget) | ||||||
} | ||||||
|
||||||
const handleCloseContextMenu = (event: MouseEvent) => { | ||||||
event.stopPropagation() | ||||||
setAnchorEl(undefined) | ||||||
} | ||||||
|
||||||
const handleOpenModal = | ||||||
(type: ModalType, event: typeof OVERVIEW_EVENTS.SIDEBAR_RENAME | typeof OVERVIEW_EVENTS.ADD_NEW_NETWORK) => | ||||||
(e: MouseEvent) => { | ||||||
const trackingLabel = | ||||||
router.pathname === AppRoutes.welcome.accounts ? OVERVIEW_LABELS.login_page : OVERVIEW_LABELS.sidebar | ||||||
handleCloseContextMenu(e) | ||||||
setOpen((prev) => ({ ...prev, [type]: true })) | ||||||
|
||||||
trackEvent({ ...event, label: trackingLabel }) | ||||||
} | ||||||
|
||||||
const handleCloseModal = () => { | ||||||
setOpen(defaultOpen) | ||||||
} | ||||||
|
||||||
return ( | ||||||
<> | ||||||
<IconButton data-testid="safe-options-btn" edge="end" size="small" onClick={handleOpenContextMenu}> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<MoreVertIcon sx={({ palette }) => ({ color: palette.border.main })} /> | ||||||
</IconButton> | ||||||
<ContextMenu anchorEl={anchorEl} open={!!anchorEl} onClose={handleCloseContextMenu}> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<MenuItem onClick={handleOpenModal(ModalType.RENAME, OVERVIEW_EVENTS.SIDEBAR_RENAME)}> | ||||||
<ListItemIcon> | ||||||
<SvgIcon component={EditIcon} inheritViewBox fontSize="small" color="success" /> | ||||||
</ListItemIcon> | ||||||
<ListItemText data-testid="rename-btn">Rename</ListItemText> | ||||||
</MenuItem> | ||||||
|
||||||
<MenuItem onClick={handleOpenModal(ModalType.ADD_CHAIN, OVERVIEW_EVENTS.ADD_NEW_NETWORK)}> | ||||||
<ListItemIcon> | ||||||
<SvgIcon component={PlusIcon} inheritViewBox fontSize="small" color="primary" /> | ||||||
</ListItemIcon> | ||||||
<ListItemText data-testid="add-chain-btn">Add another network</ListItemText> | ||||||
</MenuItem> | ||||||
</ContextMenu> | ||||||
|
||||||
{open[ModalType.RENAME] && ( | ||||||
<EntryDialog | ||||||
handleClose={handleCloseModal} | ||||||
defaultValues={{ name, address }} | ||||||
chainIds={chainIds} | ||||||
disableAddressInput | ||||||
/> | ||||||
)} | ||||||
|
||||||
{open[ModalType.ADD_CHAIN] && ( | ||||||
<CreateSafeOnNewChain | ||||||
onClose={handleCloseModal} | ||||||
currentName={name} | ||||||
deployedChainIds={chainIds} | ||||||
open | ||||||
safeAddress={address} | ||||||
/> | ||||||
)} | ||||||
</> | ||||||
) | ||||||
} | ||||||
|
||||||
export default MultiAccountContextMenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
about the architecture of this component, since it's a button that shows a dropdown with some options which triggers a modal, would be amazing if we can separate the dropdown in generic renderProps component which provides the
openMenu
function to the rendered child and takes an array of options? something like:in this case,
items
would be a common type like this:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The architecture also comes from the MUI component library. I do not think we can easily rewrite it to this.
So I'll stick to how the examples use the component for the time being.