Skip to content

Commit

Permalink
fix: remove sign out if there are no keys
Browse files Browse the repository at this point in the history
  • Loading branch information
alter-eggo committed Aug 7, 2024
1 parent 0cf3dae commit 051b1b5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
13 changes: 13 additions & 0 deletions src/app/common/hooks/auth/use-has-keys.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useHasLedgerKeys } from '@app/store/ledger/ledger.selectors';
import { useCurrentKeyDetails } from '@app/store/software-keys/software-key.selectors';

export function useHasKeys() {
const hasSoftwareKeys = !!useCurrentKeyDetails();
const hasLedgerKeys = useHasLedgerKeys();

return {
hasSoftwareKeys,
hasLedgerKeys,
hasKeys: hasSoftwareKeys || hasLedgerKeys,
};
}
35 changes: 19 additions & 16 deletions src/app/features/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { RouteUrls } from '@shared/route-urls';
import { analytics } from '@shared/utils/analytics';

import { useHasKeys } from '@app/common/hooks/auth/use-has-keys';
import { useKeyActions } from '@app/common/hooks/use-key-actions';
import { useModifierKey } from '@app/common/hooks/use-modifier-key';
import { useWalletType } from '@app/common/use-wallet-type';
Expand All @@ -34,8 +35,7 @@ import { Divider } from '@app/components/layout/divider';
import { NetworkDialog } from '@app/features/settings/network/network';
import { SignOut } from '@app/features/settings/sign-out/sign-out-confirm';
import { ThemeDialog } from '@app/features/settings/theme/theme-dialog';
import { useCurrentStacksAccount } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';
import { useHasLedgerKeys, useLedgerDeviceTargetId } from '@app/store/ledger/ledger.selectors';
import { useLedgerDeviceTargetId } from '@app/store/ledger/ledger.selectors';
import { useCurrentNetworkId } from '@app/store/networks/networks.selectors';

import { openFeedbackDialog } from '../feedback-button/feedback-button';
Expand All @@ -51,7 +51,9 @@ export function Settings({ triggerButton, toggleSwitchAccount }: SettingsProps)
const [showSignOut, setShowSignOut] = useState(false);
const [showChangeTheme, setShowChangeTheme] = useState(false);
const [showChangeNetwork, setShowChangeNetwork] = useState(false);
const hasGeneratedWallet = !!useCurrentStacksAccount();

const { hasKeys, hasLedgerKeys } = useHasKeys();

const { lockWallet } = useKeyActions();

const currentNetworkId = useCurrentNetworkId();
Expand All @@ -62,7 +64,6 @@ export function Settings({ triggerButton, toggleSwitchAccount }: SettingsProps)

const location = useLocation();

const isLedger = useHasLedgerKeys();
const { isPressed: showAdvancedMenuOptions } = useModifierKey('alt', 120);

return (
Expand All @@ -81,12 +82,12 @@ export function Settings({ triggerButton, toggleSwitchAccount }: SettingsProps)
})}
>
<DropdownMenu.Group>
{isLedger && targetId && (
{hasLedgerKeys && targetId && (
<DropdownMenu.Item>
<LedgerDeviceItemRow deviceType={extractDeviceNameFromKnownTargetIds(targetId)} />
</DropdownMenu.Item>
)}
{hasGeneratedWallet && (
{hasKeys && (
<DropdownMenu.Item
data-testid={SettingsSelectors.SwitchAccountTrigger}
onSelect={toggleSwitchAccount}
Expand All @@ -96,7 +97,7 @@ export function Settings({ triggerButton, toggleSwitchAccount }: SettingsProps)
</Flag>
</DropdownMenu.Item>
)}
{hasGeneratedWallet && walletType === 'software' && (
{hasKeys && walletType === 'software' && (
<DropdownMenu.Item
data-testid={SettingsSelectors.ViewSecretKeyListItem}
onSelect={() => navigate(RouteUrls.ViewSecretKey)}
Expand Down Expand Up @@ -176,7 +177,7 @@ export function Settings({ triggerButton, toggleSwitchAccount }: SettingsProps)
<Divider />
<DropdownMenu.Group>
{showAdvancedMenuOptions && <AdvancedMenuItems />}
{hasGeneratedWallet && walletType === 'software' && (
{hasKeys && walletType === 'software' && (
<DropdownMenu.Item
onSelect={() => {
void analytics.track('lock_session');
Expand All @@ -191,14 +192,16 @@ export function Settings({ triggerButton, toggleSwitchAccount }: SettingsProps)
</DropdownMenu.Item>
)}

<DropdownMenu.Item
onSelect={() => setShowSignOut(!showSignOut)}
data-testid={SettingsSelectors.SignOutListItem}
>
<Flag color="red.action-primary-default" img={<ExitIcon />} textStyle="label.02">
Sign out
</Flag>
</DropdownMenu.Item>
{hasKeys && (
<DropdownMenu.Item
onSelect={() => setShowSignOut(!showSignOut)}
data-testid={SettingsSelectors.SignOutListItem}
>
<Flag color="red.action-primary-default" img={<ExitIcon />} textStyle="label.02">
Sign out
</Flag>
</DropdownMenu.Item>
)}
</DropdownMenu.Group>
<AppVersion />
</DropdownMenu.Content>
Expand Down

0 comments on commit 051b1b5

Please sign in to comment.