Skip to content

Commit

Permalink
chore(suite): fix aborted discovery process in wallet switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhavel committed Nov 6, 2024
1 parent 47555aa commit 527a53b
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 223 deletions.
20 changes: 19 additions & 1 deletion packages/components/src/components/Card/Card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,23 @@ export default meta;

export const Card: StoryObj = {
args: {
children: <p>Lorem ipsum</p>,
children: (
<p>
Quos delectus veritatis est doloribus dolor. Odit fugit omnis magni ipsam quia rem
aut. Et alias sint non. Consequuntur dignissimos veritatis debitis corporis esse.
Quaerat voluptatem unde aut. Iusto laborum omnis quis amet atque. Sint culpa
delectus non soluta temporibus saepe. Sequi saepe corrupti aliquam ut sit assumenda
aspernatur consequuntur. Ut est ullam iusto facilis voluptatibus. Sit est cum quos.
Quasi deleniti non fugit iste alias consequuntur. Ullam ad ut culpa est reiciendis
molestiae. Reiciendis ab veritatis a totam inventore nihil voluptatem occaecati.
Quisquam atque odit quia nam. Laboriosam rem et ut. Maxime qui voluptatem
voluptatem.
</p>
),
label: '',
paddingType: 'normal',
fillType: 'default',
isHiglighted: false,
...getFramePropsStory(allowedCardFrameProps).args,
},
argTypes: {
Expand All @@ -35,6 +48,11 @@ export const Card: StoryObj = {
type: 'radio',
},
},
isHiglighted: {
control: {
type: 'boolean',
},
},
...getFramePropsStory(allowedCardFrameProps).argTypes,
},
};
26 changes: 25 additions & 1 deletion packages/components/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { forwardRef, HTMLAttributes, ReactNode } from 'react';
import styled from 'styled-components';
import styled, { css } from 'styled-components';
import { borders, Elevation, spacingsPx } from '@trezor/theme';
import { ElevationUp, useElevation } from '../ElevationContext/ElevationContext';
import {
Expand Down Expand Up @@ -46,12 +46,14 @@ const CardContainer = styled.div<
$paddingType: PaddingType;
$fillType: FillType;
$isClickable: boolean;
$isHiglighted: boolean;
$hasLabel: boolean;
} & TransientProps<AllowedFrameProps>
>`
width: 100%;
display: flex;
flex-direction: column;
position: relative;
padding: ${mapPaddingTypeToPadding};
border-radius: ${borders.radii.md};
transition:
Expand All @@ -60,6 +62,23 @@ const CardContainer = styled.div<
border-color 0.2s;
cursor: ${({ $isClickable }) => ($isClickable ? 'pointer' : 'default')};
${({ theme, $isHiglighted, $paddingType }) =>
$isHiglighted &&
css`
overflow: hidden;
padding-left: calc(${spacingsPx.xxs} + ${mapPaddingTypeToPadding({ $paddingType })});
&::before {
content: '';
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: ${spacingsPx.xxs};
background: ${theme.backgroundSecondaryDefault};
}
`}
${mapFillTypeToCSS}
${withFrameProps}
`;
Expand All @@ -73,6 +92,7 @@ type CommonCardProps = AccessibilityProps & {
children?: ReactNode;
className?: string;
label?: ReactNode;
isHiglighted?: boolean;
'data-testid'?: string;
};

Expand All @@ -91,6 +111,7 @@ const CardComponent = forwardRef<HTMLDivElement, CardPropsWithTransientProps>(
className,
tabIndex,
label,
isHiglighted = false,
'data-testid': dataTest,
...rest
},
Expand All @@ -105,6 +126,7 @@ const CardComponent = forwardRef<HTMLDivElement, CardPropsWithTransientProps>(
$paddingType={paddingType}
$fillType={fillType}
$isClickable={Boolean(onClick)}
$isHiglighted={isHiglighted}
$hasLabel={Boolean(label)}
onClick={onClick}
onMouseEnter={onMouseEnter}
Expand Down Expand Up @@ -133,6 +155,7 @@ export const Card = forwardRef<HTMLDivElement, CardProps>(
tabIndex,
children,
'data-testid': dataTest,
isHiglighted,
...rest
},
ref,
Expand All @@ -147,6 +170,7 @@ export const Card = forwardRef<HTMLDivElement, CardProps>(
fillType,
children,
label,
isHiglighted,
'data-testid': dataTest,
};
const frameProps = pickAndPrepareFrameProps(rest, allowedCardFrameProps);
Expand Down
11 changes: 6 additions & 5 deletions packages/components/src/components/Card/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Elevation,
mapElevationToBackground,
mapElevationToBorder,
SpacingPxValues,
} from '@trezor/theme';
import { css, DefaultTheme, RuleSet } from 'styled-components';
import { PaddingType, FillType } from './types';
Expand All @@ -19,8 +20,8 @@ type FillTypeMapArgs = {
theme: DefaultTheme;
};

