// @flow import * as ICONS from 'constants/icons'; import * as SETTINGS from 'constants/settings'; import * as PAGES from 'constants/pages'; import React, { Fragment } from 'react'; import { withRouter } from 'react-router'; import classnames from 'classnames'; import Button from 'component/button'; import LbcSymbol from 'component/common/lbc-symbol'; import WunderBar from 'component/wunderbar'; import Icon from 'component/common/icon'; import { Menu, MenuList, MenuButton, MenuItem } from '@reach/menu-button'; import Tooltip from 'component/common/tooltip'; // @if TARGET='app' import { IS_MAC } from 'component/app/view'; // @endif type Props = { balance: string, roundedBalance: number, history: { push: string => void, goBack: () => void, goForward: () => void, location: { pathname: string } }, currentTheme: string, automaticDarkModeEnabled: boolean, setClientSetting: (string, boolean | string) => void, hideBalance: boolean, email: ?string, authHeader: boolean, syncError: ?string, signOut: () => void, openMobileNavigation: () => void, }; const Header = (props: Props) => { const { roundedBalance, history, setClientSetting, currentTheme, automaticDarkModeEnabled, hideBalance, email, authHeader, signOut, syncError, openMobileNavigation, } = props; const authenticated = Boolean(email); // on the verify page don't let anyone escape other than by closing the tab to keep session data consistent const isVerifyPage = history.location.pathname.includes(PAGES.AUTH_VERIFY); const isAuthPage = history.location.pathname.includes(PAGES.AUTH); // Sign out if they click the "x" when they are on the password prompt const authHeaderAction = syncError ? { onClick: signOut } : { navigate: '/' }; const homeButtonNavigationProps = isVerifyPage ? {} : authHeader ? authHeaderAction : { navigate: '/' }; const closeButtonNavigationProps = authHeader ? authHeaderAction : { onClick: () => history.goBack() }; function handleThemeToggle() { if (automaticDarkModeEnabled) { setClientSetting(SETTINGS.AUTOMATIC_DARK_MODE_ENABLED, false); } if (currentTheme === 'dark') { setClientSetting(SETTINGS.THEME, 'light'); } else { setClientSetting(SETTINGS.THEME, 'dark'); } } function getWalletTitle() { return hideBalance ? ( __('Wallet') ) : ( {roundedBalance} ); } return (
)} {/* @endif */} {!authHeader && }
{!authHeader ? (
{(!IS_WEB || authenticated) && (
) : ( !isVerifyPage && (
{/* Add an empty span here so we can use the same style as above */} {/* This pushes the close button to the right side */}
) )} {!authenticated && !isAuthPage && (
); }; export default withRouter(Header);