Skip to content

Commit 960f5d7

Browse files
committed
fix(trading): delete suite-analytics
1 parent be67d22 commit 960f5d7

File tree

5 files changed

+29
-28
lines changed

5 files changed

+29
-28
lines changed

suite-common/trading/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"@trezor/connect": "workspace:*",
2020
"@trezor/env-utils": "workspace:*",
2121
"@trezor/react-utils": "workspace:*",
22-
"@trezor/suite-analytics": "workspace:*",
2322
"@trezor/utils": "workspace:*",
2423
"react": "18.2.0",
2524
"uuid": "^11.0.5"

suite-common/trading/src/thunks/buy/__tests__/confirmTradeThunk.test.ts

+20-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { BuyTradeResponse } from 'invity-api';
33

44
import { configureMockStore, extraDependenciesMock } from '@suite-common/test-utils';
55
import { Account } from '@suite-common/wallet-types';
6-
import { analytics } from '@trezor/suite-analytics';
76

87
import { MIN_MAX_QUOTES_OK } from '../../../__fixtures__/buyUtils';
98
import { invityAPI } from '../../../invityAPI';
@@ -46,7 +45,7 @@ describe('confirmTradeThunk', () => {
4645
});
4746

4847
const mockProcessResponseData = jest.fn();
49-
const mockAnalyticsReport = jest.spyOn(analytics, 'report');
48+
const mockAnalyticsTriggerConfirm = jest.fn();
5049

