-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathuseRampNavigation.ts
More file actions
96 lines (90 loc) · 3.26 KB
/
useRampNavigation.ts
File metadata and controls
96 lines (90 loc) · 3.26 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { useCallback } from 'react';
import { useNavigation } from '@react-navigation/native';
import { useSelector } from 'react-redux';
import {
RampIntent,
RampType as AggregatorRampType,
} from '../Aggregator/types';
import { createRampNavigationDetails } from '../Aggregator/routes/utils';
import { createDepositNavigationDetails } from '../Deposit/routes/utils';
import {
navigateToRampBuy,
NavigateToRampBuyMode,
type NavigateToRampBuyOptions,
} from '../utils/navigateToRampBuy';
import { getRampRoutingDecision } from '../../../../reducers/fiatOrders';
import { useRampsTokens } from './useRampsTokens';
import useRampsUnifiedV1Enabled from './useRampsUnifiedV1Enabled';
import useRampsUnifiedV2Enabled from './useRampsUnifiedV2Enabled';
/**
* Hook that returns functions to navigate to ramp flows.
*
* @returns An object containing navigation functions:
* - goToBuy: Smart routing based on unified V1 settings and routing decision
* - goToAggregator: deprecated Always navigates to aggregator BUY flow (bypasses smart routing)
* - goToSell: Always navigates to aggregator SELL flow
* - goToDeposit: deprecated Always navigates to deposit flow (bypasses smart routing)
*/
export const useRampNavigation = () => {
const navigation = useNavigation();
const isRampsUnifiedV1Enabled = useRampsUnifiedV1Enabled();
const isRampsUnifiedV2Enabled = useRampsUnifiedV2Enabled();
const rampRoutingDecision = useSelector(getRampRoutingDecision);
const { setSelectedToken, tokens: rampsTokens } = useRampsTokens();
const goToBuy = useCallback(
(intent?: RampIntent, options?: NavigateToRampBuyOptions) => {
navigateToRampBuy(navigation, intent, options, {
isRampsUnifiedV1Enabled,
isRampsUnifiedV2Enabled,
rampRoutingDecision,
rampsTokensAll: rampsTokens?.allTokens ?? [],
setSelectedToken,
});
},
[
setSelectedToken,
navigation,
isRampsUnifiedV1Enabled,
isRampsUnifiedV2Enabled,
rampRoutingDecision,
rampsTokens?.allTokens,
],
);
/**
* @deprecated Use goToBuy instead. This function always navigates to the aggregator BUY flow,
* bypassing unified routing. Use goToBuy for smart routing that respects user preferences.
*/
const goToAggregator = useCallback(
(intent?: RampIntent) => {
goToBuy(intent, {
mode: NavigateToRampBuyMode.AGGREGATOR,
overrideUnifiedRouting: true,
});
},
[goToBuy],
);
const goToSell = useCallback(
(intent?: RampIntent) => {
navigation.navigate(
...createRampNavigationDetails(AggregatorRampType.SELL, intent),
);
},
[navigation],
);
/**
* @deprecated Use goToBuy instead. This function always navigates to the deposit flow,
* bypassing unified routing. Use goToBuy for smart routing that respects user preferences.
*/
const goToDeposit = useCallback(
(intent?: RampIntent) => {
goToBuy(intent, {
mode: NavigateToRampBuyMode.DEPOSIT,
overrideUnifiedRouting: true,
});
},
[goToBuy],
);
// Deprecated entries remain part of the public hook API for existing callers.
// eslint-disable-next-line @typescript-eslint/no-deprecated -- backward-compatible exports
return { goToBuy, goToAggregator, goToSell, goToDeposit };
};