Skip to content

Commit b72a510

Browse files
adderpositivevytick
authored andcommitted
fix(trading): delete suite-analytics
1 parent ecc04a4 commit b72a510

File tree

5 files changed

+34
-28
lines changed

5 files changed

+34
-28
lines changed

suite-common/trading/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"@trezor/connect": "workspace:*",
2121
"@trezor/env-utils": "workspace:*",
2222
"@trezor/react-utils": "workspace:*",
23-
"@trezor/suite-analytics": "workspace:*",
2423
"@trezor/utils": "workspace:*",
2524
"react": "18.2.0",
2625
"react-redux": "8.0.7",

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

+25-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 mocktriggerAnalyticsTradeConfirmation = jest.fn();
5049

5150
const tradeForm = {
5251
form: {
@@ -62,13 +61,13 @@ describe('confirmTradeThunk', () => {
6261
return {
6362
store,
6463
mockProcessResponseData,
65-
mockAnalyticsReport,
64+
mocktriggerAnalyticsTradeConfirmation,
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, mocktriggerAnalyticsTradeConfirmation } = getMocks({
7271
selectedQuote: undefined,
7372
});
7473

@@ -82,19 +81,21 @@ describe('confirmTradeThunk', () => {
8281
descriptor: 'desc',
8382
index: 1,
8483
} as Account,
84+
triggerAnalyticsTradeConfirmation: mocktriggerAnalyticsTradeConfirmation,
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(mocktriggerAnalyticsTradeConfirmation).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, mocktriggerAnalyticsTradeConfirmation } =
98+
getMocks();
9899

99100
invityAPI.doBuyTrade = () => Promise.resolve(undefined as unknown as BuyTradeResponse);
100101

@@ -108,6 +109,7 @@ describe('confirmTradeThunk', () => {
108109
descriptor: 'desc',
109110
index: 1,
110111
} as Account,
112+
triggerAnalyticsTradeConfirmation: mocktriggerAnalyticsTradeConfirmation,
111113
processResponseData: mockProcessResponseData,
112114
}),
113115
);
@@ -116,15 +118,16 @@ describe('confirmTradeThunk', () => {
116118
.getActions()
117119
.find(action => action.type === '@common/in-app-notifications/addToast');
118120

119-
expect(mockAnalyticsReport).toHaveBeenCalledTimes(1);
121+
expect(mocktriggerAnalyticsTradeConfirmation).toHaveBeenCalledTimes(1);
120122
expect(toastAction?.payload.type).toEqual('error');
121123
expect(toastAction?.payload.error).toEqual('No response from the server');
122124
expect(mockProcessResponseData).toHaveBeenCalledTimes(0);
123125
expect(store.getState().wallet.trading.buy.isLoading).toBeFalsy();
124126
});
125127

126128
it('if there is no trade in response', async () => {
127-
const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks();
129+
const { store, mockProcessResponseData, mocktriggerAnalyticsTradeConfirmation } =
130+
getMocks();
128131

129132
invityAPI.doBuyTrade = () => Promise.resolve({} as BuyTradeResponse);
130133

@@ -138,6 +141,7 @@ describe('confirmTradeThunk', () => {
138141
descriptor: 'desc',
139142
index: 1,
140143
} as Account,
144+
triggerAnalyticsTradeConfirmation: mocktriggerAnalyticsTradeConfirmation,
141145
processResponseData: mockProcessResponseData,
142146
}),
143147
);
@@ -146,15 +150,16 @@ describe('confirmTradeThunk', () => {
146150
.getActions()
147151
.find(action => action.type === '@common/in-app-notifications/addToast');
148152

149-
expect(mockAnalyticsReport).toHaveBeenCalledTimes(1);
153+
expect(mocktriggerAnalyticsTradeConfirmation).toHaveBeenCalledTimes(1);
150154
expect(toastAction?.payload.type).toEqual('error');
151155
expect(toastAction?.payload.error).toEqual('No response from the server');
152156
expect(mockProcessResponseData).toHaveBeenCalledTimes(0);
153157
expect(store.getState().wallet.trading.buy.isLoading).toBeFalsy();
154158
});
155159

156160
it('if there is no response trade payment id', async () => {
157-
const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks();
161+
const { store, mockProcessResponseData, mocktriggerAnalyticsTradeConfirmation } =
162+
getMocks();
158163

159164
invityAPI.doBuyTrade = () =>
160165
Promise.resolve({
@@ -174,6 +179,7 @@ describe('confirmTradeThunk', () => {
174179
descriptor: 'desc',
175180
index: 1,
176181
} as Account,
182+
triggerAnalyticsTradeConfirmation: mocktriggerAnalyticsTradeConfirmation,
177183
processResponseData: mockProcessResponseData,
178184
}),
179185
);
@@ -182,15 +188,16 @@ describe('confirmTradeThunk', () => {
182188
.getActions()
183189
.find(action => action.type === '@common/in-app-notifications/addToast');
184190

185-
expect(mockAnalyticsReport).toHaveBeenCalledTimes(1);
191+
expect(mocktriggerAnalyticsTradeConfirmation).toHaveBeenCalledTimes(1);
186192
expect(toastAction?.payload.type).toEqual('error');
187193
expect(toastAction?.payload.error).toEqual('No response from the server');
188194
expect(mockProcessResponseData).toHaveBeenCalledTimes(0);
189195
expect(store.getState().wallet.trading.buy.isLoading).toBeFalsy();
190196
});
191197

192198
it('if there is trade error', async () => {
193-
const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks();
199+
const { store, mockProcessResponseData, mocktriggerAnalyticsTradeConfirmation } =
200+
getMocks();
194201
const error = 'Error message from API';
195202

196203
invityAPI.doBuyTrade = () =>
@@ -211,14 +218,15 @@ describe('confirmTradeThunk', () => {
211218
descriptor: 'desc',
212219
index: 1,
213220
} as Account,
221+
triggerAnalyticsTradeConfirmation: mocktriggerAnalyticsTradeConfirmation,
214222
processResponseData: mockProcessResponseData,
215223
}),
216224
);
217225

218226
const toastAction = store
219227
.getActions()
220228
.find(action => action.type === '@common/in-app-notifications/addToast');
221-
expect(mockAnalyticsReport).toHaveBeenCalledTimes(1);
229+
expect(mocktriggerAnalyticsTradeConfirmation).toHaveBeenCalledTimes(1);
222230
expect(toastAction?.payload.type).toEqual('error');
223231
expect(toastAction?.payload.error).toEqual(error);
224232
expect(mockProcessResponseData).toHaveBeenCalledTimes(0);
@@ -227,7 +235,8 @@ describe('confirmTradeThunk', () => {
227235
});
228236

229237
it('should call processResponseData with response and save trade', async () => {
230-
const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks();
238+
const { store, mockProcessResponseData, mocktriggerAnalyticsTradeConfirmation } =
239+
getMocks();
231240

232241
const dateString = new Date().toISOString();
233242
jest.spyOn(Date.prototype, 'toISOString').mockImplementation(() => dateString);
@@ -249,13 +258,14 @@ describe('confirmTradeThunk', () => {
249258
descriptor: 'desc',
250259
index: 1,
251260
} as Account,
261+
triggerAnalyticsTradeConfirmation: mocktriggerAnalyticsTradeConfirmation,
252262
processResponseData: mockProcessResponseData,
253263
}),
254264
);
255265

256266
const { trades } = store.getState().wallet.trading;
257267

258-
expect(mockAnalyticsReport).toHaveBeenCalledTimes(1);
268+
expect(mocktriggerAnalyticsTradeConfirmation).toHaveBeenCalledTimes(1);
259269
expect(mockProcessResponseData).toHaveBeenCalledTimes(1);
260270
expect(trades.length).toEqual(1);
261271
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+
triggerAnalyticsTradeConfirmation: () => 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+
triggerAnalyticsTradeConfirmation,
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+
triggerAnalyticsTradeConfirmation();
4041

4142
const trade = {
4243
...selectedQuote,

suite-common/trading/tsconfig.json

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
{ "path": "../../packages/connect" },
1313
{ "path": "../../packages/env-utils" },
1414
{ "path": "../../packages/react-utils" },
15-
{
16-
"path": "../../packages/suite-analytics"
17-
},
1815
{ "path": "../../packages/utils" },
1916
{ "path": "../test-utils" }
2017
]

yarn.lock

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

0 commit comments

Comments
 (0)