-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathDelegationDrawer.tsx
More file actions
234 lines (223 loc) · 5.79 KB
/
Copy pathDelegationDrawer.tsx
File metadata and controls
234 lines (223 loc) · 5.79 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import { BigNumber } from "bignumber.js";
import React from "react";
import type { ComponentType } from "react";
import { View, StyleSheet, ScrollView } from "react-native";
import type { StyleProp, ViewStyle } from "react-native";
import { getAccountCurrency } from "@ledgerhq/live-common/account/index";
import { getCurrencyColor } from "@ledgerhq/live-common/currencies/index";
import type { AccountLike } from "@ledgerhq/types-live";
// TODO move to component
import { useTheme } from "@react-navigation/native";
import DelegatingContainer from "~/families/tezos/DelegatingContainer";
import { rgba } from "../colors";
import getWindowDimensions from "~/logic/getWindowDimensions";
import QueuedDrawer from "./QueuedDrawer";
import Circle from "./Circle";
import Touchable from "./Touchable";
import LText from "./LText";
import CurrencyUnitValue from "./CurrencyUnitValue";
import CounterValue from "./CounterValue";
import CurrencyIcon from "./CurrencyIcon";
import { normalize } from "~/helpers/normalizeSize";
import { useAccountUnit } from "~/hooks/useAccountUnit";
const { height } = getWindowDimensions();
type Props = {
isOpen: boolean;
onClose: () => void;
account: AccountLike;
icon?: React.ReactNode;
ValidatorImage: ComponentType<{
size: number;
}>;
counterValueDate?: Date;
amount: BigNumber;
data: FieldType[];
actions: Action[];
undelegation?: boolean;
};
export default function DelegationDrawer({
isOpen,
onClose,
account,
ValidatorImage,
counterValueDate,
// TODO use formattedAmount & formattedCounterValue instead
amount,
data,
actions,
undelegation,
icon,
}: Props) {
const currency = getAccountCurrency(account);
const color = getCurrencyColor(currency);
const unit = useAccountUnit(account);
const iconWidth = normalize(64);
return (
<QueuedDrawer style={styles.modal} isRequestingToBeOpened={isOpen} onClose={onClose}>
<View style={styles.root}>
<DelegatingContainer
left={
icon || (
<Circle size={iconWidth} bg={rgba(color, 0.2)}>
<CurrencyIcon size={iconWidth / 2} currency={currency} />
</Circle>
)
}
undelegation={undelegation}
right={<ValidatorImage size={iconWidth} />}
/>
<View style={styles.subHeader}>
<LText semiBold style={[styles.currencyValue]}>
<CurrencyUnitValue showCode unit={unit} value={amount} />
</LText>
<LText semiBold style={styles.counterValue} color="grey">
<CounterValue
currency={currency}
showCode
value={amount}
alwaysShowSign={false}
withPlaceholder
date={counterValueDate}
/>
</LText>
</View>
<ScrollView style={styles.scrollSection} showsVerticalScrollIndicator={true}>
{data.map((field, i) => (
<DataField {...field} key={"data-" + i} isLast={i === data.length - 1} />
))}
</ScrollView>
<View style={[styles.row, styles.actionsRow]}>
{actions.map((props, i) => (
<ActionButton key={`actions-${i}`} {...props} />
))}
</View>
</View>
</QueuedDrawer>
);
}
export type FieldType = {
label: React.ReactNode;
Component: React.ReactNode;
};
type DataFieldProps = FieldType & {
isLast: boolean;
};
function DataField({ label, Component, isLast }: DataFieldProps) {
const { colors } = useTheme();
return (
<View
style={[
styles.row,
styles.fieldRow,
{
borderBottomColor: colors.lightFog,
},
isLast ? styles.lastRow : undefined,
]}
>
<View>
<LText numberOfLines={1} semiBold style={styles.labelText} color="smoke">
{label}
</LText>
</View>
<View style={styles.valueWrapper}>{Component}</View>
</View>
);
}
export type Action = {
label?: React.ReactNode;
Icon: string | ComponentType<IconProps>;
event?: string;
eventProperties?: Record<string, unknown>;
disabled?: boolean;
onPress?: () => void;
};
export type IconProps = {
size: number;
style: StyleProp<ViewStyle>;
bg?: string;
};
function ActionButton({ label, Icon, event, eventProperties, onPress, disabled }: Action) {
return (
<Touchable
disabled={disabled}
event={event}
eventProperties={eventProperties}
style={styles.actionButtonWrapper}
onPress={onPress}
>
<Icon size={48} style={styles.actionIcon} />
<LText semiBold style={[styles.actionText]} color={disabled ? "grey" : "darkBlue"}>
{label}
</LText>
</Touchable>
);
}
export const styles = StyleSheet.create({
modal: {
position: "relative",
},
root: {
paddingTop: 8,
},
closeButton: {
alignSelf: "flex-end",
marginRight: 16,
},
scrollSection: {
maxHeight: height - normalize(425),
paddingHorizontal: 16,
},
subHeader: {
paddingBottom: 16,
alignItems: "center",
alignSelf: "center",
},
currencyValue: {
fontSize: 22,
},
counterValue: {
fontSize: 16,
},
row: {
flexDirection: "row",
alignItems: "center",
},
fieldRow: {
justifyContent: "space-between",
borderBottomWidth: 1,
paddingVertical: 16,
},
lastRow: {
borderBottomWidth: 0,
},
labelText: {
paddingRight: 8,
fontSize: 14,
},
valueWrapper: {
width: "50%",
alignItems: "flex-end",
},
actionsRow: {
paddingTop: 16,
paddingHorizontal: 16,
alignItems: "flex-start",
justifyContent: "space-between",
},
actionWrapper: {
width: 80,
alignItems: "center",
},
actionIcon: {
marginBottom: 8,
},
actionText: {
fontSize: 14,
textAlign: "center",
},
actionButtonWrapper: {
width: 80,
alignItems: "center",
},
});