1
+ /* eslint-disable camelcase */
1
2
/* eslint-disable react/no-multi-comp */
2
3
/* eslint-disable promise/catch-or-return */
3
4
/* eslint-disable no-magic-numbers */
@@ -23,6 +24,7 @@ import { DrawerContent } from '@src/views/browser-view/components/Drawer';
23
24
import { useTranslation } from 'react-i18next' ;
24
25
import { WarningModal } from '@views/browser/components' ;
25
26
import styles from './SendFlow.module.scss' ;
27
+ import { TxCreationType , TX_CREATION_TYPE_KEY } from '@providers/AnalyticsProvider/analyticsTracker' ;
26
28
27
29
const SATS_IN_BTC = 100_000_000 ;
28
30
@@ -157,19 +159,35 @@ export const SendFlow: React.FC = () => {
157
159
return false ;
158
160
} , [ pendingTxs , utxos ] ) ;
159
161
162
+ useEffect ( ( ) => {
163
+ setDrawerConfig ( {
164
+ ...config ,
165
+ onClose : ( ) => {
166
+ // eslint-disable-next-line sonarjs/no-small-switch
167
+ switch ( step ) {
168
+ case 'DONE' :
169
+ analytics . sendEventToPostHog ( PostHogAction . SendAllDoneCloseClick ) ;
170
+ break ;
171
+ case 'FAILED' :
172
+ case 'UNAUTHORIZED' :
173
+ analytics . sendEventToPostHog ( PostHogAction . SendSomethingWentWrongXClick ) ;
174
+ break ;
175
+ default :
176
+ break ;
177
+ }
178
+ config ?. onClose ? config ?. onClose ( ) : setDrawerConfig ( ) ;
179
+ }
180
+ } ) ;
181
+ // eslint-disable-next-line react-hooks/exhaustive-deps
182
+ } , [ analytics , setDrawerConfig , step ] ) ;
183
+
160
184
const {
161
185
walletUI : { appMode }
162
186
} = useWalletStore ( ) ;
163
187
const isPopupView = appMode === APP_MODE_POPUP ;
164
188
165
189
useEffect ( ( ) => {
166
190
switch ( step ) {
167
- case 'AMOUNT' :
168
- analytics . sendEventToPostHog ( PostHogAction . SendClick ) ;
169
- break ;
170
- case 'REVIEW' :
171
- analytics . sendEventToPostHog ( PostHogAction . SendTransactionDataReviewTransactionClick ) ;
172
- break ;
173
191
case 'DONE' :
174
192
analytics . sendEventToPostHog ( PostHogAction . SendAllDoneView ) ;
175
193
break ;
@@ -236,6 +254,7 @@ export const SendFlow: React.FC = () => {
236
254
237
255
// Step 1 -> 2
238
256
const goToReview = ( newFeeRate : number ) => {
257
+ analytics . sendEventToPostHog ( PostHogAction . SendTransactionDataReviewTransactionClick ) ;
239
258
setFeeRate ( newFeeRate ) ;
240
259
setUnsignedTransaction (
241
260
buildTransaction ( {
@@ -262,7 +281,13 @@ export const SendFlow: React.FC = () => {
262
281
} ) ;
263
282
} ;
264
283
// Step 2 -> 3
265
- const goToPassword = ( ) => setStep ( 'PASSWORD' ) ;
284
+ const goToPassword = ( ) => {
285
+ analytics . sendEventToPostHog ( PostHogAction . SendTransactionSummaryConfirmClick , {
286
+ trigger_point : 'send button' ,
287
+ [ TX_CREATION_TYPE_KEY ] : TxCreationType . Internal
288
+ } ) ;
289
+ setStep ( 'PASSWORD' ) ;
290
+ } ;
266
291
267
292
const handleSignTransaction = useCallback (
268
293
async ( password : Buffer ) : Promise < Bitcoin . SignedTransaction > | undefined => {
@@ -274,6 +299,7 @@ export const SendFlow: React.FC = () => {
274
299
275
300
const handleSubmitTx = async ( signedTx : Bitcoin . SignedTransaction ) => {
276
301
try {
302
+ analytics . sendEventToPostHog ( PostHogAction . SendTransactionConfirmationConfirmClick ) ;
277
303
const hash = await bitcoinWallet . submitTransaction ( signedTx . hex ) ;
278
304
setConfirmationHash ( hash ) ;
279
305
setStep ( 'DONE' ) ;
@@ -335,9 +361,13 @@ export const SendFlow: React.FC = () => {
335
361
if ( step === 'DONE' ) {
336
362
return (
337
363
< TransactionSuccess
338
- onClose = { onClose }
364
+ onClose = { ( ) => {
365
+ analytics . sendEventToPostHog ( PostHogAction . SendAllDoneCloseClick ) ;
366
+ onClose ( ) ;
367
+ } }
339
368
isPopupView = { isPopupView }
340
369
onViewTransaction = { ( ) => {
370
+ analytics . sendEventToPostHog ( PostHogAction . SendAllDoneViewTransactionClick ) ;
341
371
setDrawerConfig ( ) ;
342
372
redirectToTransactions ( ) ;
343
373
} }
@@ -347,7 +377,20 @@ export const SendFlow: React.FC = () => {
347
377
}
348
378
349
379
if ( step === 'FAILED' ) {
350
- return < TransactionFailed onClose = { onClose } isPopupView = { isPopupView } onBack = { backToReview } txError = { txError } /> ;
380
+ return (
381
+ < TransactionFailed
382
+ onClose = { ( ) => {
383
+ analytics . sendEventToPostHog ( PostHogAction . SendSomethingWentWrongCancelClick ) ;
384
+ onClose ( ) ;
385
+ } }
386
+ isPopupView = { isPopupView }
387
+ onBack = { ( ) => {
388
+ analytics . sendEventToPostHog ( PostHogAction . SendSomethingWentWrongBackClick ) ;
389
+ backToReview ( ) ;
390
+ } }
391
+ txError = { txError }
392
+ />
393
+ ) ;
351
394
}
352
395
353
396
return < > </ > ;
0 commit comments