|
| 1 | +import { useMemo } from 'react'; |
| 2 | + |
| 3 | +import { Button, Modal } from '@trezor/components'; |
| 4 | +import { isDesktop } from '@trezor/env-utils'; |
| 5 | +import { TREZOR_SUPPORT_URL } from '@trezor/urls'; |
| 6 | + |
| 7 | +import { Translation } from 'src/components/suite/Translation'; |
| 8 | +import { TroubleshootingTipsItem } from 'src/components/suite/troubleshooting/TroubleshootingTips'; |
| 9 | +import { TroubleshootingTipsList } from 'src/components/suite/troubleshooting/TroubleshootingTipsList'; |
| 10 | +import { |
| 11 | + TROUBLESHOOTING_ALL_BLUETOOTH_TIPS, |
| 12 | + TROUBLESHOOTING_TIP_BRIDGE_STATUS, |
| 13 | + TROUBLESHOOTING_TIP_CABLE, |
| 14 | + TROUBLESHOOTING_TIP_DIFFERENT_COMPUTER, |
| 15 | + TROUBLESHOOTING_TIP_SUITE_DESKTOP, |
| 16 | + TROUBLESHOOTING_TIP_SUITE_DESKTOP_TOGGLE_BRIDGE, |
| 17 | + TROUBLESHOOTING_TIP_UDEV, |
| 18 | + TROUBLESHOOTING_TIP_USB, |
| 19 | +} from 'src/components/suite/troubleshooting/tips'; |
| 20 | +import { useSelector } from 'src/hooks/suite'; |
| 21 | +import { useBridgeDesktopApi } from 'src/hooks/suite/useBridgeDesktopApi'; |
| 22 | +import { selectHasTransportOfType } from 'src/selectors/suite/suiteSelectors'; |
| 23 | + |
| 24 | +type DontSeeYourTrezorModalProps = { |
| 25 | + isBluetoothMode: boolean; |
| 26 | + onGoBack?: () => void; |
| 27 | +}; |
| 28 | + |
| 29 | +const commonCableTips = [ |
| 30 | + TROUBLESHOOTING_TIP_UDEV, |
| 31 | + TROUBLESHOOTING_TIP_CABLE, |
| 32 | + TROUBLESHOOTING_TIP_USB, |
| 33 | +]; |
| 34 | + |
| 35 | +export const DontSeeYourTrezorModal = ({ |
| 36 | + onGoBack, |
| 37 | + isBluetoothMode, |
| 38 | +}: DontSeeYourTrezorModalProps) => { |
| 39 | + const isWebUsbTransport = useSelector(selectHasTransportOfType('WebUsbTransport')); |
| 40 | + |
| 41 | + const bridgeDesktopApi = useBridgeDesktopApi(); |
| 42 | + |
| 43 | + const openTrezorSupport = () => { |
| 44 | + window.open(TREZOR_SUPPORT_URL, '_blank'); |
| 45 | + onGoBack?.(); |
| 46 | + }; |
| 47 | + |
| 48 | + const cableItem: TroubleshootingTipsItem[] = useMemo(() => { |
| 49 | + const items = isWebUsbTransport |
| 50 | + ? [...commonCableTips, TROUBLESHOOTING_TIP_SUITE_DESKTOP] |
| 51 | + : [ |
| 52 | + TROUBLESHOOTING_TIP_BRIDGE_STATUS, |
| 53 | + ...commonCableTips, |
| 54 | + TROUBLESHOOTING_TIP_DIFFERENT_COMPUTER, |
| 55 | + ]; |
| 56 | + |
| 57 | + if (bridgeDesktopApi?.bridgeProcess?.process) { |
| 58 | + items.push(TROUBLESHOOTING_TIP_SUITE_DESKTOP_TOGGLE_BRIDGE); |
| 59 | + } else { |
| 60 | + // TODO: here we are going to put instruction to uninstall standalone bridge |
| 61 | + } |
| 62 | + |
| 63 | + return items; |
| 64 | + }, [isWebUsbTransport, bridgeDesktopApi]); |
| 65 | + |
| 66 | + const tipItems = useMemo(() => { |
| 67 | + if (isBluetoothMode && isDesktop()) { |
| 68 | + return TROUBLESHOOTING_ALL_BLUETOOTH_TIPS; |
| 69 | + } |
| 70 | + |
| 71 | + return cableItem; |
| 72 | + }, [isBluetoothMode, cableItem]); |
| 73 | + |
| 74 | + return ( |
| 75 | + <Modal |
| 76 | + bottomContent={ |
| 77 | + <> |
| 78 | + <Button onClick={onGoBack} variant="info"> |
| 79 | + <Translation |
| 80 | + id={isBluetoothMode ? 'TR_BLUETOOTH_SCAN_AGAIN' : 'TR_GOT_IT'} |
| 81 | + /> |
| 82 | + </Button> |
| 83 | + <Button |
| 84 | + variant="tertiary" |
| 85 | + onClick={isBluetoothMode ? onGoBack : openTrezorSupport} |
| 86 | + > |
| 87 | + <Translation |
| 88 | + id={isBluetoothMode ? 'TR_CANCEL' : 'TR_CONTACT_TREZOR_SUPPORT'} |
| 89 | + /> |
| 90 | + </Button> |
| 91 | + </> |
| 92 | + } |
| 93 | + heading={<Translation id="TR_STILL_DONT_SEE_YOUR_TREZOR" />} |
| 94 | + onCancel={onGoBack} |
| 95 | + > |
| 96 | + <TroubleshootingTipsList items={tipItems} /> |
| 97 | + </Modal> |
| 98 | + ); |
| 99 | +}; |
0 commit comments