From 47d50cf2ad03059b49bc8b92547a409123cd24e4 Mon Sep 17 00:00:00 2001 From: Martin Homola Date: Fri, 7 Mar 2025 09:30:58 +0100 Subject: [PATCH] fix(trading): delete suite-analytics --- suite-common/trading/package.json | 1 - .../buy/__tests__/confirmTradeThunk.test.ts | 40 ++++++++++++------- .../src/thunks/buy/confirmTradeThunk.ts | 17 ++++---- suite-common/trading/tsconfig.json | 3 -- yarn.lock | 1 - 5 files changed, 34 insertions(+), 28 deletions(-) diff --git a/suite-common/trading/package.json b/suite-common/trading/package.json index 2049f109a1f..85a0605afe1 100644 --- a/suite-common/trading/package.json +++ b/suite-common/trading/package.json @@ -19,7 +19,6 @@ "@trezor/connect": "workspace:*", "@trezor/env-utils": "workspace:*", "@trezor/react-utils": "workspace:*", - "@trezor/suite-analytics": "workspace:*", "@trezor/utils": "workspace:*", "react": "18.2.0", "uuid": "^11.0.5" diff --git a/suite-common/trading/src/thunks/buy/__tests__/confirmTradeThunk.test.ts b/suite-common/trading/src/thunks/buy/__tests__/confirmTradeThunk.test.ts index 505774df442..71282e169fd 100644 --- a/suite-common/trading/src/thunks/buy/__tests__/confirmTradeThunk.test.ts +++ b/suite-common/trading/src/thunks/buy/__tests__/confirmTradeThunk.test.ts @@ -3,7 +3,6 @@ import { BuyTradeResponse } from 'invity-api'; import { configureMockStore, extraDependenciesMock } from '@suite-common/test-utils'; import { Account } from '@suite-common/wallet-types'; -import { analytics } from '@trezor/suite-analytics'; import { MIN_MAX_QUOTES_OK } from '../../../__fixtures__/buyUtils'; import { invityAPI } from '../../../invityAPI'; @@ -46,7 +45,7 @@ describe('confirmTradeThunk', () => { }); const mockProcessResponseData = jest.fn(); - const mockAnalyticsReport = jest.spyOn(analytics, 'report'); + const mocktriggerAnalyticsTradeConfirmation = jest.fn(); const tradeForm = { form: { @@ -62,13 +61,13 @@ describe('confirmTradeThunk', () => { return { store, mockProcessResponseData, - mockAnalyticsReport, + mocktriggerAnalyticsTradeConfirmation, tradeForm, }; }; it('should not trigger any action if selectedQuote is not set', async () => { - const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks({ + const { store, mockProcessResponseData, mocktriggerAnalyticsTradeConfirmation } = getMocks({ selectedQuote: undefined, }); @@ -82,19 +81,21 @@ describe('confirmTradeThunk', () => { descriptor: 'desc', index: 1, } as Account, + triggerAnalyticsTradeConfirmation: mocktriggerAnalyticsTradeConfirmation, processResponseData: mockProcessResponseData, }), ); expect(store.getActions().length).toEqual(2); expect(mockProcessResponseData).toHaveBeenCalledTimes(0); - expect(mockAnalyticsReport).toHaveBeenCalledTimes(0); + expect(mocktriggerAnalyticsTradeConfirmation).toHaveBeenCalledTimes(0); expect(store.getState().wallet.trading.buy.isLoading).toBeFalsy(); }); describe('should show error toast', () => { it('if there is no response', async () => { - const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks(); + const { store, mockProcessResponseData, mocktriggerAnalyticsTradeConfirmation } = + getMocks(); invityAPI.doBuyTrade = () => Promise.resolve(undefined as unknown as BuyTradeResponse); @@ -108,6 +109,7 @@ describe('confirmTradeThunk', () => { descriptor: 'desc', index: 1, } as Account, + triggerAnalyticsTradeConfirmation: mocktriggerAnalyticsTradeConfirmation, processResponseData: mockProcessResponseData, }), ); @@ -116,7 +118,7 @@ describe('confirmTradeThunk', () => { .getActions() .find(action => action.type === '@common/in-app-notifications/addToast'); - expect(mockAnalyticsReport).toHaveBeenCalledTimes(1); + expect(mocktriggerAnalyticsTradeConfirmation).toHaveBeenCalledTimes(1); expect(toastAction?.payload.type).toEqual('error'); expect(toastAction?.payload.error).toEqual('No response from the server'); expect(mockProcessResponseData).toHaveBeenCalledTimes(0); @@ -124,7 +126,8 @@ describe('confirmTradeThunk', () => { }); it('if there is no trade in response', async () => { - const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks(); + const { store, mockProcessResponseData, mocktriggerAnalyticsTradeConfirmation } = + getMocks(); invityAPI.doBuyTrade = () => Promise.resolve({} as BuyTradeResponse); @@ -138,6 +141,7 @@ describe('confirmTradeThunk', () => { descriptor: 'desc', index: 1, } as Account, + triggerAnalyticsTradeConfirmation: mocktriggerAnalyticsTradeConfirmation, processResponseData: mockProcessResponseData, }), ); @@ -146,7 +150,7 @@ describe('confirmTradeThunk', () => { .getActions() .find(action => action.type === '@common/in-app-notifications/addToast'); - expect(mockAnalyticsReport).toHaveBeenCalledTimes(1); + expect(mocktriggerAnalyticsTradeConfirmation).toHaveBeenCalledTimes(1); expect(toastAction?.payload.type).toEqual('error'); expect(toastAction?.payload.error).toEqual('No response from the server'); expect(mockProcessResponseData).toHaveBeenCalledTimes(0); @@ -154,7 +158,8 @@ describe('confirmTradeThunk', () => { }); it('if there is no response trade payment id', async () => { - const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks(); + const { store, mockProcessResponseData, mocktriggerAnalyticsTradeConfirmation } = + getMocks(); invityAPI.doBuyTrade = () => Promise.resolve({ @@ -174,6 +179,7 @@ describe('confirmTradeThunk', () => { descriptor: 'desc', index: 1, } as Account, + triggerAnalyticsTradeConfirmation: mocktriggerAnalyticsTradeConfirmation, processResponseData: mockProcessResponseData, }), ); @@ -182,7 +188,7 @@ describe('confirmTradeThunk', () => { .getActions() .find(action => action.type === '@common/in-app-notifications/addToast'); - expect(mockAnalyticsReport).toHaveBeenCalledTimes(1); + expect(mocktriggerAnalyticsTradeConfirmation).toHaveBeenCalledTimes(1); expect(toastAction?.payload.type).toEqual('error'); expect(toastAction?.payload.error).toEqual('No response from the server'); expect(mockProcessResponseData).toHaveBeenCalledTimes(0); @@ -190,7 +196,8 @@ describe('confirmTradeThunk', () => { }); it('if there is trade error', async () => { - const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks(); + const { store, mockProcessResponseData, mocktriggerAnalyticsTradeConfirmation } = + getMocks(); const error = 'Error message from API'; invityAPI.doBuyTrade = () => @@ -211,6 +218,7 @@ describe('confirmTradeThunk', () => { descriptor: 'desc', index: 1, } as Account, + triggerAnalyticsTradeConfirmation: mocktriggerAnalyticsTradeConfirmation, processResponseData: mockProcessResponseData, }), ); @@ -218,7 +226,7 @@ describe('confirmTradeThunk', () => { const toastAction = store .getActions() .find(action => action.type === '@common/in-app-notifications/addToast'); - expect(mockAnalyticsReport).toHaveBeenCalledTimes(1); + expect(mocktriggerAnalyticsTradeConfirmation).toHaveBeenCalledTimes(1); expect(toastAction?.payload.type).toEqual('error'); expect(toastAction?.payload.error).toEqual(error); expect(mockProcessResponseData).toHaveBeenCalledTimes(0); @@ -227,7 +235,8 @@ describe('confirmTradeThunk', () => { }); it('should call processResponseData with response and save trade', async () => { - const { store, mockProcessResponseData, mockAnalyticsReport } = getMocks(); + const { store, mockProcessResponseData, mocktriggerAnalyticsTradeConfirmation } = + getMocks(); const dateString = new Date().toISOString(); jest.spyOn(Date.prototype, 'toISOString').mockImplementation(() => dateString); @@ -249,13 +258,14 @@ describe('confirmTradeThunk', () => { descriptor: 'desc', index: 1, } as Account, + triggerAnalyticsTradeConfirmation: mocktriggerAnalyticsTradeConfirmation, processResponseData: mockProcessResponseData, }), ); const { trades } = store.getState().wallet.trading; - expect(mockAnalyticsReport).toHaveBeenCalledTimes(1); + expect(mocktriggerAnalyticsTradeConfirmation).toHaveBeenCalledTimes(1); expect(mockProcessResponseData).toHaveBeenCalledTimes(1); expect(trades.length).toEqual(1); expect(trades[0]).toEqual({ diff --git a/suite-common/trading/src/thunks/buy/confirmTradeThunk.ts b/suite-common/trading/src/thunks/buy/confirmTradeThunk.ts index 300e31f80f6..478be31fa81 100644 --- a/suite-common/trading/src/thunks/buy/confirmTradeThunk.ts +++ b/suite-common/trading/src/thunks/buy/confirmTradeThunk.ts @@ -3,7 +3,6 @@ import { BuyTradeResponse } from 'invity-api'; import { createThunk } from '@suite-common/redux-utils'; import { notificationsActions } from '@suite-common/toast-notifications'; import { Account } from '@suite-common/wallet-types'; -import { EventType, analytics } from '@trezor/suite-analytics'; import { BUY_THUNK_COMMON_PREFIX } from './handleRequestThunk'; import { tradingActions } from '../../actions/tradingActions'; @@ -16,13 +15,20 @@ export type ConfirmTradeThunkProps = { address: string; account: Account; + triggerAnalyticsTradeConfirmation: () => void; processResponseData: (response: BuyTradeResponse) => void; }; export const confirmTradeThunk = createThunk( `${BUY_THUNK_COMMON_PREFIX}/confirmTrade`, async ( - { returnUrl, address, account, processResponseData }: ConfirmTradeThunkProps, + { + returnUrl, + address, + account, + triggerAnalyticsTradeConfirmation, + processResponseData, + }: ConfirmTradeThunkProps, { dispatch, getState }, ) => { const selectedQuote = selectTradingBuySelectedQuote(getState()); @@ -31,12 +37,7 @@ export const confirmTradeThunk = createThunk( dispatch(tradingBuyActions.setIsLoading(true)); - analytics.report({ - type: EventType.TradingConfirmTrade, - payload: { - type: 'buy', - }, - }); + triggerAnalyticsTradeConfirmation(); const trade = { ...selectedQuote, diff --git a/suite-common/trading/tsconfig.json b/suite-common/trading/tsconfig.json index f8796d03586..fdf0c8ab446 100644 --- a/suite-common/trading/tsconfig.json +++ b/suite-common/trading/tsconfig.json @@ -9,9 +9,6 @@ { "path": "../../packages/connect" }, { "path": "../../packages/env-utils" }, { "path": "../../packages/react-utils" }, - { - "path": "../../packages/suite-analytics" - }, { "path": "../../packages/utils" }, { "path": "../test-utils" } ] diff --git a/yarn.lock b/yarn.lock index dfa9061f191..b015fac24b2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9725,7 +9725,6 @@ __metadata: "@trezor/connect": "workspace:*" "@trezor/env-utils": "workspace:*" "@trezor/react-utils": "workspace:*" - "@trezor/suite-analytics": "workspace:*" "@trezor/utils": "workspace:*" "@types/invity-api": "npm:^1.1.5" react: "npm:18.2.0"