Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mroz22 committed Nov 3, 2024
1 parent 5a5f41e commit e42c5fe
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
6 changes: 6 additions & 0 deletions packages/connect-explorer/src/actions/trezorConnectActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ export const init =
const urlParams = new URLSearchParams(window.location.search);
const coreMode = (urlParams.get('core-mode') as ConnectOptions['coreMode']) || 'auto';

console.log('process.env.CONNECT_EXPLORER_FULL_URL', process.env.CONNECT_EXPLORER_FULL_URL);
const sessionsBackground = process.env.CONNECT_EXPLORER_FULL_URL
? `${process.env.CONNECT_EXPLORER_FULL_URL}/workers/sessions-background-sharedworker.js`
: window.origin + '/workers/sessions-background-sharedworker.js';

const connectOptions = {
coreMode,
transportReconnect: true,
Expand All @@ -158,6 +163,7 @@ export const init =
},
trustedHost: false,
connectSrc: window.__TREZOR_CONNECT_SRC,
sessionsBackground,
...options,
};

Expand Down
11 changes: 7 additions & 4 deletions packages/transport/src/transports/webusb.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import { UsbApi } from '../api/usb';

import { BrowserSessionsBackground } from '../sessions/background-browser';

console.log('process.env.ASSET_PREFIX', process.env.ASSET_PREFIX);

const defaultSessionsBackgroundUrl =
window.location.origin +
`${process.env.ASSET_PREFIX || ''}/workers/sessions-background-sharedworker.js`
// just in case so that whoever defines ASSET_PREFIX does not need to worry about trailing slashes
.replace(/\/+/g, '/');
'https://connect.trezor.io/9/workers/sessions-background-sharedworker.js';

type WebUsbTransportParams = AbstractTransportParams & { sessionsBackgroundUrl?: string };

Expand All @@ -28,6 +27,10 @@ export class WebUsbTransport extends AbstractApiTransport {
logger,
...rest,
});
if (sessionsBackgroundUrl && sessionsBackgroundUrl !== defaultSessionsBackgroundUrl) {
console.log('using custom sessionsBackgroundUrl', sessionsBackgroundUrl);
}
//////
this.sessionsBackgroundUrl = sessionsBackgroundUrl ?? defaultSessionsBackgroundUrl;
}

Expand Down
37 changes: 26 additions & 11 deletions suite-common/connect-init/src/connectInitThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import TrezorConnect, {
} from '@trezor/connect';
import { getSynchronize } from '@trezor/utils';
import { deviceConnectThunks } from '@suite-common/wallet-core';
import { resolveStaticPath } from '@suite-common/suite-utils';
import { isDevEnv, resolveStaticPath } from '@suite-common/suite-utils';
import { isDesktop, isNative } from '@trezor/env-utils';

import { cardanoConnectPatch } from './cardanoConnectPatch';
Expand Down Expand Up @@ -109,20 +109,35 @@ export const connectInitThunk = createThunk(

cardanoConnectPatch(getEnabledNetworks);

// note:
// this way, for local development you will get http://localhost:8000/static/connect/workers/sessions-background-sharedworker.js which is still the not-shared shared-worker
// meaning that testing it together with connect-explorer dev build (http://localhost:8088/workers/sessions-background-sharedworker.js) will not work locally.
// in production however, suite and connect are served from the same domain (trezor.io, sldev.cz) so it will work as expected.
// suite-web connect (explorer)
// ====================================================== ====================
// localhost:8000 localhost:8088
// https://dev.suite.sldev.cz/suite-web/develop/web/ https://dev.suite.sldev.cz/connect/develop/
// suite.trezor.io/web connect.trezor.io/9/
// suite.trezor.io/web/ connect.trezor.io/9.3.0/

// local - no sync, since we don't have dev server on the same port
// dev -
// prod -
let sessionsBackground: string | undefined;

//
if (typeof window !== 'undefined' && !isNative()) {
sessionsBackground =
window.location.origin +
resolveStaticPath(
'connect/workers/sessions-background-sharedworker.js',
`${process.env.ASSET_PREFIX || ''}`,
);
if (isDevEnv) {
if (window.location.origin.includes('localhost')) {
sessionsBackground = undefined;
} else {
// we are expecting accompanying connect build at specified location
sessionsBackground = `${window.location.origin}/${process.env.ASSET_PREFIX || ''}connect/workers/sessions-background-sharedworker.js`;
}
} else {
sessionsBackground =
'https://connect.trezor.io/9/workers/sessions-background-sharedworker.js';
}
}

console.log('sessionsBackground', sessionsBackground);

Check failure on line 139 in suite-common/connect-init/src/connectInitThunks.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement

// Duplicates `getBinFilesBaseUrlThunk`, because calling any other thunk would change store.getActions() history,
// and it would be impossible to test this thunk in isolation (many unit tests depend on it).
const binFilesBaseUrl = isDesktop()
Expand Down

0 comments on commit e42c5fe

Please sign in to comment.