This repository has been archived by the owner on Jun 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 117
/
RenderError.js
159 lines (148 loc) · 4.05 KB
/
RenderError.js
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
// @flow
import React, { Component } from "react";
import { StyleSheet, View } from "react-native";
import { BleErrorCode } from "react-native-ble-plx";
import { Trans } from "react-i18next";
import { PairingFailed, GenuineCheckFailed } from "@ledgerhq/errors";
import LocationRequired from "../LocationRequired";
import { TrackScreen } from "../../analytics";
import Touchable from "../../components/Touchable";
import LText from "../../components/LText";
import Button from "../../components/Button";
import GenericErrorView from "../../components/GenericErrorView";
import HelpLink from "../../components/HelpLink";
import IconArrowRight from "../../icons/ArrowRight";
import colors from "../../colors";
import { urls } from "../../config/urls";
type Props = {
error: Error,
status: string,
onRetry: () => void,
onBypassGenuine: () => void,
};
const hitSlop = {
top: 16,
left: 16,
right: 16,
bottom: 16,
};
class RenderError extends Component<Props> {
render() {
const { error, status, onBypassGenuine, onRetry } = this.props;
// $FlowFixMe
if (error.errorCode === BleErrorCode.LocationServicesDisabled) {
return <LocationRequired onRetry={onRetry} errorType="disabled" />;
}
// $FlowFixMe
if (error.errorCode === BleErrorCode.BluetoothUnauthorized) {
return <LocationRequired onRetry={onRetry} errorType="unauthorized" />;
}
const isPairingStatus = status === "pairing";
const isGenuineCheckStatus = status === "genuinecheck";
const url = (isPairingStatus && urls.errors.PairingFailed) || undefined;
const outerError = isPairingStatus
? new PairingFailed()
: isGenuineCheckStatus
? new GenuineCheckFailed()
: null;
return (
<View style={styles.root}>
<TrackScreen category="PairDevices" name="Error" />
<View style={styles.body}>
<GenericErrorView
error={error}
outerError={outerError}
withDescription
withIcon
/>
<View style={styles.buttonContainer}>
<Button
event="PairDevicesRetry"
type="primary"
title={<Trans i18nKey="common.retry" />}
onPress={onRetry}
containerStyle={styles.button}
/>
</View>
{isGenuineCheckStatus ? (
<Touchable
event="PairDevicesBypassGenuine"
onPress={onBypassGenuine}
hitSlop={hitSlop}
style={styles.linkContainer}
>
<LText style={styles.linkText} semiBold>
<Trans i18nKey="common.skip" />{" "}
</LText>
<IconArrowRight size={16} color={colors.live} />
</Touchable>
) : (
<HelpLink url={url} style={styles.linkContainer} />
)}
</View>
{isGenuineCheckStatus ? (
<View style={styles.footer}>
<HelpLink style={styles.linkContainerGenuine} />
</View>
) : null}
</View>
);
}
}
export default RenderError;
const styles = StyleSheet.create({
root: {
flex: 1,
flexDirection: "column",
},
body: {
flex: 1,
padding: 20,
alignItems: "center",
justifyContent: "center",
flexDirection: "column",
},
title: {
marginTop: 32,
textAlign: "center",
color: colors.darkBlue,
fontSize: 18,
},
description: {
marginTop: 16,
paddingHorizontal: 24,
textAlign: "center",
fontSize: 14,
lineHeight: 21,
color: colors.smoke,
},
buttonContainer: {
flexDirection: "row",
marginTop: 32,
},
button: {
flex: 1,
},
linkContainer: {
marginTop: 24,
alignItems: "center",
justifyContent: "center",
flexDirection: "row",
},
linkContainerGenuine: {
alignItems: "center",
justifyContent: "center",
flexDirection: "row",
},
linkText: {
color: colors.live,
marginLeft: 6,
},
footer: {
height: 48,
alignItems: "center",
justifyContent: "center",
borderTopWidth: 1,
borderColor: colors.lightFog,
},
});