From 000352b84e2fd2ebf482145fdd3d96dc458a77af Mon Sep 17 00:00:00 2001 From: Peter Sanderson Date: Wed, 27 Nov 2024 18:32:25 +0100 Subject: [PATCH] feat: add tip warning the developers that they may have bridge disabled in the debug settings --- .../suite/PrerequisitesGuide/Transport.tsx | 34 ++++++++++++--- .../suite/troubleshooting/tips/index.tsx | 43 ++++++++++++++----- 2 files changed, 60 insertions(+), 17 deletions(-) diff --git a/packages/suite/src/components/suite/PrerequisitesGuide/Transport.tsx b/packages/suite/src/components/suite/PrerequisitesGuide/Transport.tsx index 204b67aba784..1d197a1f00cd 100644 --- a/packages/suite/src/components/suite/PrerequisitesGuide/Transport.tsx +++ b/packages/suite/src/components/suite/PrerequisitesGuide/Transport.tsx @@ -1,17 +1,25 @@ +import { isDesktop } from '@trezor/env-utils'; + import { Translation, TroubleshootingTips } from 'src/components/suite'; import { TROUBLESHOOTING_TIP_SUITE_DESKTOP, TROUBLESHOOTING_TIP_RESTART_COMPUTER, TROUBLESHOOTING_TIP_WEBUSB_ENVIRONMENT, + TROUBLESHOOTING_ENABLE_IN_DEBUG, + TipItem, } from 'src/components/suite/troubleshooting/tips'; -export const Transport = () => { - const items = [ - TROUBLESHOOTING_TIP_WEBUSB_ENVIRONMENT, - TROUBLESHOOTING_TIP_SUITE_DESKTOP, - TROUBLESHOOTING_TIP_RESTART_COMPUTER, - ]; +import { useBridgeDesktopApi } from '../../../hooks/suite/useBridgeDesktopApi'; +import { useSelector } from '../../../hooks/suite'; +import { selectIsDebugModeActive } from '../../../reducers/suite/suiteReducer'; + +const tipItems: TipItem[] = [ + TROUBLESHOOTING_TIP_WEBUSB_ENVIRONMENT, + TROUBLESHOOTING_TIP_SUITE_DESKTOP, + TROUBLESHOOTING_TIP_RESTART_COMPUTER, +] as const; +const Tips = ({ items }: { items: TipItem[] }) => { return ( // No transport layer (bridge/webUSB) is available // On web it makes sense to @@ -25,3 +33,17 @@ export const Transport = () => { /> ); }; + +const TransportDesktop = ({ items }: { items: TipItem[] }) => { + const isDebugModeActive = useSelector(selectIsDebugModeActive); + const { bridgeProcess, bridgeSettings } = useBridgeDesktopApi(); + + if (isDebugModeActive && !bridgeProcess.process && !bridgeSettings?.legacy) { + items.push(TROUBLESHOOTING_ENABLE_IN_DEBUG); + } + + return ; +}; + +export const Transport = () => + isDesktop() ? : ; diff --git a/packages/suite/src/components/suite/troubleshooting/tips/index.tsx b/packages/suite/src/components/suite/troubleshooting/tips/index.tsx index 81b2fe205551..a1cfd94a56f4 100644 --- a/packages/suite/src/components/suite/troubleshooting/tips/index.tsx +++ b/packages/suite/src/components/suite/troubleshooting/tips/index.tsx @@ -1,5 +1,8 @@ +import { ReactNode } from 'react'; + import { isWeb, isDesktop, isLinux, isAndroid } from '@trezor/env-utils'; import { TREZOR_SUPPORT_DEVICE_URL } from '@trezor/urls'; +import { Text } from '@trezor/components'; import { TrezorLink } from 'src/components/suite'; import { Translation } from 'src/components/suite/Translation'; @@ -7,21 +10,28 @@ import { Translation } from 'src/components/suite/Translation'; import { BridgeStatus, SuiteDesktopTip, BridgeToggle, Wrapper } from './BridgeTip'; import { UdevDescription } from './UdevDescription'; -export const TROUBLESHOOTING_TIP_BRIDGE_STATUS = { +export type TipItem = { + key: string; + heading: ReactNode; + description: ReactNode; + hide?: boolean; +}; + +export const TROUBLESHOOTING_TIP_BRIDGE_STATUS: TipItem = { key: 'bridge-status', heading: , description: , hide: !isWeb(), }; -export const TROUBLESHOOTING_TIP_WEBUSB_ENVIRONMENT = { +export const TROUBLESHOOTING_TIP_WEBUSB_ENVIRONMENT: TipItem = { key: 'webusb-environment', heading: , description: , hide: !isWeb(), }; -export const TROUBLESHOOTING_TIP_UNREADABLE_HID = { +export const TROUBLESHOOTING_TIP_UNREADABLE_HID: TipItem = { key: 'unreadable-hid', heading: , description: ( @@ -40,53 +50,64 @@ export const TROUBLESHOOTING_TIP_UNREADABLE_HID = { ), }; -export const TROUBLESHOOTING_TIP_SUITE_DESKTOP = { +export const TROUBLESHOOTING_TIP_SUITE_DESKTOP: TipItem = { key: 'suite-desktop', heading: , description: , hide: !isWeb(), }; -export const TROUBLESHOOTING_TIP_SUITE_DESKTOP_TOGGLE_BRIDGE = { +export const TROUBLESHOOTING_TIP_SUITE_DESKTOP_TOGGLE_BRIDGE: TipItem = { key: 'suite-desktop', heading: , description: , hide: isWeb() || isAndroid(), }; -export const TROUBLESHOOTING_TIP_CABLE = { +export const TROUBLESHOOTING_TIP_CABLE: TipItem = { key: 'cable', heading: , description: , }; -export const TROUBLESHOOTING_TIP_USB = { +export const TROUBLESHOOTING_TIP_USB: TipItem = { key: 'usbPort', heading: , description: , hide: isAndroid(), }; -export const TROUBLESHOOTING_TIP_DIFFERENT_COMPUTER = { +export const TROUBLESHOOTING_TIP_DIFFERENT_COMPUTER: TipItem = { key: 'differentComputer', heading: , description: , }; -export const TROUBLESHOOTING_TIP_RESTART_COMPUTER = { +export const TROUBLESHOOTING_TIP_RESTART_COMPUTER: TipItem = { key: 'restartComputer', heading: , description: , }; -export const TROUBLESHOOTING_TIP_UDEV = { +export const TROUBLESHOOTING_ENABLE_IN_DEBUG: TipItem = { + key: 'enableInDebug', + heading: ( + <> + You may have disabled bridge in the debug settings. + + ), + description: <>Try to enable it. You know, ... with the switch., + hide: isWeb(), +}; + +export const TROUBLESHOOTING_TIP_UDEV: TipItem = { key: 'udev', heading: , description: , hide: !isLinux(), }; -export const TROUBLESHOOTING_TIP_RECONNECT = { +export const TROUBLESHOOTING_TIP_RECONNECT: TipItem = { key: 'device-reconnect', heading: , description: (