Skip to content

Commit

Permalink
feat(suite): open suite desktop from troubleshooting tip directly
Browse files Browse the repository at this point in the history
  • Loading branch information
martykan authored and mroz22 committed Jul 26, 2024
1 parent 3218b74 commit f6b0fe5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
5 changes: 2 additions & 3 deletions packages/suite/src/components/suite/troubleshooting/tips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { goto } from 'src/actions/suite/routerActions';
import { typography } from '@trezor/theme';
import styled from 'styled-components';
import { isWebUsb } from 'src/utils/suite/transport';
import { useOpenSuiteDesktop } from 'src/hooks/suite/useOpenSuiteDesktop';

const Wrapper = styled.div`
a {
Expand Down Expand Up @@ -57,9 +58,7 @@ const BridgeStatus = () => (
);

const BridgeInstall = () => {
const dispatch = useDispatch();

const handleClick = () => dispatch(goto('suite-bridge'));
const handleClick = useOpenSuiteDesktop();

return (
<Wrapper>
Expand Down
26 changes: 26 additions & 0 deletions packages/suite/src/hooks/suite/useOpenSuiteDesktop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import TrezorConnect from '@trezor/connect';
import { useWindowFocus } from '@trezor/react-utils';
import { SUITE_BRIDGE_DEEPLINK, SUITE_URL } from '@trezor/urls';
import { isWebUsb } from 'src/utils/suite/transport';
import { useSelector } from 'src/hooks/suite';

export const useOpenSuiteDesktop = () => {
const transport = useSelector(state => state.suite.transport);
const windowFocused = useWindowFocus();
const handleOpenSuite = () => {
if (isWebUsb(transport)) {
TrezorConnect.disableWebUSB();
}

location.href = SUITE_BRIDGE_DEEPLINK;

// fallback in case deeplink does not work
window.setTimeout(() => {
if (!windowFocused.current) return;

window.open(SUITE_URL);
}, 500);
};

return handleOpenSuite;
};
20 changes: 2 additions & 18 deletions packages/suite/src/views/suite/bridge/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import styled from 'styled-components';
import { SUITE_BRIDGE_DEEPLINK, SUITE_URL } from '@trezor/urls';
import { Translation, Modal, Metadata } from 'src/components/suite';
import { Button } from '@trezor/components';
import { goto } from 'src/actions/suite/routerActions';
import { useDispatch, useSelector } from 'src/hooks/suite';
import { isWebUsb } from 'src/utils/suite/transport';
import TrezorConnect from '@trezor/connect';
import { useWindowFocus } from '@trezor/react-utils';
import { useOpenSuiteDesktop } from 'src/hooks/suite/useOpenSuiteDesktop';

const StyledButton = styled(Button)`
path {
Expand All @@ -26,21 +24,7 @@ export const BridgeUnavailable = () => {
const transport = useSelector(state => state.suite.transport);
const dispatch = useDispatch();

const windowFocused = useWindowFocus();
const handleOpenSuite = () => {
if (isWebUsb(transport)) {
TrezorConnect.disableWebUSB();
}

location.href = SUITE_BRIDGE_DEEPLINK;

// fallback in case deeplink does not work
window.setTimeout(() => {
if (!windowFocused.current) return;

window.open(SUITE_URL);
}, 500);
};
const handleOpenSuite = useOpenSuiteDesktop();

const goToWallet = () => dispatch(goto('wallet-index'));

Expand Down

0 comments on commit f6b0fe5

Please sign in to comment.