Skip to content
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

Refactor out LogoutButton and match style of other header buttons #2131

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions packages/gui/src/components/app/AppStatusHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { Color, Flex, useMode, Mode, useDarkMode, useAuth, Tooltip } from '@chia-network/core';
import { Color, Flex, useMode, Mode, useDarkMode } from '@chia-network/core';
import { WalletConnections, WalletStatus, WalletReceiveAddressField } from '@chia-network/wallets';
import { Trans } from '@lingui/macro';
import { Logout as LogoutIcon } from '@mui/icons-material';
import { Box, ButtonGroup, Button, Popover, PopoverProps, IconButton } from '@mui/material';
import { Box, ButtonGroup, Button, Popover, PopoverProps } from '@mui/material';
import { useTheme, styled, alpha } from '@mui/material/styles';
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';

import Connections from '../fullNode/FullNodeConnections';
import FullNodeStateIndicator from '../fullNode/FullNodeStateIndicator';
import NotificationsDropdown from '../notification/NotificationsDropdown';
import WalletConnectDropdown from '../walletConnect/WalletConnectDropdown';

import AppTestnetIndicator from './AppTestnetIndicator';
import LogoutButton from './LogoutButton';

const StyledPopover = styled((props: PopoverProps) => <Popover {...props} />)(({ theme }) => ({
'& .MuiPopover-paper': {
Expand Down Expand Up @@ -47,6 +46,9 @@ export default function AppStatusHeader() {
const theme = useTheme();
const { isDarkMode } = useDarkMode();
const borderColor = (theme.palette as any).border[isDarkMode ? 'dark' : 'main'];
const ButtonGroupStyle = {
minHeight: '42px',
};
const ButtonStyle = {
paddingTop: '3px',
paddingBottom: 0,
Expand Down Expand Up @@ -91,8 +93,6 @@ export default function AppStatusHeader() {
};

const [mode] = useMode();
const navigate = useNavigate();
const { logOut } = useAuth();

const [anchorElFN, setAnchorElFN] = useState<HTMLButtonElement | null>(null);
const [anchorElW, setAnchorElW] = useState<HTMLButtonElement | null>(null);
Expand All @@ -113,18 +113,12 @@ export default function AppStatusHeader() {
setAnchorElW(null);
};

async function handleLogout() {
await logOut();

navigate('/');
}

return (
<Flex flexGrow={1} gap={2} flexWrap="wrap" alignItems="center">
<AppTestnetIndicator />
<WalletReceiveAddressField variant="outlined" size="small" fullWidth isDarkMode={isDarkMode} />
<Flex flexGrow={1} gap={2} alignItems="center" justifyContent="space-between">
<ButtonGroup variant="outlined" color="secondary" size="small">
<ButtonGroup variant="outlined" color="secondary" size="small" sx={ButtonGroupStyle}>
{mode === Mode.FARMING && (
<>
<Button onClick={handleClickFN} aria-describedby="fullnode-connections" sx={ButtonStyle}>
Expand Down Expand Up @@ -179,11 +173,7 @@ export default function AppStatusHeader() {
<Flex gap={0.5} alignItems="center">
<WalletConnectDropdown />
<NotificationsDropdown />
<Tooltip title={<Trans>Log Out</Trans>}>
<IconButton onClick={handleLogout} data-testid="AppStatusHeader-log-out">
<LogoutIcon />
</IconButton>
</Tooltip>
<LogoutButton />
</Flex>
</Flex>
</Flex>
Expand Down
1 change: 1 addition & 0 deletions packages/gui/src/components/app/AppTestnetIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default function AppTestnetIndicator() {
sx={{
...BorderStyle,
backgroundColor: theme.palette.background.default,
minHeight: '42px',
'&:hover': { backgroundColor: theme.palette.background.default, border: `1px solid ${borderColor}` },
}}
disableRipple
Expand Down
38 changes: 38 additions & 0 deletions packages/gui/src/components/app/LogoutButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Tooltip, useAuth } from '@chia-network/core';
import { Trans } from '@lingui/macro';
import { Logout as LogoutIcon } from '@mui/icons-material';
import { Button } from '@mui/material';
import React, { useCallback } from 'react';
import { useNavigate } from 'react-router-dom';

export default function LogoutButton() {
const navigate = useNavigate();
const { logOut } = useAuth();
const ButtonStyle = {
minWidth: 0,
width: '40px',
minHeight: '40px',
borderRadius: '8px',
};

const handleLogout = useCallback(async () => {
await logOut();

navigate('/');
}, [logOut, navigate]);

return (
<Tooltip title={<Trans>Log Out</Trans>}>
<Button
variant="text"
onClick={handleLogout}
color="secondary"
size="small"
data-testid="AppStatusHeader-log-out"
sx={ButtonStyle}
>
<LogoutIcon color="info" />
</Button>
</Tooltip>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import NotificationsMenu from './NotificationsMenu';

const buttonStyle = (theme) => ({
minWidth: 0,
borderRadius: 2,
borderRadius: '8px',
borderColor: theme.palette.mode === 'dark' ? 'border.dark' : 'border.main',
height: '42px',
width: '40px',
minHeight: '40px',
'&:hover': {
borderColor: theme.palette.mode === 'dark' ? 'border.dark' : 'border.main',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export default function WalletConnectDropdown() {

const ButtonStyle = {
minWidth: 0,
height: '42px',
borderRadius: 2,
width: '40px',
minHeight: '40px',
borderRadius: '8px',
};

const color = enabled && !isLoading && pairs.get().length > 0 ? 'primary' : 'info';
Expand Down