-
Notifications
You must be signed in to change notification settings - Fork 47
/
RecoveryPhraseScreen.tsx
263 lines (235 loc) · 7.64 KB
/
RecoveryPhraseScreen.tsx
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
import {useFocusEffect, useNavigation} from '@react-navigation/native'
import {useSetupWallet} from '@yoroi/setup-wallet'
import {useTheme} from '@yoroi/theme'
import {BlurView} from 'expo-blur'
import * as React from 'react'
import {
Linking,
Platform,
ScrollView,
StyleSheet,
Text,
TouchableOpacity,
useWindowDimensions,
View,
} from 'react-native'
import LinearGradient from 'react-native-linear-gradient'
import {SafeAreaView} from 'react-native-safe-area-context'
import {Button, useModal} from '../../../../components'
import {Space} from '../../../../components/Space/Space'
import {useMetrics} from '../../../../metrics/metricsManager'
import {WalletInitRouteNavigation} from '../../../../navigation'
import {generateAdaMnemonic} from '../../../../yoroi-wallets/cardano/mnemonic'
import {CardAboutPhrase} from '../../common/CardAboutPhrase/CardAboutPhrase'
import {YoroiZendeskLink} from '../../common/contants'
import {LearnMoreButton} from '../../common/LearnMoreButton/LearnMoreButton'
import {StepperProgress} from '../../common/StepperProgress/StepperProgress'
import {useStrings} from '../../common/useStrings'
import {EyeClosed as EyeClosedIllustration} from '../../illustrations/EyeClosed'
import {EyeOpen as EyeOpenIllustration} from '../../illustrations/EyeOpen'
import {Info as InfoIllustration} from '../../illustrations/Info'
const useSizeModal = () => {
const HEIGHT_SCREEN = useWindowDimensions().height
const mediumScreenHeight = 800
const largerScreenHeight = 900
const PERCENTAGE = HEIGHT_SCREEN >= largerScreenHeight ? 48 : HEIGHT_SCREEN >= mediumScreenHeight ? 55 : 75
const HEIGHT_MODAL = (HEIGHT_SCREEN / 100) * PERCENTAGE
return {HEIGHT_MODAL} as const
}
export const RecoveryPhraseScreen = () => {
const {styles, colors} = useStyles()
const {HEIGHT_MODAL} = useSizeModal()
const {openModal, closeModal} = useModal()
const [isBlur, setIsBlur] = React.useState(true)
const navigation = useNavigation<WalletInitRouteNavigation>()
const strings = useStrings()
const {mnemonicChanged, showCreateWalletInfoModal, showCreateWalletInfoModalChanged} = useSetupWallet()
const {track} = useMetrics()
const bold = useBold()
const mnemonic = React.useMemo(() => generateAdaMnemonic(), [])
useFocusEffect(
React.useCallback(() => {
track.createWalletLearnPhraseStepViewed()
}, [track]),
)
const handleOnShowModal = React.useCallback(() => {
openModal(
strings.recoveryPhraseModalTitle,
<View style={styles.modal}>
<ScrollView>
<View style={styles.content}>
<CardAboutPhrase
title={strings.recoveryPhraseCardTitle}
linesOfText={[
strings.recoveryPhraseCardFirstItem,
strings.recoveryPhraseCardSecondItem,
strings.recoveryPhraseCardThirdItem,
strings.recoveryPhraseCardFourthItem,
strings.recoveryPhraseCardFifthItem,
]}
/>
<LearnMoreButton
onPress={() => {
Linking.openURL(YoroiZendeskLink)
}}
/>
</View>
</ScrollView>
<Space height="s" />
<Button
title={strings.continueButton}
style={styles.button}
onPress={() => {
closeModal()
showCreateWalletInfoModalChanged(false)
}}
/>
<Space height="l" />
</View>,
HEIGHT_MODAL,
)
}, [
HEIGHT_MODAL,
closeModal,
openModal,
showCreateWalletInfoModalChanged,
strings.continueButton,
strings.recoveryPhraseCardFifthItem,
strings.recoveryPhraseCardFirstItem,
strings.recoveryPhraseCardFourthItem,
strings.recoveryPhraseCardSecondItem,
strings.recoveryPhraseCardThirdItem,
strings.recoveryPhraseCardTitle,
strings.recoveryPhraseModalTitle,
styles.button,
styles.content,
styles.modal,
])
React.useEffect(() => {
if (showCreateWalletInfoModal) handleOnShowModal()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [showCreateWalletInfoModal])
return (
<SafeAreaView edges={['left', 'right', 'bottom']} style={styles.root}>
<View style={styles.content}>
<StepperProgress currentStep={2} currentStepTitle={strings.stepRecoveryPhrase} totalSteps={4} />
<Text style={styles.title}>
{strings.recoveryPhraseTitle(bold)}
<TouchableOpacity onPress={handleOnShowModal}>
<InfoIllustration />
</TouchableOpacity>
</Text>
<View style={styles.mnemonicWords}>
<BlurView
experimentalBlurMethod={Platform.OS === 'android' ? 'dimezisBlurView' : 'none'}
intensity={isBlur ? 14 : 0}
style={styles.blurView}
/>
{mnemonic.split(' ').map((word, index) => (
<View key={`mnemonic-${index}`} testID={`mnemonic-${index}`} style={styles.mnemonicTextContainer}>
<LinearGradient
style={[StyleSheet.absoluteFill, {opacity: 1}]}
start={{x: 1, y: 0}}
end={{x: 0, y: 0}}
colors={colors.gradientBlueGreen}
/>
<Text style={styles.mnemonicText}>
<Text style={styles.mnemonicText}>{index + 1}. </Text>
{word}
</Text>
</View>
))}
</View>
<TouchableOpacity activeOpacity={0.5} style={styles.blurButton} onPress={() => setIsBlur(!isBlur)}>
{isBlur ? <EyeOpenIllustration /> : <EyeClosedIllustration />}
<Text style={styles.blurTextButton}>
{!isBlur ? strings.hideRecoveryPhraseButton : strings.showRecoveryPhraseButton}
</Text>
</TouchableOpacity>
</View>
<View>
<Button
title={strings.next}
style={styles.button}
disabled={isBlur}
onPress={() => {
mnemonicChanged(mnemonic)
navigation.navigate('setup-wallet-verify-recovery-phrase-mnemonic')
}}
/>
<Space height="s" />
</View>
</SafeAreaView>
)
}
const useBold = () => {
const {styles} = useStyles()
return {
b: (text: React.ReactNode) => <Text style={styles.bolder}>{text}</Text>,
}
}
const useStyles = () => {
const {theme} = useTheme()
const styles = StyleSheet.create({
root: {
flex: 1,
...theme.padding['x-l'],
justifyContent: 'space-between',
backgroundColor: theme.color['white-static'],
},
modal: {
flex: 1,
},
title: {
...theme.typography['body-1-l-regular'],
color: theme.color.gray[900],
},
bolder: {
...theme.typography['body-1-l-medium'],
},
content: {
gap: 16,
},
button: {backgroundColor: theme.color.primary[500]},
mnemonicWords: {
flexDirection: 'row',
flexWrap: 'wrap',
gap: 8,
...theme.padding['y-s'],
},
mnemonicTextContainer: {
flexDirection: 'row',
flexWrap: 'wrap',
borderRadius: 8,
overflow: 'hidden',
...theme.padding['x-l'],
...theme.padding['y-s'],
},
mnemonicText: {
...theme.typography['body-1-l-regular'],
color: theme.color.primary['600'],
},
blurView: {
position: 'absolute',
...theme.padding['xxl'],
left: -8,
right: -8,
bottom: 0,
top: 0,
zIndex: 1,
},
blurButton: {
flexDirection: 'row',
alignItems: 'center',
gap: 8,
},
blurTextButton: {
...theme.typography['button-2-m'],
color: theme.color.primary[500],
},
})
const colors = {
gradientBlueGreen: theme.color.gradients['blue-green'],
}
return {styles, colors} as const
}