Skip to content

Commit cd5335e

Browse files
rhyslbwbslabiak
andauthored
LW-11276 Update configuration to use Lace PostHog proxy (#1376)
* refactor: generalise PostHog host variables This is too specific. What if we want to use a proxy? * feature: replace Public PostHog URL with Lace proxy * test(extension): add delay for onboarding tests (#1377) --------- Co-authored-by: bslabiak <112852128+bslabiak@users.noreply.github.com>
1 parent 10a7560 commit cd5335e

File tree

12 files changed

+33
-27
lines changed

12 files changed

+33
-27
lines changed

apps/browser-extension-wallet/.env.defaults

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ BANXA_LACE_URL=https://lacewallet.banxa-sandbox.com/
5454
BANXA_HOMEPAGE_URL=https://banxa.com/
5555

5656
# events tracking
57-
PUBLIC_POSTHOG_HOST=https://eu.posthog.com
57+
POSTHOG_HOST=https://e.lw.iog.io
5858
POSTHOG_EXCLUDED_EVENTS=
5959
# set this variable to true only in release packages. By having this set to false, we ensure that we will not be using Post Hog production projects tokens in development stage
6060
PRODUCTION_MODE_TRACKING=false

apps/browser-extension-wallet/.env.developerpreview

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ BANXA_LACE_URL=https://lacewallet.banxa-sandbox.com/
5252
BANXA_HOMEPAGE_URL=https://banxa.com/
5353

5454
# events tracking
55-
PUBLIC_POSTHOG_HOST=https://eu.posthog.com
55+
POSTHOG_HOST=https://e.lw.iog.io
5656
POSTHOG_EXCLUDED_EVENTS=
5757
# set this variable to true only in release packages. By having this set to false, we ensure that we will not be using Post Hog production projects tokens in development stage
5858
PRODUCTION_MODE_TRACKING=false
@@ -87,5 +87,5 @@ LACE_EXTENSION_KEY=djcdfchkaijggdjokfomholkalbffgil
8787
# Extension uninstall redirect
8888
LACE_EXTENSION_UNINSTALL_REDIRECT_URL=
8989

90-
# Midnight
90+
# Midnight
9191
MIDNIGHT_EVENT_BANNER_REMINDER_TIME=129600000

apps/browser-extension-wallet/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ YOUTUBE_RECOVERY_PHRASE_VIDEO_URL=https://www.youtube-nocookie.com/embed/hOFVXo9
4949
BANXA_LACE_URL=https://lacewallet.banxa-sandbox.com/
5050
BANXA_HOMEPAGE_URL=https://banxa.com/
5151
# events tracking
52-
PUBLIC_POSTHOG_HOST=https://eu.posthog.com
52+
POSTHOG_HOST=https://e.lw.iog.io
5353
# set this variable to true only in release packages. By having this set to false, we ensure that we will not be using Post Hog production projects tokens in development stage
5454
PRODUCTION_MODE_TRACKING=false
5555
SESSION_LENGTH_IN_SECONDS=60

apps/browser-extension-wallet/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"permissions": ["webRequest", "storage", "tabs", "unlimitedStorage"],
2020
"host_permissions": ["<all_urls>"],
2121
"content_security_policy": {
22-
"extension_pages": "default-src 'self' $LOCALHOST_DEFAULT_SRC; frame-src https://connect.trezor.io/ https://www.youtube-nocookie.com; script-src 'self' 'wasm-unsafe-eval' $LOCALHOST_SCRIPT_SRC; font-src 'self' https://use.typekit.net; object-src 'self'; connect-src $CARDANO_SERVICES_URLS $ADA_HANDLE_URLS https://coingecko.live-mainnet.eks.lw.iog.io https://muesliswap.live-mainnet.eks.lw.iog.io $LOCALHOST_CONNECT_SRC https://eu.posthog.com/ https://use.typekit.net data:; style-src * 'unsafe-inline'; img-src * data:;"
22+
"extension_pages": "default-src 'self' $LOCALHOST_DEFAULT_SRC; frame-src https://connect.trezor.io/ https://www.youtube-nocookie.com; script-src 'self' 'wasm-unsafe-eval' $LOCALHOST_SCRIPT_SRC; font-src 'self' https://use.typekit.net; object-src 'self'; connect-src $CARDANO_SERVICES_URLS $ADA_HANDLE_URLS https://coingecko.live-mainnet.eks.lw.iog.io https://muesliswap.live-mainnet.eks.lw.iog.io $LOCALHOST_CONNECT_SRC $POSTHOG_HOST https://use.typekit.net data:; style-src * 'unsafe-inline'; img-src * data:;"
2323
},
2424
"content_scripts": [
2525
{

apps/browser-extension-wallet/src/providers/PostHogClientProvider/client/PostHogClient.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const mockUserId$ = new ReplaySubject<UserId>();
1616
jest.mock('posthog-js');
1717

1818
describe('PostHogClient', () => {
19-
const publicPosthogHost = 'test';
19+
const posthogHost = 'test';
2020
const chain = Wallet.Cardano.ChainIds.Preprod;
2121
const userId = 'userId';
2222
const mockUserIdService = {
@@ -31,20 +31,20 @@ describe('PostHogClient', () => {
3131

3232
it('should initialize posthog on construction', async () => {
3333
// eslint-disable-next-line no-new
34-
const client = new PostHogClient(chain, mockUserIdService, mockBackgroundStorageUtil, undefined, publicPosthogHost);
34+
const client = new PostHogClient(chain, mockUserIdService, mockBackgroundStorageUtil, undefined, posthogHost);
3535

3636
await waitFor(() => expect(client).toBeDefined());
3737
expect(posthog.init).toHaveBeenCalledWith(
3838
expect.stringContaining(DEV_NETWORK_ID_TO_POSTHOG_TOKEN_MAP[chain.networkMagic]),
3939
expect.objectContaining({
4040
// eslint-disable-next-line camelcase
41-
api_host: publicPosthogHost
41+
api_host: posthogHost
4242
})
4343
);
4444
});
4545

4646
it('should send page navigation events with distinct id and view = extended as default', async () => {
47-
const client = new PostHogClient(chain, mockUserIdService, mockBackgroundStorageUtil, undefined, publicPosthogHost);
47+
const client = new PostHogClient(chain, mockUserIdService, mockBackgroundStorageUtil, undefined, posthogHost);
4848
await client.sendPageNavigationEvent();
4949
expect(posthog.capture).toHaveBeenCalledWith(
5050
'$pageview',
@@ -57,7 +57,7 @@ describe('PostHogClient', () => {
5757
});
5858

5959
it('should send session started event', async () => {
60-
const client = new PostHogClient(chain, mockUserIdService, mockBackgroundStorageUtil, undefined, publicPosthogHost);
60+
const client = new PostHogClient(chain, mockUserIdService, mockBackgroundStorageUtil, undefined, posthogHost);
6161
await client.sendSessionStartEvent();
6262
expect(posthog.capture).toHaveBeenCalledWith(
6363
PostHogAction.WalletSessionStartPageview,
@@ -70,7 +70,7 @@ describe('PostHogClient', () => {
7070
});
7171

7272
it('should send events with distinct id', async () => {
73-
const client = new PostHogClient(chain, mockUserIdService, mockBackgroundStorageUtil, undefined, publicPosthogHost);
73+
const client = new PostHogClient(chain, mockUserIdService, mockBackgroundStorageUtil, undefined, posthogHost);
7474
const event = PostHogAction.OnboardingCreateClick;
7575
const extraProps = { some: 'prop', another: 'test' };
7676

@@ -88,7 +88,7 @@ describe('PostHogClient', () => {
8888

8989
it('should be possible to change the chain', () => {
9090
const previewChain = Wallet.Cardano.ChainIds.Preview;
91-
const client = new PostHogClient(chain, mockUserIdService, mockBackgroundStorageUtil, undefined, publicPosthogHost);
91+
const client = new PostHogClient(chain, mockUserIdService, mockBackgroundStorageUtil, undefined, posthogHost);
9292
expect(posthog.set_config).not.toHaveBeenCalled();
9393
client.setChain(previewChain);
9494
expect(posthog.set_config).toHaveBeenCalledWith(
@@ -104,7 +104,7 @@ describe('PostHogClient', () => {
104104
mockUserIdService,
105105
mockBackgroundStorageUtil,
106106
ExtensionViews.Popup,
107-
publicPosthogHost
107+
posthogHost
108108
);
109109
const event = PostHogAction.OnboardingCreateClick;
110110

@@ -124,7 +124,7 @@ describe('PostHogClient', () => {
124124
mockUserIdService,
125125
mockBackgroundStorageUtil,
126126
ExtensionViews.Extended,
127-
publicPosthogHost
127+
posthogHost
128128
);
129129
const event = PostHogAction.OnboardingCreateClick;
130130

@@ -145,7 +145,7 @@ describe('PostHogClient', () => {
145145
mockUserIdService,
146146
mockBackgroundStorageUtil,
147147
ExtensionViews.Extended,
148-
publicPosthogHost
148+
posthogHost
149149
);
150150
const event = PostHogAction.OnboardingCreateClick;
151151

@@ -168,7 +168,7 @@ describe('PostHogClient', () => {
168168
{ ...mockUserIdService, getAliasProperties: mockGetAliasProperties },
169169
mockBackgroundStorageUtil,
170170
ExtensionViews.Extended,
171-
publicPosthogHost
171+
posthogHost
172172
);
173173
await client.sendAliasEvent();
174174
expect(posthog.alias).toHaveBeenCalledWith(mockAliasProperties.alias, mockAliasProperties.id);
@@ -181,7 +181,7 @@ describe('PostHogClient', () => {
181181
{ ...mockUserIdService, getAliasProperties: mockGetAliasProperties },
182182
mockBackgroundStorageUtil,
183183
ExtensionViews.Extended,
184-
publicPosthogHost
184+
posthogHost
185185
);
186186
await client.sendAliasEvent();
187187
expect(posthog.alias).not.toHaveBeenCalled();
@@ -194,7 +194,7 @@ describe('PostHogClient', () => {
194194
mockUserIdService,
195195
mockBackgroundStorageUtil,
196196
ExtensionViews.Extended,
197-
publicPosthogHost
197+
posthogHost
198198
);
199199
mockUserIdService.userId$.next({
200200
type: UserTrackingType.Enhanced,
@@ -224,7 +224,7 @@ describe('PostHogClient', () => {
224224
{ ...mockUserIdService, userId$: tracking },
225225
mockBackgroundStorageUtil,
226226
ExtensionViews.Extended,
227-
publicPosthogHost
227+
posthogHost
228228
);
229229

230230
await client.sendEvent(event);

apps/browser-extension-wallet/src/providers/PostHogClientProvider/client/PostHogClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
PRODUCTION_NETWORK_ID_TO_POSTHOG_PROJECT_ID_MAP,
1515
PRODUCTION_NETWORK_ID_TO_POSTHOG_TOKEN_MAP,
1616
PRODUCTION_TRACKING_MODE_ENABLED,
17-
PUBLIC_POSTHOG_HOST,
17+
POSTHOG_HOST,
1818
POSTHOG_ENABLED
1919
} from './config';
2020
import { BackgroundService, UserIdService } from '@lib/scripts/types';
@@ -44,9 +44,9 @@ export class PostHogClient<Action extends string = string> {
4444
private userIdService: UserIdService,
4545
private backgroundServiceUtils: Pick<BackgroundService, 'getBackgroundStorage' | 'setBackgroundStorage'>,
4646
private view: ExtensionViews = ExtensionViews.Extended,
47-
private publicPostHogHost: string = PUBLIC_POSTHOG_HOST
47+
private postHogHost: string = POSTHOG_HOST
4848
) {
49-
if (!this.publicPostHogHost) throw new Error('PUBLIC_POSTHOG_HOST url has not been provided');
49+
if (!this.postHogHost) throw new Error('POSTHOG_HOST url has not been provided');
5050
const token = this.getApiToken(this.chain);
5151
if (!token) throw new Error(`posthog token has not been provided for chain: ${this.chain.networkId}`);
5252
this.hasPostHogInitialized$ = new BehaviorSubject(false);
@@ -56,7 +56,7 @@ export class PostHogClient<Action extends string = string> {
5656
.then((id) => {
5757
posthog.init(token, {
5858
request_batching: false,
59-
api_host: this.publicPostHogHost,
59+
api_host: this.postHogHost,
6060
autocapture: false,
6161
disable_session_recording: true,
6262
capture_pageview: false,

apps/browser-extension-wallet/src/providers/PostHogClientProvider/client/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Wallet } from '@lace/cardano';
22

33
export const POSTHOG_ENABLED = process.env.USE_POSTHOG_ANALYTICS === 'true';
44
export const POSTHOG_OPTED_OUT_EVENTS_DISABLED = process.env.USE_POSTHOG_ANALYTICS_FOR_OPTED_OUT === 'false';
5-
export const PUBLIC_POSTHOG_HOST = process.env.PUBLIC_POSTHOG_HOST;
5+
export const POSTHOG_HOST = process.env.POSTHOG_HOST;
66
export const PRODUCTION_TRACKING_MODE_ENABLED = process.env.PRODUCTION_MODE_TRACKING === 'true';
77
export const POSTHOG_EXCLUDED_EVENTS = process.env.POSTHOG_EXCLUDED_EVENTS ?? '';
88

apps/browser-extension-wallet/test/__mocks__/set-env-vars.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ process.env.CEXPLORER_URL_SANCHONET = 'https://sanchonet.cexplorer.io';
1010
process.env.USE_HIDE_MY_BALANCE = 'true';
1111
process.env.USE_POSTHOG_ANALYTICS = 'true';
1212
process.env.USE_POSTHOG_ANALYTICS_FOR_OPTED_OUT = 'false';
13-
process.env.PUBLIC_POSTHOG_HOST = 'https://eu.posthog.com';
13+
process.env.POSTHOG_HOST = 'https://e.lw.iog.io';
1414
process.env.POSTHOG_DEV_TOKEN_PREPROD = 'test-token';

apps/browser-extension-wallet/webpack-utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ const transformManifest = (content, mode) => {
2727
mode === 'development'
2828
? 'http://localhost:* http://127.0.0.1:* ws://localhost:3000 ws://0.0.0.0:3000/ws wss://localhost:3000 ws://localhost:3001 ws://0.0.0.0:3001/ws wss://localhost:3001'
2929
: 'http://localhost:* http://127.0.0.1:*'
30-
);
30+
)
31+
.replace('$POSTHOG_HOST', process.env.POSTHOG_HOST);
3132

3233
if (process.env.LACE_EXTENSION_KEY) {
3334
manifest.key = manifest.key.replace('$LACE_EXTENSION_KEY', process.env.LACE_EXTENSION_KEY);

packages/e2e-tests/src/elements/onboarding/mainPage.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import CommonOnboardingElements from './commonOnboardingElements';
55
import recoveryPhrasePage from './recoveryPhrasePage';
66
import walletSetupPage from './walletSetupPage';
77
import topNavigationAssert from '../../assert/topNavigationAssert';
8+
import { browser } from '@wdio/globals';
89

910
export class OnboardingMainPage extends CommonOnboardingElements {
1011
private LOGO_IMAGE = '[data-testid="wallet-setup-logo"]';
@@ -112,6 +113,8 @@ export class OnboardingMainPage extends CommonOnboardingElements {
112113
}
113114

114115
async clickOnOnboardingTypeButton(button: 'Create' | 'Connect' | 'Restore'): Promise<void> {
116+
// issue LW-11288 - please remove when it will be fixed / check on CI is needed
117+
await browser.pause(1000);
115118
switch (button) {
116119
case 'Create':
117120
await this.createWalletButton.waitForClickable();

0 commit comments

Comments
 (0)