Skip to content

Commit

Permalink
fix: keep state when navigating back from login screen [ENG-5677] (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
victorkirov authored Nov 11, 2024
1 parent 8f61dca commit 51e6ceb
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 27 deletions.
5 changes: 2 additions & 3 deletions src/app/components/accountHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AccountRow from '@components/accountRow';
import useWalletReducer from '@hooks/useWalletReducer';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import styled from 'styled-components';

import OptionsDialog from '@components/optionsDialog/optionsDialog';
Expand Down Expand Up @@ -64,7 +64,6 @@ function AccountHeaderComponent({
disableAccountSwitch = false,
}: Props) {
const navigate = useNavigate();
const { pathname } = useLocation();
const selectedAccount = useSelectedAccount();
const menuDialog = useOptionsDialog();

Expand All @@ -75,7 +74,7 @@ function AccountHeaderComponent({

const handleAccountSelect = () => {
if (!disableAccountSwitch) {
navigate(RoutePaths.AccountList, { state: { from: pathname } });
navigate(RoutePaths.AccountList);
}
};

Expand Down
8 changes: 3 additions & 5 deletions src/app/components/animatedScreenContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ScreenContainer from '@components/screenContainer';
import { animated, useSpring } from '@react-spring/web';
import { ANIMATION_EASING } from '@utils/constants';
import { useLocation } from 'react-router-dom';

const containerStyles = {
display: 'flex',
Expand All @@ -12,10 +11,9 @@ const containerStyles = {
};

function AnimatedScreenContainer(): JSX.Element {
const location = useLocation();
const { state } = location;

const shouldAnimate = state?.from === '/login';
// TODO: figure this out to make animations work
// TODO: they should only load if coming fromm the login page
const shouldAnimate = false;

const styles = useSpring({
from: {
Expand Down
7 changes: 3 additions & 4 deletions src/app/components/guards/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import useWalletReducer from '@hooks/useWalletReducer';
import useWalletSelector from '@hooks/useWalletSelector';
import Spinner from '@ui-library/spinner';
import { useEffect, type PropsWithChildren } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import styled from 'styled-components';

const CenterChildContainer = styled.div`
Expand All @@ -24,7 +24,6 @@ const isInitialised = {

function AuthGuard({ children }: PropsWithChildren) {
const navigate = useNavigate();
const { pathname } = useLocation();
const { encryptedSeed, isUnlocked, accountsList } = useWalletSelector();
const { loadWallet, lockWallet } = useWalletReducer();
const seedVault = useSeedVault();
Expand All @@ -41,7 +40,7 @@ function AuthGuard({ children }: PropsWithChildren) {
if (encryptedSeed) {
// this is a legacy seed store. If it exists, we need to migrate
// it to the new seed vault which happens on login
navigate('/login', { state: { from: pathname } });
navigate('/login');
return;
}

Expand All @@ -64,7 +63,7 @@ function AuthGuard({ children }: PropsWithChildren) {
try {
await seedVault.getSeed();
} catch (error) {
navigate('/login', { state: { from: pathname } });
navigate('/login');
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/screens/connect/authenticationRequest/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function AuthenticationRequest() {
stxAddress: {
mainnet: selectedAccount.stxAddress,
testnet: publicKeyToAddress(AddressVersion.MainnetSingleSig, {
data: Buffer.from(selectedAccount.stxPublicKey, 'hex'),
data: Uint8Array.from(Buffer.from(selectedAccount.stxPublicKey, 'hex')),
type: StacksMessageType.PublicKey,
}),
},
Expand Down
3 changes: 1 addition & 2 deletions src/app/screens/connect/btcSelectAddressScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { trackMixPanel } from '@utils/mixpanel';
import RoutePaths from 'app/routes/paths';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import AddressPurposeBox from '../addressPurposeBox';
import PermissionsList from '../permissionsList';
import {
Expand All @@ -34,7 +34,6 @@ import useBtcAddressRequest from './useBtcAddressRequest';
function BtcSelectAddressScreen() {
const [loading, setLoading] = useState(false);
const navigate = useNavigate();
const { pathname } = useLocation();
const { t } = useTranslation('translation', { keyPrefix: 'SELECT_BTC_ADDRESS_SCREEN' });
const selectedAccount = useSelectedAccount();
const { network } = useWalletSelector();
Expand Down
15 changes: 3 additions & 12 deletions src/app/screens/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Button from '@ui-library/button';
import { trackMixPanel } from '@utils/mixpanel';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import {
AppVersion,
ButtonContainer,
Expand All @@ -31,7 +31,6 @@ import {
function Login(): JSX.Element {
const { t } = useTranslation('translation', { keyPrefix: 'LOGIN_SCREEN' });
const navigate = useNavigate();
const { state } = useLocation();
const { unlockWallet } = useWalletReducer();
const { hasSeed } = useSeedVault();
const { migrateCachedStorage, isVaultUpdated } = useSeedVaultMigration();
Expand Down Expand Up @@ -89,19 +88,11 @@ function Login(): JSX.Element {
setShowMigration(true);
} else {
setIsVerifying(false);
if (state?.from) {
navigate(state?.from, { state: { from: '/login' } }); // this is needed for AnimatedScreenContainer where we check the state.from
} else {
navigate(-1);
}
navigate(-1);
}
} catch (err) {
setIsVerifying(false);
if (state?.from) {
navigate(state?.from, { state: { from: '/login' } }); // this is needed for AnimatedScreenContainer where we check the state.from
} else {
navigate(-1);
}
navigate(-1);
}
};

Expand Down

0 comments on commit 51e6ceb

Please sign in to comment.