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 6, 2024
1 parent ad0afa3 commit 441999e
Show file tree
Hide file tree
Showing 16 changed files with 539 additions and 140 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
@@ -1,13 +1,14 @@
import React, { ReactNode } from 'react';
import { Tooltip } from '@trezor/components';
import { spacingsPx } from '@trezor/theme';
import styled from 'styled-components';

const Container = styled.div`
height: 44px;
display: flex;
align-items: center;
justify-content: center;
padding: ${spacingsPx.xs} ${spacingsPx.md};
cursor: pointer;
`;

Expand All @@ -16,15 +17,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,13 +5,14 @@ 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};
display: flex;
gap: ${spacingsPx.xxs};
padding: ${spacingsPx.xxs};
gap: ${spacingsPx.xs};
border-top: 1px solid ${({ theme }) => theme.borderElevation1};
padding: 0 ${spacingsPx.xs};
align-items: stretch;
> * {
Expand All @@ -21,7 +22,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,199 @@
import styled, { css, DefaultTheme, useTheme } from 'styled-components';
import { useDevice } from '../../../../../../../hooks/suite';
import { ComponentWithSubIcon, getIconSize, Icon, IconSize, iconSizes } from '@trezor/components';
import { QuickActionButton } from '../QuickActionButton';
import { UpdateIconGroup } from './UpdateIconGroup';
import { borders, Color, CSSColor } from '@trezor/theme';
import { useUpdateStatus } from './useUpdateStatus';
import { UpdateTooltip } from './UpdateTooltip';
import {
mapTrezorModelToIcon,
mapUpdateStatusToIcon,
mapUpdateStatusToVariant,
UpdateStatus,
UpdateVariant,
} from './updateQuickActionTypes';
import { isDesktop } from '@trezor/env-utils';
import { useDispatch } from 'react-redux';
import { goto } from 'src/actions/suite/routerActions';
import { SettingsAnchor } from '../../../../../../../constants/suite/anchors';

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 HighlightedProps = { $isHighlighted: boolean };

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

const Highlighted = styled.div<HighlightedProps>`
${highlighted}
`;

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

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

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

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

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

type DeviceUpdateIconProps = {
iconSize: IconSize;
updateStatus: UpdateStatus;
variant: UpdateVariant;
};

const DeviceUpdateIcon = ({ iconSize, updateStatus, variant }: DeviceUpdateIconProps) => {
const { device } = useDevice();

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

return (
<Highlighted $isHighlighted={updateStatus !== '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>
);
};

type SuiteUpdateIconProps = {
iconSize: IconSize;
updateStatus: UpdateStatus;
variant: UpdateVariant;
};

const SuiteUpdateIcon = ({ iconSize, updateStatus, variant }: SuiteUpdateIconProps) => {
const theme = useTheme();

return (
<SuiteIconRectangle
$variant={variant}
$isHighlighted={updateStatus !== 'up-to-date'}
$size={iconSize}
>
<Highlighted $isHighlighted={updateStatus !== 'up-to-date'}>
<Icon name="trezor" size={iconSizes.small} color={theme['iconDefaultInverted']} />
</Highlighted>
</SuiteIconRectangle>
);
};

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

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

const updateSubIcon = mapUpdateStatusToIcon[updateStatus];
const variant = mapUpdateStatusToVariant[updateStatus];
const iconSize: IconSize = 'medium';

const isDesktopSuite = isDesktop();

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

const handleOnclick = () => {
if (updateStatusSuite === 'update-available') {
dispatch(goto('settings-index', { anchor: SettingsAnchor.VersionWithUpdate }));
} else if (updateStatusDevice === 'update-available') {
dispatch(goto('settings-device', { anchor: SettingsAnchor.FirmwareVersion }));
}
};

return (
<QuickActionButton
tooltip={
<UpdateTooltip
updateStatusDevice={updateStatusDevice}
updateStatusSuite={updateStatusSuite}
/>
}
onClick={handleOnclick}
>
<ComponentWithSubIcon
variant={variant}
subIconProps={{
name: updateSubIcon,
color: theme.iconDefaultInverted,
size: iconSizes.extraSmall,
}}
>
<UpdateIconGroup $variant={variant}>
<DeviceUpdateIcon
iconSize={iconSize}
updateStatus={updateStatusDevice}
variant={variant}
/>
{isDesktopSuite && (
<SuiteUpdateIcon
iconSize={iconSize}
updateStatus={updateStatusDevice}
variant={variant}
/>
)}
</UpdateIconGroup>
</ComponentWithSubIcon>
</QuickActionButton>
);
};
Loading

0 comments on commit 441999e

Please sign in to comment.