5150
const tradeForm = {
5251
form: {
@@ -62,13 +61,13 @@ describe('confirmTradeThunk', () => {
6261
return {
6362
store,
6463
mockProcessResponseData,
65-
mockAnalyticsReport,
64+
mockAnalyticsTriggerConfirm,
6665
tradeForm,
6766
};
6867
};
6968

7069
it('should not trigger any action if selectedQuote is not set', async () => {
71-
const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks({
70+
const { store, mockProcessResponseData, mockAnalyticsTriggerConfirm } = getMocks({
7271
selectedQuote: undefined,
7372
});
7473

@@ -82,19 +81,20 @@ describe('confirmTradeThunk', () => {
8281
descriptor: 'desc',
8382
index: 1,
8483
} as Account,
84+
analyticsTriggerConfirm: mockAnalyticsTriggerConfirm,
8585
processResponseData: mockProcessResponseData,
8686
}),
8787
);
8888

8989
expect(store.getActions().length).toEqual(2);
9090
expect(mockProcessResponseData).toHaveBeenCalledTimes(0);
91-
expect(mockAnalyticsReport).toHaveBeenCalledTimes(0);
91+
expect(mockAnalyticsTriggerConfirm).toHaveBeenCalledTimes(0);
9292
expect(store.getState().wallet.trading.buy.isLoading).toBeFalsy();
9393
});
9494

9595
describe('should show error toast', () => {
9696
it('if there is no response', async () => {
97-
const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks();
97+
const { store, mockProcessResponseData, mockAnalyticsTriggerConfirm } = getMocks();
9898

9999
invityAPI.doBuyTrade = () => Promise.resolve(undefined as unknown as BuyTradeResponse);
100100

@@ -108,6 +108,7 @@ describe('confirmTradeThunk', () => {
108108
descriptor: 'desc',
109109
index: 1,
110110
} as Account,
111+
analyticsTriggerConfirm: mockAnalyticsTriggerConfirm,
111112
processResponseData: mockProcessResponseData,
112113
}),
113114
);
@@ -116,15 +117,15 @@ describe('confirmTradeThunk', () => {
116117
.getActions()
117118
.find(action => action.type === '@common/in-app-notifications/addToast');
118119

119-
expect(mockAnalyticsReport).toHaveBeenCalledTimes(1);
120+
expect(mockAnalyticsTriggerConfirm).toHaveBeenCalledTimes(1);
120121
expect(toastAction?.payload.type).toEqual('error');
121122
expect(toastAction?.payload.error).toEqual('No response from the server');
122123
expect(mockProcessResponseData).toHaveBeenCalledTimes(0);
123124
expect(store.getState().wallet.trading.buy.isLoading).toBeFalsy();
124125
});
125126

126127
it('if there is no trade in response', async () => {
127-
const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks();
128+
const { store, mockProcessResponseData, mockAnalyticsTriggerConfirm } = getMocks();
128129

129130
invityAPI.doBuyTrade = () => Promise.resolve({} as BuyTradeResponse);
130131

@@ -138,6 +139,7 @@ describe('confirmTradeThunk', () => {
138139
descriptor: 'desc',
139140
index: 1,
140141
} as Account,
142+
analyticsTriggerConfirm: mockAnalyticsTriggerConfirm,
141143
processResponseData: mockProcessResponseData,
142144
}),
143145
);
@@ -146,15 +148,15 @@ describe('confirmTradeThunk', () => {
146148
.getActions()
147149
.find(action => action.type === '@common/in-app-notifications/addToast');
148150

149-
expect(mockAnalyticsReport).toHaveBeenCalledTimes(1);
151+
expect(mockAnalyticsTriggerConfirm).toHaveBeenCalledTimes(1);
150152
expect(toastAction?.payload.type).toEqual('error');
151153
expect(toastAction?.payload.error).toEqual('No response from the server');
152154
expect(mockProcessResponseData).toHaveBeenCalledTimes(0);
153155
expect(store.getState().wallet.trading.buy.isLoading).toBeFalsy();
154156
});
155157

156158
it('if there is no response trade payment id', async () => {
157-
const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks();
159+
const { store, mockProcessResponseData, mockAnalyticsTriggerConfirm } = getMocks();
158160

159161
invityAPI.doBuyTrade = () =>
160162
Promise.resolve({
@@ -174,6 +176,7 @@ describe('confirmTradeThunk', () => {
174176
descriptor: 'desc',
175177
index: 1,
176178
} as Account,
179+
analyticsTriggerConfirm: mockAnalyticsTriggerConfirm,
177180
processResponseData: mockProcessResponseData,
178181
}),
179182
);
@@ -182,15 +185,15 @@ describe('confirmTradeThunk', () => {
182185
.getActions()
183186
.find(action => action.type === '@common/in-app-notifications/addToast');
184187

185-
expect(mockAnalyticsReport).toHaveBeenCalledTimes(1);
188+
expect(mockAnalyticsTriggerConfirm).toHaveBeenCalledTimes(1);
186189
expect(toastAction?.payload.type).toEqual('error');
187190
expect(toastAction?.payload.error).toEqual('No response from the server');
188191
expect(mockProcessResponseData).toHaveBeenCalledTimes(0);
189192
expect(store.getState().wallet.trading.buy.isLoading).toBeFalsy();
190193
});
191194

192195
it('if there is trade error', async () => {
193-
const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks();
196+
const { store, mockProcessResponseData, mockAnalyticsTriggerConfirm } = getMocks();
194197
const error = 'Error message from API';
195198

196199
invityAPI.doBuyTrade = () =>
@@ -211,14 +214,15 @@ describe('confirmTradeThunk', () => {
211214
descriptor: 'desc',
212215
index: 1,
213216
} as Account,
217+
analyticsTriggerConfirm: mockAnalyticsTriggerConfirm,
214218
processResponseData: mockProcessResponseData,
215219
}),
216220
);
217221

218222
const toastAction = store
219223
.getActions()
220224
.find(action => action.type === '@common/in-app-notifications/addToast');
221-
expect(mockAnalyticsReport).toHaveBeenCalledTimes(1);
225+
expect(mockAnalyticsTriggerConfirm).toHaveBeenCalledTimes(1);
222226
expect(toastAction?.payload.type).toEqual('error');
223227
expect(toastAction?.payload.error).toEqual(error);
224228
expect(mockProcessResponseData).toHaveBeenCalledTimes(0);
@@ -227,7 +231,7 @@ describe('confirmTradeThunk', () => {
227231
});
228232

229233
it('should call processResponseData with response and save trade', async () => {
230-
const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks();
234+
const { store, mockProcessResponseData, mockAnalyticsTriggerConfirm } = getMocks();
231235

232236
const dateString = new Date().toISOString();
233237
jest.spyOn(Date.prototype, 'toISOString').mockImplementation(() => dateString);
@@ -249,13 +253,14 @@ describe('confirmTradeThunk', () => {
249253
descriptor: 'desc',
250254
index: 1,
251255
} as Account,
256+
analyticsTriggerConfirm: mockAnalyticsTriggerConfirm,
252257
processResponseData: mockProcessResponseData,
253258
}),
254259
);
255260

256261
const { trades } = store.getState().wallet.trading;
257262

258-
expect(mockAnalyticsReport).toHaveBeenCalledTimes(1);
263+
expect(mockAnalyticsTriggerConfirm).toHaveBeenCalledTimes(1);
259264
expect(mockProcessResponseData).toHaveBeenCalledTimes(1);
260265
expect(trades.length).toEqual(1);
261266
expect(trades[0]).toEqual({

suite-common/trading/src/thunks/buy/confirmTradeThunk.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { BuyTradeResponse } from 'invity-api';
33
import { createThunk } from '@suite-common/redux-utils';
44
import { notificationsActions } from '@suite-common/toast-notifications';
55
import { Account } from '@suite-common/wallet-types';
6-
import { EventType, analytics } from '@trezor/suite-analytics';
76

87
import { BUY_THUNK_COMMON_PREFIX } from './handleRequestThunk';
98
import { tradingActions } from '../../actions/tradingActions';
@@ -16,13 +15,20 @@ export type ConfirmTradeThunkProps = {
1615
address: string;
1716
account: Account;
1817

18+
analyticsTriggerConfirm: () => void;
1919
processResponseData: (response: BuyTradeResponse) => void;
2020
};
2121

2222
export const confirmTradeThunk = createThunk(
2323
`${BUY_THUNK_COMMON_PREFIX}/confirmTrade`,
2424
async (
25-
{ returnUrl, address, account, processResponseData }: ConfirmTradeThunkProps,
25+
{
26+
returnUrl,
27+
address,
28+
account,
29+
analyticsTriggerConfirm,
30+
processResponseData,
31+
}: ConfirmTradeThunkProps,
2632
{ dispatch, getState },
2733
) => {
2834
const selectedQuote = selectTradingBuySelectedQuote(getState());
@@ -31,12 +37,7 @@ export const confirmTradeThunk = createThunk(
3137

3238
dispatch(tradingBuyActions.setIsLoading(true));
3339

34-
analytics.report({
35-
type: EventType.TradingConfirmTrade,
36-
payload: {
37-
type: 'buy',
38-
},
39-
});
40+
analyticsTriggerConfirm();
4041

4142
const trade = {
4243
...selectedQuote,

suite-common/trading/tsconfig.json

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
{ "path": "../../packages/connect" },
1010
{ "path": "../../packages/env-utils" },
1111
{ "path": "../../packages/react-utils" },
12-
{
13-
"path": "../../packages/suite-analytics"
14-
},
1512
{ "path": "../../packages/utils" },
1613
{ "path": "../test-utils" }
1714
]

yarn.lock

-1
Original file line numberDiff line numberDiff line change
@@ -9725,7 +9725,6 @@ __metadata:
97259725
"@trezor/connect": "workspace:*"
97269726
"@trezor/env-utils": "workspace:*"
97279727
"@trezor/react-utils": "workspace:*"
9728-
"@trezor/suite-analytics": "workspace:*"
97299728
"@trezor/utils": "workspace:*"
97309729
"@types/invity-api": "npm:^1.1.5"
97319730
react: "npm:18.2.0"

0 commit comments

Comments
 (0)