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

Reset to mainnet on signout #5304

Merged
merged 2 commits into from
Apr 24, 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
2 changes: 2 additions & 0 deletions src/app/common/hooks/use-key-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useBitcoinClient, useStacksClient } from '@app/store/common/api-clients
import { inMemoryKeyActions } from '@app/store/in-memory-key/in-memory-key.actions';
import { bitcoinKeysSlice } from '@app/store/ledger/bitcoin/bitcoin-key.slice';
import { stacksKeysSlice } from '@app/store/ledger/stacks/stacks-key.slice';
import { networksSlice } from '@app/store/networks/networks.slice';
import { clearWalletSession } from '@app/store/session-restore';
import { keyActions } from '@app/store/software-keys/software-key.actions';
import { useCurrentKeyDetails } from '@app/store/software-keys/software-key.selectors';
Expand Down Expand Up @@ -55,6 +56,7 @@ export function useKeyActions() {

async signOut() {
await clearWalletSession();
dispatch(networksSlice.actions.changeNetwork('mainnet'));
dispatch(keyActions.signOut());
dispatch(bitcoinKeysSlice.actions.signOut());
dispatch(stacksKeysSlice.actions.signOut());
Expand Down
11 changes: 7 additions & 4 deletions src/app/features/settings/network/network.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ import { NetworkListItem } from '@app/features/settings/network/network-list-ite
import { useCurrentNetworkState, useNetworksActions } from '@app/store/networks/networks.hooks';
import { useNetworks } from '@app/store/networks/networks.selectors';
import { Button } from '@app/ui/components/button/button';
import { Dialog, DialogProps } from '@app/ui/components/containers/dialog/dialog';
import { Dialog } from '@app/ui/components/containers/dialog/dialog';
import { Footer } from '@app/ui/components/containers/footers/footer';
import { Header } from '@app/ui/components/containers/headers/header';

const defaultNetworkIds = Object.values(WalletDefaultNetworkConfigurationIds) as string[];

export function NetworkDialog({ isShowing, onClose }: DialogProps) {
interface NetworkDialogProps {
onClose(): void;
}

export function NetworkDialog({ onClose }: NetworkDialogProps) {
const navigate = useNavigate();
const networks = useNetworks();
const analytics = useAnalytics();
const networksActions = useNetworksActions();
const currentNetwork = useCurrentNetworkState();

function addNetwork() {
void analytics.track('add_network');
navigate(RouteUrls.AddNetwork);
Expand All @@ -41,7 +44,7 @@ export function NetworkDialog({ isShowing, onClose }: DialogProps) {
return (
<Dialog
header={<Header variant="dialog" title="Change network" />}
isShowing={isShowing}
isShowing
onClose={onClose}
footer={
<Footer>
Expand Down
14 changes: 5 additions & 9 deletions src/app/features/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,11 @@ export function Settings({ triggerButton, toggleSwitchAccount }: SettingsProps)
</DropdownMenu.Content>
</DropdownMenu.Portal>
</DropdownMenu.Root>
<SignOut isShowing={showSignOut} onClose={() => setShowSignOut(!showSignOut)} />
<ThemeDialog
isShowing={showChangeTheme}
onClose={() => setShowChangeTheme(!showChangeTheme)}
/>
<NetworkDialog
isShowing={showChangeNetwork}
onClose={() => setShowChangeNetwork(!showChangeNetwork)}
/>
{showSignOut && <SignOut onClose={() => setShowSignOut(!showSignOut)} />}
{showChangeTheme && <ThemeDialog onClose={() => setShowChangeTheme(!showChangeTheme)} />}
{showChangeNetwork && (
<NetworkDialog onClose={() => setShowChangeNetwork(!showChangeNetwork)} />
)}
pete-watters marked this conversation as resolved.
Show resolved Hide resolved
</>
);
}
14 changes: 3 additions & 11 deletions src/app/features/settings/sign-out/sign-out-confirm.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';

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

import { useAnalytics } from '@app/common/hooks/analytics/use-analytics';
import { useKeyActions } from '@app/common/hooks/use-key-actions';

import { SignOutDialog } from './sign-out';

interface SignOutProps {
isShowing: boolean;
onClose(): void;
}

export function SignOut({ isShowing = false, onClose }: SignOutProps) {
const analytics = useAnalytics();

useEffect(() => void analytics.track('sign-out'), [analytics]);
export function SignOut({ onClose }: SignOutProps) {
const { signOut } = useKeyActions();
const navigate = useNavigate();
// #4370 SMELL without this early return the wallet crashes on new install with
// : Wallet is neither of type `ledger` nor `software`
if (!isShowing) return null;

return (
<SignOutDialog
isShowing={isShowing}
isShowing
onUserDeleteWallet={() => {
void signOut().finally(() => {
navigate(RouteUrls.Onboarding);
Expand Down
14 changes: 7 additions & 7 deletions src/app/features/settings/theme/theme-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { useCallback } from 'react';

import { useAnalytics } from '@app/common/hooks/analytics/use-analytics';
import { UserSelectedTheme, themeLabelMap, useThemeSwitcher } from '@app/common/theme-provider';
import { Dialog, DialogProps } from '@app/ui/components/containers/dialog/dialog';
import { Dialog } from '@app/ui/components/containers/dialog/dialog';
import { Header } from '@app/ui/components/containers/headers/header';

import { ThemeListItem } from './theme-list-item';

export function ThemeDialog({ isShowing, onClose }: DialogProps) {
interface ThemeDialogProps {
onClose(): void;
}

export function ThemeDialog({ onClose }: ThemeDialogProps) {
const themes = Object.keys(themeLabelMap) as UserSelectedTheme[];
const analytics = useAnalytics();
const { setUserSelectedTheme } = useThemeSwitcher();
Expand All @@ -25,11 +29,7 @@ export function ThemeDialog({ isShowing, onClose }: DialogProps) {
const { userSelectedTheme } = useThemeSwitcher();

return (
<Dialog
header={<Header variant="dialog" title="Change theme" />}
isShowing={isShowing}
onClose={onClose}
>
<Dialog header={<Header variant="dialog" title="Change theme" />} isShowing onClose={onClose}>
{themes.map(theme => (
<ThemeListItem
key={theme}
Expand Down
Loading