Skip to content

Commit

Permalink
feat(suite): Implementation of the update icons in QuickActions bar
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-sanderson committed Sep 5, 2024
1 parent d916c7a commit 0c7cc3b
Show file tree
Hide file tree
Showing 16 changed files with 459 additions and 135 deletions.
2 changes: 1 addition & 1 deletion packages/suite-desktop-api/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export type HandshakeElectron = {
desktopUpdate?: {
allowPrerelease: boolean;
isAutomaticUpdateEnabled: boolean;
firstRun?: string;
firstRun?: string; // string => contains the version of the updated Suite
};
paths: {
userDir: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const CustomBackend = () => {
size: iconSizes.extraSmall,
}}
>
<Icon name="backend" size={iconSizes.medium} />
<Icon name="backend" size={iconSizes.medium} variant="tertiary" />
</ComponentWithSubIcon>
</QuickActionButton>
</NavBackends>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ type ActionButtonProps = {
children: ReactNode;
tooltip: ReactNode;
'data-testid'?: string;
isOpen?: boolean;
};

export const QuickActionButton = ({
children,
onClick,
tooltip,
'data-testid': dataTest,
isOpen,
}: ActionButtonProps) => (
<Tooltip content={tooltip} cursor="pointer">
<Tooltip content={tooltip} cursor="pointer" isOpen={isOpen}>
<Container data-testid={dataTest} onClick={onClick}>
{children}
</Container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Tor } from './Tor';
import { CustomBackend } from './CustomBackend';
import { DebugAndExperimental } from './DebugAndExperimental';
import { HideBalances } from './HideBalances';
// import { Update } from './Update';
import { Update } from './Update/Update';

const ActionsContainer = styled.div`
border-top: 1px solid ${({ theme }) => theme.borderElevation1};
Expand All @@ -21,7 +21,7 @@ const ActionsContainer = styled.div`

export const QuickActions = () => (
<ActionsContainer>
{/* <Update /> */}
<Update />
<DebugAndExperimental />
<CustomBackend />
<Tor />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const Tor = () => {
size: iconSizes.extraSmall,
}}
>
<Icon name="tor" size={iconSizes.medium} />
<Icon name="tor" size={iconSizes.medium} variant="tertiary" />
</ComponentWithSubIcon>
</QuickActionButton>
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import styled, { css, DefaultTheme, useTheme } from 'styled-components';
import { useDevice } from '../../../../../../../hooks/suite';
import { ComponentWithSubIcon, getIconSize, Icon, iconSizes, Row } from '@trezor/components';
import { QuickActionButton } from '../QuickActionButton';
import { UpdateIconGroup } from './UpdateIconGroup';
import { borders, Color, CSSColor, spacings } from '@trezor/theme';
import { useUpdateStatus } from './useUpdateStatus';
import { UpdateTooltip } from './UpdateTooltip';
import {
mapTrezorModelToIcon,
mapUpdateStatusToIcon,
mapUpdateStatusToVariant,
UpdateVariant,
} from './updateQuickActionTypes';

type MapArgs = {
$variant: UpdateVariant;
theme: DefaultTheme;
};

export const mapVariantToIconColor = ({ $variant, theme }: MapArgs): CSSColor => {
const colorMap: Record<UpdateVariant, Color> = {
info: 'iconAlertBlue',
purple: 'iconAlertPurple',
tertiary: 'iconSubdued',
};

return theme[colorMap[$variant]];
};

type SuiteIconRectangle = {
$variant: UpdateVariant;
$isHighlighted: boolean;
$size: number;
};

const SuiteIconRectangle = styled.div<SuiteIconRectangle>`
display: flex;
align-items: center;
justify-content: center;
padding-left: 0.5px;
width: ${({ $size }) => $size}px;
height: ${({ $size }) => $size}px;
border-radius: ${borders.radii.xxs};
background-color: ${({ $variant, theme }) => mapVariantToIconColor({ $variant, theme })};
${({ $isHighlighted }) =>
$isHighlighted
? ''
: css`
opacity: 50%;
`}
`;

type HighlightedProps = { $isHighlighted: boolean };

const Highlighted = styled.div<HighlightedProps>`
${({ $isHighlighted }) =>
$isHighlighted
? ''
: css`
opacity: 50%;
`}
`;

const Relative = styled.div<{ $size: number }>`
position: relative;
width: ${({ $size }) => $size}px;
height: ${({ $size }) => $size}px;
`;

type UsbCableFroTrezorIcon = {
$variant: UpdateVariant;
$size: number;
};

const UsbCableFroTrezorIcon = styled.div<UsbCableFroTrezorIcon>`
border-left: 2px solid ${({ $variant, theme }) => mapVariantToIconColor({ $variant, theme })};
height: 5px;
position: absolute;
bottom: -4px;
left: ${({ $size }) => $size / 2}px;
`;

export const Update = () => {
const theme = useTheme();

const { updateStatus, updateStatusDevice, updateStatusSuite } = useUpdateStatus();
const { device } = useDevice();

const updateSubIcon = mapUpdateStatusToIcon[updateStatus];
const variant = mapUpdateStatusToVariant[updateStatus];
const iconSize = getIconSize(iconSizes.medium);

if (device?.features === undefined) {
return null;
}

return (
<QuickActionButton
tooltip={
<UpdateTooltip
updateStatusDevice={updateStatusDevice}
updateStatusSuite={updateStatusSuite}
/>
}
isOpen
>
<ComponentWithSubIcon
variant={variant}
subIconProps={{
name: updateSubIcon,
color: theme.iconDefaultInverted,
size: iconSizes.extraSmall,
}}
>
<UpdateIconGroup $variant={variant}>
<Row gap={spacings.xxs}>
<Highlighted $isHighlighted={updateStatusDevice !== 'up-to-date'}>
<Relative $size={iconSize}>
<Icon
name={mapTrezorModelToIcon[device.features.internal_model]}
size={iconSizes.medium}
variant={variant}
/>
<UsbCableFroTrezorIcon $variant={variant} $size={iconSize} />
</Relative>
</Highlighted>
<SuiteIconRectangle
$variant={variant}
$isHighlighted={updateStatusSuite !== 'up-to-date'}
$size={iconSize}
>
<Highlighted $isHighlighted={updateStatusSuite !== 'up-to-date'}>
<Icon
name="trezor"
size={iconSizes.small}
color={theme['iconDefaultInverted']}
/>
</Highlighted>
</SuiteIconRectangle>
</Row>
</UpdateIconGroup>
</ComponentWithSubIcon>
</QuickActionButton>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { spacingsPx } from '@trezor/theme';
import styled, { css } from 'styled-components';
import { mapVariantToIconBackground, UpdateVariant } from './updateQuickActionTypes';

type UpdateIconGroupProps = {
$variant?: UpdateVariant;
};

export const UpdateIconGroup = styled.div<UpdateIconGroupProps>`
display: flex;
align-items: center;
justify-content: center;
padding: ${spacingsPx.xxs} ${spacingsPx.xxs};
margin: -${spacingsPx.xxs};
background-color: ${({ $variant, theme }) =>
$variant && mapVariantToIconBackground({ $variant, theme })};
border-radius: 6px;
${({ $variant, theme }) =>
$variant === 'tertiary'
? css`
border: 1.5px solid ${theme['borderElevationNegative']};
`
: ''};
`;
Loading

0 comments on commit 0c7cc3b

Please sign in to comment.