Skip to content

Commit

Permalink
fix(suite): account details animation triggering on first render
Browse files Browse the repository at this point in the history
(cherry picked from commit 2c95e1d)
  • Loading branch information
adamhavel authored and MiroslavProchazka committed Aug 20, 2024
1 parent 3043625 commit b24d080
Showing 1 changed file with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useState, useEffect } from 'react';
import styled, { keyframes } from 'styled-components';
import { Account } from '@suite-common/wallet-types';
import { spacingsPx } from '@trezor/theme';
Expand Down Expand Up @@ -36,11 +37,19 @@ const rotateOut = keyframes`
}
`;

const DetailsContainer = styled.div<{ $isBalanceShown: boolean }>`
const getAnimation = ($isBalanceShown: boolean, $shouldAnimate: boolean) => {
if (!$shouldAnimate) return 'none';

return $isBalanceShown ? rotateIn : rotateOut;
};

const DetailsContainer = styled.div<{ $isBalanceShown: boolean; $shouldAnimate: boolean }>`
display: flex;
flex-direction: column;
justify-content: ${({ $isBalanceShown }) => ($isBalanceShown ? 'space-between' : 'center')};
animation: ${({ $isBalanceShown }) => ($isBalanceShown ? rotateIn : rotateOut)} 0.3s forwards;
animation: ${({ $isBalanceShown, $shouldAnimate }) =>
getAnimation($isBalanceShown, $shouldAnimate)}
0.3s forwards;
`;

const AccountHeading = styled(H2)<{ $isBalanceShown: boolean }>`
Expand Down Expand Up @@ -69,12 +78,25 @@ interface AccountDetailsProps {
}

export const AccountDetails = ({ selectedAccount, isBalanceShown }: AccountDetailsProps) => {
const [shouldAnimate, setShouldAnimate] = useState(false);
const [hasMounted, setHasMounted] = useState(false);
const selectedAccountLabels = useSelector(selectLabelingDataForSelectedAccount);
const { defaultAccountLabelString } = useAccountLabel();
const { symbol, key, path, index, accountType, formattedBalance } = selectedAccount;

useEffect(() => {
setHasMounted(true);
}, []);

useEffect(() => {
if (!hasMounted) return;

setShouldAnimate(true);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isBalanceShown]);

return (
<DetailsContainer $isBalanceShown={isBalanceShown}>
<DetailsContainer $isBalanceShown={isBalanceShown} $shouldAnimate={shouldAnimate}>
<AccountHeading $isBalanceShown={isBalanceShown}>
<MetadataLabeling
defaultVisibleValue={
Expand Down

0 comments on commit b24d080

Please sign in to comment.