Skip to content

Commit

Permalink
feat: add tip warning the developers that they may have bridge disabl…
Browse files Browse the repository at this point in the history
…ed in the debug settings
  • Loading branch information
peter-sanderson committed Nov 28, 2024
1 parent 5ac9e53 commit 000352b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <Tips items={items} />;
};

export const Transport = () =>
isDesktop() ? <TransportDesktop items={tipItems} /> : <Tips items={tipItems} />;
43 changes: 32 additions & 11 deletions packages/suite/src/components/suite/troubleshooting/tips/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
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';

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: <Translation id="TR_TROUBLESHOOTING_TIP_BRIDGE_STATUS_TITLE" />,
description: <BridgeStatus />,
hide: !isWeb(),
};

export const TROUBLESHOOTING_TIP_WEBUSB_ENVIRONMENT = {
export const TROUBLESHOOTING_TIP_WEBUSB_ENVIRONMENT: TipItem = {
key: 'webusb-environment',
heading: <Translation id="TR_TROUBLESHOOTING_TIP_BROWSER_WEBUSB_TITLE" />,
description: <Translation id="TR_TROUBLESHOOTING_TIP_BROWSER_WEBUSB_DESCRIPTION" />,
hide: !isWeb(),
};

export const TROUBLESHOOTING_TIP_UNREADABLE_HID = {
export const TROUBLESHOOTING_TIP_UNREADABLE_HID: TipItem = {
key: 'unreadable-hid',
heading: <Translation id="TR_TROUBLESHOOTING_TIP_UNREADABLE_HID_TITLE" />,
description: (
Expand All @@ -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: <Translation id="TR_TROUBLESHOOTING_TIP_SUITE_DESKTOP_TITLE" />,
description: <SuiteDesktopTip />,
hide: !isWeb(),
};

export const TROUBLESHOOTING_TIP_SUITE_DESKTOP_TOGGLE_BRIDGE = {
export const TROUBLESHOOTING_TIP_SUITE_DESKTOP_TOGGLE_BRIDGE: TipItem = {
key: 'suite-desktop',
heading: <Translation id="TR_TROUBLESHOOTING_TIP_SUITE_DESKTOP_TOGGLE_BRIDGE_TITLE" />,
description: <BridgeToggle />,
hide: isWeb() || isAndroid(),
};

export const TROUBLESHOOTING_TIP_CABLE = {
export const TROUBLESHOOTING_TIP_CABLE: TipItem = {
key: 'cable',
heading: <Translation id="TR_TROUBLESHOOTING_TIP_CABLE_TITLE" />,
description: <Translation id="TR_TROUBLESHOOTING_TIP_CABLE_DESCRIPTION" />,
};

export const TROUBLESHOOTING_TIP_USB = {
export const TROUBLESHOOTING_TIP_USB: TipItem = {
key: 'usbPort',
heading: <Translation id="TR_TROUBLESHOOTING_TIP_USB_PORT_TITLE" />,
description: <Translation id="TR_TROUBLESHOOTING_TIP_USB_PORT_DESCRIPTION" />,
hide: isAndroid(),
};

export const TROUBLESHOOTING_TIP_DIFFERENT_COMPUTER = {
export const TROUBLESHOOTING_TIP_DIFFERENT_COMPUTER: TipItem = {
key: 'differentComputer',
heading: <Translation id="TR_TROUBLESHOOTING_TIP_COMPUTER_TITLE" />,
description: <Translation id="TR_TROUBLESHOOTING_TIP_COMPUTER_DESCRIPTION" />,
};

export const TROUBLESHOOTING_TIP_RESTART_COMPUTER = {
export const TROUBLESHOOTING_TIP_RESTART_COMPUTER: TipItem = {
key: 'restartComputer',
heading: <Translation id="TR_TROUBLESHOOTING_TIP_RESTART_COMPUTER_TITLE" />,
description: <Translation id="TR_TROUBLESHOOTING_TIP_RESTART_COMPUTER_DESCRIPTION" />,
};

export const TROUBLESHOOTING_TIP_UDEV = {
export const TROUBLESHOOTING_ENABLE_IN_DEBUG: TipItem = {
key: 'enableInDebug',
heading: (
<>
You may have <Text variant="destructive">disabled bridge in the debug</Text> settings.
</>
),
description: <>Try to enable it. You know, ... with the switch.</>,
hide: isWeb(),
};

export const TROUBLESHOOTING_TIP_UDEV: TipItem = {
key: 'udev',
heading: <Translation id="TR_UDEV_DOWNLOAD_TITLE" />,
description: <UdevDescription />,
hide: !isLinux(),
};

export const TROUBLESHOOTING_TIP_RECONNECT = {
export const TROUBLESHOOTING_TIP_RECONNECT: TipItem = {
key: 'device-reconnect',
heading: <Translation id="TR_RECONNECT_YOUR_DEVICE" />,
description: (
Expand Down

0 comments on commit 000352b

Please sign in to comment.