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

Show settings menu when session locked #5785

Merged
merged 5 commits into from
Aug 21, 2024
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
3 changes: 1 addition & 2 deletions src/app/components/layout/footer/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export function Footer({ children, ...props }: HasChildren & FlexProps) {
gap="space.05"
p="space.05"
bottom={0}
width="100vw"
maxWidth="100%"
width="100%"
zIndex={1}
minHeight="footerHeight"
position="fixed"
Expand Down
32 changes: 7 additions & 25 deletions src/app/components/layout/headers/logo-box.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
import { useLocation, useNavigate } from 'react-router-dom';

import { OnboardingSelectors } from '@tests/selectors/onboarding.selectors';
import { Box } from 'leather-styles/jsx';
import { Box, BoxProps } from 'leather-styles/jsx';

import { Logo } from '@leather.io/ui';

import { RouteUrls } from '@shared/route-urls';

export function LogoBox({ isSessionLocked }: { isSessionLocked?: boolean | undefined }) {
const navigate = useNavigate();
const location = useLocation();

const shouldShowLogo =
location.pathname === RouteUrls.Home || location.pathname === RouteUrls.Activity;

const hideBelow = shouldShowLogo ? undefined : isSessionLocked ? undefined : 'sm';
const hideFrom = shouldShowLogo ? undefined : isSessionLocked ? 'sm' : undefined;
interface LogoBoxProps extends BoxProps {
onClick?(): void;
}

export function LogoBox({ onClick, ...props }: LogoBoxProps) {
return (
<Box
height="headerContainerHeight"
margin="auto"
px="space.02"
hideBelow={hideBelow}
hideFrom={hideFrom}
>
<Logo
data-testid={OnboardingSelectors.LogoRouteToHome}
onClick={() => navigate(RouteUrls.Home)}
/>
<Box height="headerContainerHeight" margin="auto" px="space.02" hideBelow="sm" {...props}>
<Logo data-testid={OnboardingSelectors.LogoRouteToHome} onClick={onClick} />
</Box>
);
}
2 changes: 1 addition & 1 deletion src/app/features/add-network/add-network.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function AddNetwork() {

return (
<>
<PageHeader title="Add Network" />
<PageHeader title="Add network" />
<Content>
<Page>
<Formik initialValues={initialFormValues} onSubmit={onSubmit}>
Expand Down
33 changes: 33 additions & 0 deletions src/app/features/container/headers/home.header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useOutletContext } from 'react-router-dom';

import { SettingsSelectors } from '@tests/selectors/settings.selectors';

import { HamburgerIcon } from '@leather.io/ui';

import { SwitchAccountOutletContext } from '@shared/switch-account';

import { Header } from '@app/components/layout/headers/header';
import { HeaderGrid, HeaderGridRightCol } from '@app/components/layout/headers/header-grid';
import { LogoBox } from '@app/components/layout/headers/logo-box';
import { Settings } from '@app/features/settings/settings';

export function HomeHeader() {
const { isShowingSwitchAccount, setIsShowingSwitchAccount } =
useOutletContext<SwitchAccountOutletContext>();

return (
<Header paddingLeft={{ base: undefined, sm: 0 }}>
<HeaderGrid
leftCol={<LogoBox hideBelow={undefined} />}
rightCol={
<HeaderGridRightCol>
<Settings
triggerButton={<HamburgerIcon data-testid={SettingsSelectors.SettingsMenuBtn} />}
toggleSwitchAccount={() => setIsShowingSwitchAccount(!isShowingSwitchAccount)}
/>
</HeaderGridRightCol>
}
/>
</Header>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SharedComponentsSelectors } from '@tests/selectors/shared-component.sel

import { ArrowLeftIcon, HamburgerIcon } from '@leather.io/ui';

import { RouteUrls } from '@shared/route-urls';
import { SwitchAccountOutletContext } from '@shared/switch-account';

import { Header } from '@app/components/layout/headers/header';
Expand All @@ -13,29 +14,27 @@ import { HeaderGrid, HeaderGridRightCol } from '@app/components/layout/headers/h
import { LogoBox } from '@app/components/layout/headers/logo-box';
import { Settings } from '@app/features/settings/settings';

interface MainHeaderProps {
hideBackButton?: boolean;
interface OnboardingHeaderProps {
hideLogo?: boolean;
}

export function MainHeader({ hideBackButton = false, hideLogo = false }: MainHeaderProps) {
export function OnboardingHeader({ hideLogo = false }: OnboardingHeaderProps) {
const { isShowingSwitchAccount, setIsShowingSwitchAccount } =
useOutletContext<SwitchAccountOutletContext>();
const navigate = useNavigate();

return (
<>
<Header paddingLeft={{ base: undefined, sm: 0 }}>
<HeaderGrid
leftCol={
<>
{!hideBackButton && (
<HeaderActionButton
icon={<ArrowLeftIcon />}
onAction={() => navigate(-1)}
dataTestId={SharedComponentsSelectors.HeaderBackBtn}
/>
)}
{!hideLogo && <LogoBox />}
<HeaderActionButton
icon={<ArrowLeftIcon />}
onAction={() => navigate(-1)}
dataTestId={SharedComponentsSelectors.HeaderBackBtn}
/>
{!hideLogo && <LogoBox onClick={() => navigate(RouteUrls.Home)} />}
</>
}
rightCol={
Expand Down
10 changes: 4 additions & 6 deletions src/app/features/container/headers/page.header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ import { Settings } from '@app/features/settings/settings';
interface PageHeaderProps {
title?: string;
isSummaryPage?: boolean;
isSessionLocked?: boolean;
isSettingsVisibleOnSm?: boolean;
onBackLocation?: RouteUrls;
onClose?(): void;
}

export function PageHeader({
title,
isSummaryPage,
isSessionLocked,
isSettingsVisibleOnSm,
isSummaryPage = false,
isSettingsVisibleOnSm = true,
onBackLocation,
}: PageHeaderProps) {
const { isShowingSwitchAccount, setIsShowingSwitchAccount } =
Expand All @@ -37,7 +35,7 @@ export function PageHeader({

// pages with nested dialogs specify onBackLocation to prevent navigate(-1) re-opening the dialog
const onGoBack = onBackLocation ? () => navigate(onBackLocation) : () => navigate(-1);
const canGoBack = !isSummaryPage && !isSessionLocked;
const canGoBack = !isSummaryPage;

return (
<>
Expand All @@ -52,7 +50,7 @@ export function PageHeader({
dataTestId={SharedComponentsSelectors.HeaderBackBtn}
/>
)}
<LogoBox isSessionLocked={isSessionLocked} />
<LogoBox onClick={() => navigate(RouteUrls.Home)} />
</>
}
centerCol={title && <styled.span textStyle="heading.05">{title}</styled.span>}
Expand Down
34 changes: 34 additions & 0 deletions src/app/features/container/headers/unlock.header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useNavigate } from 'react-router-dom';

import { SettingsSelectors } from '@tests/selectors/settings.selectors';

import { HamburgerIcon } from '@leather.io/ui';

import { RouteUrls } from '@shared/route-urls';

import { Header } from '@app/components/layout/headers/header';
import { HeaderGrid, HeaderGridRightCol } from '@app/components/layout/headers/header-grid';
import { LogoBox } from '@app/components/layout/headers/logo-box';
import { Settings } from '@app/features/settings/settings';

export function UnlockHeader() {
const navigate = useNavigate();

return (
<Header paddingLeft={{ base: undefined, sm: 0 }}>
<HeaderGrid
leftCol={
<LogoBox onClick={() => navigate(RouteUrls.Home)} hideBelow={undefined} hideFrom="sm" />
}
rightCol={
<HeaderGridRightCol>
<Settings
canLockWallet={false}
triggerButton={<HamburgerIcon data-testid={SettingsSelectors.SettingsMenuBtn} />}
/>
</HeaderGridRightCol>
}
/>
</Header>
);
}
15 changes: 10 additions & 5 deletions src/app/features/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ import { AdvancedMenuItems } from './components/advanced-menu-items';
import { LedgerDeviceItemRow } from './components/ledger-item-row';

interface SettingsProps {
canLockWallet?: boolean;
triggerButton: React.ReactNode;
toggleSwitchAccount(): void;
toggleSwitchAccount?(): void;
}
export function Settings({ triggerButton, toggleSwitchAccount }: SettingsProps) {
export function Settings({
canLockWallet = true,
triggerButton,
toggleSwitchAccount,
}: SettingsProps) {
const [showSignOut, setShowSignOut] = useState(false);
const [showChangeTheme, setShowChangeTheme] = useState(false);
const [showChangeNetwork, setShowChangeNetwork] = useState(false);
Expand All @@ -70,7 +75,7 @@ export function Settings({ triggerButton, toggleSwitchAccount }: SettingsProps)
() =>
[
showAdvancedMenuOptions && <AdvancedMenuItems />,
hasKeys && walletType === 'software' && (
canLockWallet && hasKeys && walletType === 'software' && (
<DropdownMenu.Item
onSelect={() => {
void analytics.track('lock_session');
Expand All @@ -96,7 +101,7 @@ export function Settings({ triggerButton, toggleSwitchAccount }: SettingsProps)
</DropdownMenu.Item>
),
].filter(Boolean),
[hasKeys, lockWallet, navigate, showAdvancedMenuOptions, showSignOut, walletType]
[canLockWallet, hasKeys, lockWallet, navigate, showAdvancedMenuOptions, showSignOut, walletType]
);

return (
Expand All @@ -120,7 +125,7 @@ export function Settings({ triggerButton, toggleSwitchAccount }: SettingsProps)
<LedgerDeviceItemRow deviceType={extractDeviceNameFromKnownTargetIds(targetId)} />
</DropdownMenu.Item>
)}
{hasKeys && (
{hasKeys && toggleSwitchAccount && (
<DropdownMenu.Item
data-testid={SettingsSelectors.SwitchAccountTrigger}
onSelect={toggleSwitchAccount}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { EyeSlashIcon, KeyIcon, LockIcon } from '@leather.io/ui';
import { RouteUrls } from '@shared/route-urls';

import { Content, TwoColumnLayout } from '@app/components/layout';
import { MainHeader } from '@app/features/container/headers/main.header';
import { OnboardingHeader } from '@app/features/container/headers/onboarding.header';
import { SecretKey } from '@app/features/secret-key-displayer/secret-key-displayer';
import { useDefaultWalletSecretKey } from '@app/store/in-memory-key/in-memory-key.selectors';

Expand All @@ -24,7 +24,7 @@ export const BackUpSecretKeyPage = memo(() => {

return (
<>
<MainHeader />
<OnboardingHeader />
<Content>
<TwoColumnLayout
title="Back up your Secret Key"
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/onboarding/set-password/set-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
validatePassword,
} from '@app/common/validation/validate-password';
import { Content, TwoColumnLayout } from '@app/components/layout';
import { MainHeader } from '@app/features/container/headers/main.header';
import { OnboardingHeader } from '@app/features/container/headers/onboarding.header';
import { OnboardingGate } from '@app/routes/onboarding-gate';
import { useStacksAccounts } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';

Expand Down Expand Up @@ -111,7 +111,7 @@ function SetPasswordPage() {
});
return (
<>
<MainHeader />
<OnboardingHeader />
<Content>
<Formik
initialValues={setPasswordFormValues}
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/onboarding/sign-in/sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Link } from '@leather.io/ui';
import { createNullArrayOfLength } from '@leather.io/utils';

import { Content, TwoColumnLayout } from '@app/components/layout';
import { MainHeader } from '@app/features/container/headers/main.header';
import { OnboardingHeader } from '@app/features/container/headers/onboarding.header';
import { MnemonicForm } from '@app/pages/onboarding/sign-in/mnemonic-form';

export function SignIn() {
Expand All @@ -20,7 +20,7 @@ export function SignIn() {

return (
<>
<MainHeader />
<OnboardingHeader />
<Content>
<TwoColumnLayout
title={
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/unlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Outlet, useNavigate } from 'react-router-dom';

import { Content } from '@app/components/layout';
import { RequestPassword } from '@app/components/request-password';
import { PageHeader } from '@app/features/container/headers/page.header';
import { UnlockHeader } from '@app/features/container/headers/unlock.header';

export function Unlock() {
const navigate = useNavigate();
Expand All @@ -12,7 +12,7 @@ export function Unlock() {

return (
<>
<PageHeader isSessionLocked />
<UnlockHeader />
<Content>
<RequestPassword onSuccess={returnToPreviousRoute} />
<Outlet />
Expand Down
6 changes: 3 additions & 3 deletions src/app/pages/view-secret-key/view-secret-key.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { analytics } from '@shared/utils/analytics';

import { Content, TwoColumnLayout } from '@app/components/layout';
import { RequestPassword } from '@app/components/request-password';
import { MainHeader } from '@app/features/container/headers/main.header';
import { OnboardingHeader } from '@app/features/container/headers/onboarding.header';
import { SecretKey } from '@app/features/secret-key-displayer/secret-key-displayer';
import { useDefaultWalletSecretKey } from '@app/store/in-memory-key/in-memory-key.selectors';

Expand All @@ -20,7 +20,7 @@ export function ViewSecretKey() {
if (showSecretKey) {
return (
<>
<MainHeader />
<OnboardingHeader />
<Content>
<TwoColumnLayout
title={
Expand All @@ -46,7 +46,7 @@ export function ViewSecretKey() {

return (
<>
<MainHeader hideLogo />
<OnboardingHeader hideLogo />
<Content>
<RequestPassword onSuccess={() => setShowSecretKey(true)} />
<Outlet />
Expand Down
4 changes: 2 additions & 2 deletions src/app/routes/app-routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { SwitchAccountLayout } from '@app/components/layout/layouts/switch-accou
import { LoadingSpinner } from '@app/components/loading-spinner';
import { AddNetwork } from '@app/features/add-network/add-network';
import { Container } from '@app/features/container/container';
import { MainHeader } from '@app/features/container/headers/main.header';
import { HomeHeader } from '@app/features/container/headers/home.header';
import { IncreaseBtcFeeDialog } from '@app/features/dialogs/increase-fee-dialog/increase-btc-fee-dialog';
import { IncreaseStxFeeDialog } from '@app/features/dialogs/increase-fee-dialog/increase-stx-fee-dialog';
import { leatherIntroDialogRoutes } from '@app/features/dialogs/leather-intro-dialog/leather-intro-dialog';
Expand Down Expand Up @@ -82,7 +82,7 @@ function useAppRoutes() {
<Route
element={
<>
<MainHeader hideBackButton />
<HomeHeader />
<Content>
<SwitchAccountLayout />
</Content>
Expand Down
Loading