diff --git a/src/app/common/hooks/auth/use-has-keys.tsx b/src/app/common/hooks/auth/use-has-keys.tsx new file mode 100644 index 00000000000..b19b8c18025 --- /dev/null +++ b/src/app/common/hooks/auth/use-has-keys.tsx @@ -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, + }; +} diff --git a/src/app/features/settings/settings.tsx b/src/app/features/settings/settings.tsx index 8b99dbb45cc..1dc8804d7fc 100644 --- a/src/app/features/settings/settings.tsx +++ b/src/app/features/settings/settings.tsx @@ -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'; @@ -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'; @@ -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(); @@ -62,7 +64,6 @@ export function Settings({ triggerButton, toggleSwitchAccount }: SettingsProps) const location = useLocation(); - const isLedger = useHasLedgerKeys(); const { isPressed: showAdvancedMenuOptions } = useModifierKey('alt', 120); return ( @@ -81,12 +82,12 @@ export function Settings({ triggerButton, toggleSwitchAccount }: SettingsProps) })} > - {isLedger && targetId && ( + {hasLedgerKeys && targetId && ( )} - {hasGeneratedWallet && ( + {hasKeys && ( )} - {hasGeneratedWallet && walletType === 'software' && ( + {hasKeys && walletType === 'software' && ( navigate(RouteUrls.ViewSecretKey)} @@ -176,7 +177,7 @@ export function Settings({ triggerButton, toggleSwitchAccount }: SettingsProps) {showAdvancedMenuOptions && } - {hasGeneratedWallet && walletType === 'software' && ( + {hasKeys && walletType === 'software' && ( { void analytics.track('lock_session'); @@ -191,14 +192,16 @@ export function Settings({ triggerButton, toggleSwitchAccount }: SettingsProps) )} - setShowSignOut(!showSignOut)} - data-testid={SettingsSelectors.SignOutListItem} - > - } textStyle="label.02"> - Sign out - - + {hasKeys && ( + setShowSignOut(!showSignOut)} + data-testid={SettingsSelectors.SignOutListItem} + > + } textStyle="label.02"> + Sign out + + + )}