export const mapPaddingTypeToLabelPadding = ({ $paddingType }: PaddingMapArgs): number | string => {
const paddingMap: Record<PaddingType, number | string> = {
export const mapPaddingTypeToLabelPadding = ({ $paddingType }: PaddingMapArgs): string => {
const paddingMap: Record<PaddingType, string> = {
none: `${spacingsPx.xxs} 0`,
small: `${spacingsPx.xxs} ${spacingsPx.sm}`,
normal: `${spacingsPx.xs} ${spacingsPx.lg}`,
Expand All @@ -30,9 +31,9 @@ export const mapPaddingTypeToLabelPadding = ({ $paddingType }: PaddingMapArgs):
return paddingMap[$paddingType];
};

export const mapPaddingTypeToPadding = ({ $paddingType }: PaddingMapArgs): number | string => {
const paddingMap: Record<PaddingType, number | string> = {
none: 0,
export const mapPaddingTypeToPadding = ({ $paddingType }: PaddingMapArgs): SpacingPxValues => {
const paddingMap: Record<PaddingType, SpacingPxValues> = {
none: '0px',
small: spacingsPx.sm,
normal: spacingsPx.lg,
large: spacingsPx.xl,
Expand Down
32 changes: 18 additions & 14 deletions packages/components/src/components/Divider/Divider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import styled from 'styled-components';
import styled, { css } from 'styled-components';
import { Color, Elevation, mapElevationToBorder, spacings } from '@trezor/theme';
import { useElevation } from '../ElevationContext/ElevationContext';
import {
Expand All @@ -8,13 +8,16 @@ import {
withFrameProps,
} from '../../utils/frameProps';
import { TransientProps } from '../../utils/transientProps';
import { allowedHeadingFrameProps } from '../typography/Heading/Heading';

export const allowedDividerFrameProps = ['margin'] as const satisfies FramePropsKeys[];
export const allowedDividerFrameProps = [
'margin',
'width',
'overflow',
] as const satisfies FramePropsKeys[];
type AllowedFrameProps = Pick<FrameProps, (typeof allowedDividerFrameProps)[number]>;
type DividerOrientation = 'horizontal' | 'vertical';

type DividerProps = AllowedFrameProps & {
export type DividerProps = AllowedFrameProps & {
orientation?: DividerOrientation;
strokeWidth?: number;
color?: Color;
Expand All @@ -30,15 +33,16 @@ const Line = styled.div<
>`
${({ $orientation, $strokeWidth }) =>
$orientation === 'vertical'
? `
height: 100%;
width: ${$strokeWidth}px;
min-width: ${$strokeWidth}px;`
: `
width: 100%;
height: ${$strokeWidth}px;
min-height: ${$strokeWidth}px;
`}
? css`
height: 100%;
width: ${$strokeWidth}px;
min-width: ${$strokeWidth}px;
`
: css`
width: 100%;
height: ${$strokeWidth}px;
min-height: ${$strokeWidth}px;
`}
background: ${({ theme, $elevation, $color }) =>
$color ? theme[$color] : mapElevationToBorder({ theme, $elevation })};
Expand All @@ -56,7 +60,7 @@ export const Divider = ({

const frameProps = pickAndPrepareFrameProps(
{ ...rest, margin: rest.margin ?? { top: spacings.md, bottom: spacings.md } },
allowedHeadingFrameProps,
allowedDividerFrameProps,
);

return (
Expand Down
14 changes: 7 additions & 7 deletions packages/components/src/utils/frameProps.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { css } from 'styled-components';
import { makePropsTransient, TransientProps } from './transientProps';
import { SpacingValues } from '@trezor/theme';
import { SpacingValues, SpacingPxValues } from '@trezor/theme';

type Margin = {
top?: SpacingValues | 'auto';
bottom?: SpacingValues | 'auto';
left?: SpacingValues | 'auto';
right?: SpacingValues | 'auto';
horizontal?: SpacingValues | 'auto';
vertical?: SpacingValues | 'auto';
top?: SpacingValues | SpacingPxValues | 'auto';
bottom?: SpacingValues | SpacingPxValues | 'auto';
left?: SpacingValues | SpacingPxValues | 'auto';
right?: SpacingValues | SpacingPxValues | 'auto';
horizontal?: SpacingValues | SpacingPxValues | 'auto';
vertical?: SpacingValues | SpacingPxValues | 'auto';
};
const overflows = [
'auto',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import styled, { useTheme } from 'styled-components';
import { useTheme } from 'styled-components';

import { Tooltip, Icon, useElevation } from '@trezor/components';
import { Tooltip, Icon } from '@trezor/components';
import { Translation } from 'src/components/suite';
import { Elevation, borders, mapElevationToBackground, spacingsPx } from '@trezor/theme';
import { ContentType } from '../types';

const EjectContainer = styled.div<{ $elevation: Elevation }>`
position: absolute;
right: ${spacingsPx.xs};
top: ${spacingsPx.xs};
background-color: ${mapElevationToBackground};
border-radius: ${borders.radii.full};
padding: ${spacingsPx.xxs};
`;

interface EjectButtonProps {
setContentType: (contentType: ContentType) => void;
'data-testid'?: string;
Expand All @@ -27,20 +17,16 @@ export const EjectButton = ({ setContentType, 'data-testid': dataTest }: EjectBu
e.stopPropagation();
};

const { elevation } = useElevation();

return (
<EjectContainer $elevation={elevation}>
<Tooltip cursor="pointer" content={<Translation id="TR_EJECT_HEADING" />}>
<Icon
data-testid={`${dataTest}/eject-button`}
name="eject"
size={22}
color={theme.legacy.TYPE_LIGHT_GREY}
hoverColor={theme.legacy.TYPE_DARK_GREY}
onClick={onEjectClick}
/>
</Tooltip>
</EjectContainer>
<Tooltip cursor="pointer" content={<Translation id="TR_EJECT_HEADING" />}>
<Icon
data-testid={`${dataTest}/eject-button`}
name="eject"
size={22}
variant="tertiary"
hoverColor={theme.textDefault}
onClick={onEjectClick}
/>
</Tooltip>
);
};
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
import styled from 'styled-components';
import { useDispatch, useSelector } from 'src/hooks/suite';
import { H3, Button, Text } from '@trezor/components';
import { H4, Button, Paragraph, Row } from '@trezor/components';
import { Translation } from 'src/components/suite';
import { deviceActions } from '@suite-common/wallet-core';
import { analytics, EventType } from '@trezor/suite-analytics';
import { AcquiredDevice } from '@suite-common/suite-types';
import { MouseEventHandler, ReactNode } from 'react';
import { spacings, spacingsPx } from '@trezor/theme';
import { spacings } from '@trezor/theme';
import { selectSuiteSettings } from '../../../../reducers/suite/suiteReducer';

const Container = styled.div`
margin: 0 ${spacingsPx.xxs};
cursor: auto;
`;

const Description = styled.div`
margin: ${spacingsPx.xs} 0 ${spacingsPx.md} 0;
`;

const Buttons = styled.div`
display: flex;
gap: ${spacingsPx.xxs};
`;

type EjectConfirmationProps = {
onCancel: MouseEventHandler<HTMLButtonElement> | undefined;
onClick: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
Expand Down Expand Up @@ -57,32 +47,32 @@ const EjectConfirmationContainer = ({

return (
<Container onClick={onClick}>
<H3>{title}</H3>
<Description>
<Text variant="tertiary">{description}</Text>
</Description>
<Buttons>
<H4>{title}</H4>
<Paragraph variant="tertiary" typographyStyle="hint" margin={{ top: spacings.xxs }}>
{description}
</Paragraph>
<Row gap={spacings.xs} margin={{ top: spacings.md }}>
<Button
size="small"
icon="eject"
iconSize={spacings.lg}
onClick={handleEject}
variant="primary"
isFullWidth
data-testid="@switch-device/eject"
isFullWidth
>
{primaryButtonLabel}
</Button>
<Button
size="small"
onClick={onCancel}
variant="tertiary"
isFullWidth
data-testid="@switch-device/cancelEject"
isFullWidth
>
<Translation id="TR_SWITCH_DEVICE_EJECT_CONFIRMATION_CANCEL_BUTTON" />
</Button>
</Buttons>
</Row>
</Container>
);
};
Expand Down
Loading

0 comments on commit 527a53b

Please sign in to comment.