From 967fc34578fc49432f6ab9ab7c8a7211512581bc Mon Sep 17 00:00:00 2001 From: Martin Varmuza Date: Mon, 27 Jan 2025 13:29:26 +0100 Subject: [PATCH] fix(suite): add missing 'use device here' button in the device settings --- .../e2e/tests/suite/multiple-sessions.test.ts | 3 ++ .../src/components/settings/DeviceBanner.tsx | 21 +++++------ .../components/suite/AcquireDeviceButton.tsx | 36 +++++++++++++++++++ .../DeviceUsedElsewhere.tsx | 25 +++---------- 4 files changed, 55 insertions(+), 30 deletions(-) create mode 100644 packages/suite/src/components/suite/AcquireDeviceButton.tsx diff --git a/packages/suite-desktop-core/e2e/tests/suite/multiple-sessions.test.ts b/packages/suite-desktop-core/e2e/tests/suite/multiple-sessions.test.ts index 5f5eac7cd5c..789dba4b4d5 100644 --- a/packages/suite-desktop-core/e2e/tests/suite/multiple-sessions.test.ts +++ b/packages/suite-desktop-core/e2e/tests/suite/multiple-sessions.test.ts @@ -96,4 +96,7 @@ test.describe('Multiple sessions', { tag: ['@group=suite'] }, () => { await expect(dashboardPage.deviceStatus).toHaveText('Refresh'); }, ); + + // todo: test what happens if you steal session and navigate directly to device settings (web) + // todo: test the same for other routes as well (/recovery, /backup, etc..) }); diff --git a/packages/suite/src/components/settings/DeviceBanner.tsx b/packages/suite/src/components/settings/DeviceBanner.tsx index 6621bb0e81f..a382edf73fd 100644 --- a/packages/suite/src/components/settings/DeviceBanner.tsx +++ b/packages/suite/src/components/settings/DeviceBanner.tsx @@ -2,13 +2,19 @@ import { ReactNode } from 'react'; import styled from 'styled-components'; -import { Card, LottieAnimation, Paragraph, Row, variables, Text } from '@trezor/components'; +import { Card, Column, LottieAnimation, Paragraph, Row, variables, Text } from '@trezor/components'; import { spacings } from '@trezor/theme'; import { useDevice, useSelector } from 'src/hooks/suite'; import { WebUsbButton } from 'src/components/suite/WebUsbButton'; import { selectHasTransportOfType } from 'src/reducers/suite/suiteReducer'; +import { AcquireDeviceButton } from '../suite/AcquireDeviceButton'; + +const StyledAcquireDeviceButton = styled(AcquireDeviceButton)` + margin-left: auto; +`; + // eslint-disable-next-line local-rules/no-override-ds-component const StyledLottieAnimation = styled(LottieAnimation)` margin: 8px 16px 8px 0; @@ -16,13 +22,6 @@ const StyledLottieAnimation = styled(LottieAnimation)` background: ${({ theme }) => theme.legacy.BG_GREY}; `; -const Column = styled.div` - display: flex; - flex-direction: column; - justify-content: center; - width: 100%; -`; - // eslint-disable-next-line local-rules/no-override-ds-component const Title = styled(Paragraph)` display: flex; @@ -38,10 +37,10 @@ const Title = styled(Paragraph)` } `; -interface DeviceBannerProps { +type DeviceBannerProps = { title: ReactNode; description?: ReactNode; -} +}; export const DeviceBanner = ({ title, description }: DeviceBannerProps) => { const { device } = useDevice(); @@ -69,6 +68,8 @@ export const DeviceBanner = ({ title, description }: DeviceBannerProps) => { {description && {description}} + + {!device?.features && } ); diff --git a/packages/suite/src/components/suite/AcquireDeviceButton.tsx b/packages/suite/src/components/suite/AcquireDeviceButton.tsx new file mode 100644 index 00000000000..4a39f803bcb --- /dev/null +++ b/packages/suite/src/components/suite/AcquireDeviceButton.tsx @@ -0,0 +1,36 @@ +import { MouseEventHandler } from 'react'; + +import { acquireDevice } from '@suite-common/wallet-core'; +import { Button } from '@trezor/components'; + +import { useDevice, useDispatch } from 'src/hooks/suite'; + +import { Translation } from './Translation'; + +type AcquireButtonProps = { + className?: string; + onClick?: MouseEventHandler; +}; + +export const AcquireDeviceButton = ({ className, onClick }: AcquireButtonProps) => { + const { isLocked } = useDevice(); + const dispatch = useDispatch(); + + const isDeviceLocked = isLocked(); + + const handleClick: MouseEventHandler = e => { + onClick?.(e); + dispatch(acquireDevice()); + }; + + return ( + + ); +}; diff --git a/packages/suite/src/components/suite/PrerequisitesGuide/DeviceUsedElsewhere.tsx b/packages/suite/src/components/suite/PrerequisitesGuide/DeviceUsedElsewhere.tsx index 7c8394371a7..7cfb62eaf88 100644 --- a/packages/suite/src/components/suite/PrerequisitesGuide/DeviceUsedElsewhere.tsx +++ b/packages/suite/src/components/suite/PrerequisitesGuide/DeviceUsedElsewhere.tsx @@ -1,36 +1,21 @@ import { MouseEventHandler } from 'react'; -import { acquireDevice } from '@suite-common/wallet-core'; -import { Button } from '@trezor/components'; - import { Translation, TroubleshootingTips } from 'src/components/suite'; -import { useDevice, useDispatch } from 'src/hooks/suite'; +import { useDevice } from 'src/hooks/suite'; import { TROUBLESHOOTING_TIP_RECONNECT, TROUBLESHOOTING_TIP_CLOSE_ALL_TABS, } from 'src/components/suite/troubleshooting/tips'; -export const DeviceUsedElsewhere = () => { - const { isLocked, device } = useDevice(); - const dispatch = useDispatch(); +import { AcquireDeviceButton } from '../AcquireDeviceButton'; - const isDeviceLocked = isLocked(); +export const DeviceUsedElsewhere = () => { + const { device } = useDevice(); const handleClick: MouseEventHandler = e => { e.stopPropagation(); - dispatch(acquireDevice()); }; - const ctaButton = ( - - ); - const tips = [ { key: 'device-used-elsewhere', @@ -51,7 +36,7 @@ export const DeviceUsedElsewhere = () => { return ( } - cta={ctaButton} + cta={} items={tips} /> );