Skip to content

Commit

Permalink
fix(connect-popup): systemInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
mroz22 committed Apr 20, 2023
1 parent 9b54197 commit 9ddc3b3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/connect-popup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@trezor/connect-analytics": "workspace:*",
"@trezor/connect-ui": "workspace:*",
"@trezor/crypto-utils": "workspace:*",
"@trezor/env-utils": "workspace:*",
"@trezor/urls": "workspace:*",
"eth-phishing-detect": "^1.2.0"
},
Expand Down
34 changes: 34 additions & 0 deletions packages/connect-popup/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
PopupEvent,
PopupInit,
PopupHandshake,
SystemInfo,
} from '@trezor/connect';
import { config } from '@trezor/connect/lib/data/config';

import { reactEventBus } from '@trezor/connect-ui/src/utils/eventBus';
import { analytics, EventType } from '@trezor/connect-analytics';
Expand All @@ -24,6 +26,35 @@ import {
postMessage,
} from './view/common';
import { isPhishingDomain } from './utils/isPhishingDomain';
import { getBrowserVersion, getBrowserName, getDeviceType, getOsFamily } from '@trezor/env-utils';

// FIXME!!!
// this is copy paste hotfix from connect-iframe package
// why: systemInfo is sent in POPUP.INIT message from connect-web/src/popup. And this was added in 9.0.8.
// In case implementator has earlier version, systemInfo does not come. One of results is that popup displays
// outdated browser.
const getSystemInfo = (supportedBrowsers: { [key: string]: { version: number } }): SystemInfo => {
const browserName = getBrowserName();
const browserVersion = getBrowserVersion();
const supportedBrowser = browserName ? supportedBrowsers[browserName.toLowerCase()] : undefined;
const outdatedBrowser = supportedBrowser
? supportedBrowser.version > parseInt(browserVersion, 10)
: false;
const mobile = getDeviceType() === 'mobile';
const supportedMobile = mobile ? typeof navigator.usb !== 'undefined' : true;
const supported = !!(supportedBrowser && !outdatedBrowser && supportedMobile);

return {
os: {
family: getOsFamily(),
mobile,
},
browser: {
supported,
outdated: outdatedBrowser,
},
};
};

let handshakeTimeout: ReturnType<typeof setTimeout>;

Expand Down Expand Up @@ -181,6 +212,9 @@ const handleMessage = (event: MessageEvent<PopupEvent | UiEvent>) => {
// handle POPUP.INIT message from window.opener
const init = async (payload: PopupInit['payload']) => {
if (!payload) return;

payload.systemInfo = getSystemInfo(config.supportedBrowsers);

try {
initMessageChannel(payload, handleMessage);
// reset loading hash
Expand Down
1 change: 1 addition & 0 deletions packages/connect-popup/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{ "path": "../connect-analytics" },
{ "path": "../connect-ui" },
{ "path": "../crypto-utils" },
{ "path": "../env-utils" },
{ "path": "../urls" },
{ "path": "../node-utils" },
{ "path": "../trezor-user-env-link" }
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7738,6 +7738,7 @@ __metadata:
"@trezor/connect-analytics": "workspace:*"
"@trezor/connect-ui": "workspace:*"
"@trezor/crypto-utils": "workspace:*"
"@trezor/env-utils": "workspace:*"
"@trezor/node-utils": "workspace:*"
"@trezor/trezor-user-env-link": "workspace:*"
"@trezor/urls": "workspace:*"
Expand Down

0 comments on commit 9ddc3b3

Please sign in to comment.