-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathRouteOptionsDrawer.tsx
More file actions
134 lines (124 loc) · 3.86 KB
/
Copy pathRouteOptionsDrawer.tsx
File metadata and controls
134 lines (124 loc) · 3.86 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import {
Drawer, EllipsizedText, MenuItem,
} from '@biom3/react';
import { motion } from 'framer-motion';
import { useContext, useEffect, useRef } from 'react';
import { Checkout } from '@imtbl/checkout-sdk';
import { useTranslation } from 'react-i18next';
import { useAnalytics, UserJourney } from '../../context/analytics-provider/SegmentAnalyticsProvider';
import { useProvidersContext } from '../../context/providers-context/ProvidersContext';
import { listVariants } from '../../lib/animation/listAnimation';
import { RouteData } from '../../lib/squid/types';
import { AddTokensContext } from '../../widgets/add-tokens/context/AddTokensContext';
import { FiatOptionType } from '../../widgets/add-tokens/types';
import { RouteOptions } from './RouteOptions';
type OptionsDrawerProps = {
checkout: Checkout;
routes: RouteData[] | undefined;
visible: boolean;
onClose: () => void;
onRouteClick: (route: RouteData) => void;
onCardClick: (type: FiatOptionType) => void;
showOnrampOption?: boolean;
showSwapOption?: boolean;
showBridgeOption?: boolean;
insufficientBalance?: boolean;
};
export function RouteOptionsDrawer({
checkout,
routes,
visible,
onClose,
onRouteClick,
onCardClick,
showOnrampOption,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
showSwapOption,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
showBridgeOption,
insufficientBalance,
}: OptionsDrawerProps) {
const { t } = useTranslation();
const { track } = useAnalytics();
const {
addTokensState: { id, chains },
} = useContext(AddTokensContext);
const {
providersState: { fromProviderInfo, fromAddress },
} = useProvidersContext();
const selectedRouteIndex = useRef<number>(0);
const handleOnRouteClick = (route: RouteData, index: number) => {
selectedRouteIndex.current = index;
onRouteClick(route);
};
useEffect(() => {
if (!visible) {
return;
}
track({
userJourney: UserJourney.ADD_TOKENS,
screen: 'InputScreen',
control: 'RoutesMenu',
controlType: 'MenuItem',
action: 'Opened',
extras: {
contextId: id,
showOnrampOption: Boolean(showOnrampOption),
showSwapOption: Boolean(showSwapOption),
insufficientBalance: Boolean(insufficientBalance),
routesAvailable: routes?.length ?? 0,
},
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [visible]);
return (
<Drawer
size="full"
visible={visible}
showHeaderBar={false}
onCloseDrawer={onClose}
>
<Drawer.Content
rc={
<motion.div variants={listVariants} initial="hidden" animate="show" />
}
sx={{
pt: 'base.spacing.x3',
px: 'base.spacing.x3',
}}
>
<MenuItem size="xSmall">
<MenuItem.FramedImage
padded
emphasized
use={(
<img src={fromProviderInfo?.icon} alt={fromProviderInfo?.name} />
)}
sx={{ mx: 'base.spacing.x2' }}
/>
<MenuItem.Label>{t('views.ADD_TOKENS.drawer.options.heading')}</MenuItem.Label>
<MenuItem.Caption>
{fromProviderInfo?.name}
{' • '}
<EllipsizedText
text={fromAddress ?? ''}
sx={{ c: 'inherit', fontSize: 'inherit' }}
/>
</MenuItem.Caption>
<MenuItem.StatefulButtCon icon="ChevronExpand" onClick={onClose} />
</MenuItem>
<RouteOptions
size="small"
checkout={checkout}
routes={routes}
chains={chains}
onCardClick={onCardClick}
onRouteClick={handleOnRouteClick}
showOnrampOption={showOnrampOption}
insufficientBalance={insufficientBalance}
selectedIndex={selectedRouteIndex.current}
/>
</Drawer.Content>
</Drawer>
);
}