This repository has been archived by the owner on Apr 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Improved the navbar and the metamask events handling #13
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b81c660
Improved the navbar and the metamask events handling
vcheeney 381c583
Fixed redirections before ballot loaded
vcheeney 4e17d16
Added extra comment
vcheeney b97151b
Update web/app/components/AccountMenu.tsx
vcheeney 46ba78a
Used early return to avoid nested if statement
vcheeney 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { LinkOff } from "@mui/icons-material"; | ||
import { | ||
Box, | ||
Button, | ||
ListItemIcon, | ||
ListItemText, | ||
Menu, | ||
MenuItem, | ||
Stack, | ||
Typography, | ||
} from "@mui/material"; | ||
import React, { FC, useState } from "react"; | ||
import { useEthereum } from "~/context/EthereumContext"; | ||
import { useVoter } from "~/context/VoterContext"; | ||
import { formatAccountString } from "~/lib/utils"; | ||
|
||
export const AccountMenu: FC = () => { | ||
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); | ||
const open = Boolean(anchorEl); | ||
const { account, logoutEthereumAccount, loading } = useEthereum(); | ||
const { voter } = useVoter(); | ||
|
||
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
|
||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Button | ||
id="account-menu" | ||
aria-controls={open ? "account-menu" : undefined} | ||
aria-haspopup="true" | ||
aria-expanded={open ? "true" : undefined} | ||
onClick={handleClick} | ||
color="neutral" | ||
> | ||
<Stack direction="row" spacing={1}> | ||
<Typography> | ||
{voter && account ? `${voter.firstName} ${voter.lastName}` : ""} | ||
vcheeney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Typography> | ||
<Box | ||
component="img" | ||
src="/metamask-fox.svg" | ||
sx={{ | ||
width: 22, | ||
}} | ||
/> | ||
<Typography | ||
sx={{ | ||
fontWeight: "bold", | ||
minWidth: 120, | ||
display: "inline-block", | ||
textAlign: "left", | ||
}} | ||
> | ||
{loading | ||
? "loading..." | ||
: (account && formatAccountString(account)) || "not connected"} | ||
</Typography> | ||
</Stack> | ||
</Button> | ||
<Menu | ||
id="basic-menu" | ||
anchorEl={anchorEl} | ||
open={open} | ||
onClose={handleClose} | ||
MenuListProps={{ | ||
"aria-labelledby": "basic-button", | ||
}} | ||
anchorOrigin={{ | ||
vertical: "bottom", | ||
horizontal: "right", | ||
}} | ||
transformOrigin={{ | ||
vertical: "top", | ||
horizontal: "right", | ||
}} | ||
sx={{ | ||
marginTop: 1, | ||
}} | ||
> | ||
<MenuItem | ||
onClick={() => { | ||
logoutEthereumAccount(); | ||
handleClose(); | ||
}} | ||
> | ||
<ListItemIcon> | ||
<LinkOff /> | ||
</ListItemIcon> | ||
<ListItemText>Disconnect</ListItemText> | ||
</MenuItem> | ||
</Menu> | ||
</> | ||
); | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const formatAccountString = (address: string) => { | ||
return address.slice(0, 6) + "..." + address.slice(-4); | ||
}; |
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.
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.
si tu fais
useState<HTMLElement>();
automatiquement le type ça va êtreHTMLElement | undefined
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.
Sick! 😀