-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathuseWalletHomeOnboardingChecklistFundPress.ts
More file actions
64 lines (59 loc) · 2.34 KB
/
useWalletHomeOnboardingChecklistFundPress.ts
File metadata and controls
64 lines (59 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { useCallback } from 'react';
import { useSelector } from 'react-redux';
import { MetaMetricsEvents } from '../../../core/Analytics';
import { useAnalytics } from '../../hooks/useAnalytics/useAnalytics';
import { ActionLocation } from '../../../util/analytics/actionButtonTracking';
import { getDetectedGeolocation } from '../../../reducers/fiatOrders';
import useRampsUnifiedV1Enabled from '../Ramp/hooks/useRampsUnifiedV1Enabled';
import useRampsUnifiedV2Enabled from '../Ramp/hooks/useRampsUnifiedV2Enabled';
import { useRampsButtonClickData } from '../Ramp/hooks/useRampsButtonClickData';
import { walletHomeOnboardingPrimaryLabelForStep } from './walletHomeOnboardingStepsStrings';
type GoToBuyFromRampNavigation = ReturnType<
typeof import('../Ramp/hooks/useRampNavigation').useRampNavigation
>['goToBuy'];
/**
* Wraps `goToBuy` with {@link MetaMetricsEvents.RAMPS_BUTTON_CLICKED} for the wallet
* home onboarding fund step (TMCU-680: `location` = onboarding_checklist).
*/
export function useWalletHomeOnboardingChecklistFundPress(
goToBuy: GoToBuyFromRampNavigation,
): () => void {
const { trackEvent, createEventBuilder } = useAnalytics();
const buttonClickData = useRampsButtonClickData();
const rampUnifiedV1Enabled = useRampsUnifiedV1Enabled();
const isV2UnifiedEnabled = useRampsUnifiedV2Enabled();
const region = useSelector(getDetectedGeolocation);
return useCallback(() => {
const rampType = isV2UnifiedEnabled
? 'UNIFIED_BUY_2'
: rampUnifiedV1Enabled
? 'UNIFIED_BUY'
: 'BUY';
trackEvent(
createEventBuilder(MetaMetricsEvents.RAMPS_BUTTON_CLICKED)
.addProperties({
button_text: walletHomeOnboardingPrimaryLabelForStep('fund'),
location: ActionLocation.ONBOARDING_CHECKLIST,
ramp_type: rampType,
region,
ramp_routing: buttonClickData.ramp_routing,
is_authenticated: buttonClickData.is_authenticated,
preferred_provider: buttonClickData.preferred_provider,
order_count: buttonClickData.order_count,
})
.build(),
);
goToBuy();
}, [
buttonClickData.is_authenticated,
buttonClickData.order_count,
buttonClickData.preferred_provider,
buttonClickData.ramp_routing,
createEventBuilder,
goToBuy,
isV2UnifiedEnabled,
rampUnifiedV1Enabled,
region,
trackEvent,
]);
}