-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathErrorDetailsModal.tsx
More file actions
168 lines (157 loc) · 4.75 KB
/
Copy pathErrorDetailsModal.tsx
File metadata and controls
168 lines (157 loc) · 4.75 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
import React, { useCallback, useRef } from 'react';
import { View, ScrollView, useWindowDimensions } from 'react-native';
import InAppBrowser from 'react-native-inappbrowser-reborn';
import { useNavigation } from '@react-navigation/native';
import type { AppStackNavigationProp } from '../../../../../../core/NavigationService/types';
import {
BottomSheet,
Button,
ButtonBaseSize,
ButtonVariant,
HeaderStandard,
Icon,
IconColor,
IconName,
IconSize,
Text,
TextColor,
TextVariant,
type BottomSheetRef,
} from '@metamask/design-system-react-native';
import { useStyles } from '../../../../../hooks/useStyles';
import {
createNavigationDetails,
useParams,
} from '../../../../../../util/navigation/navUtils';
import Routes from '../../../../../../constants/navigation/Routes';
import { strings } from '../../../../../../../locales/i18n';
import Logger from '../../../../../../util/Logger';
import styleSheet from './ErrorDetailsModal.styles';
import { useElevatedSurface } from '../../../../../../util/theme/themeUtils';
export interface ErrorDetailsModalParams {
errorMessage: string;
providerName?: string;
providerSupportUrl?: string;
showChangeProvider?: boolean;
amount?: number;
}
export const createErrorDetailsModalNavDetails =
createNavigationDetails<ErrorDetailsModalParams>(
Routes.RAMP.MODALS.ID,
Routes.RAMP.MODALS.ERROR_DETAILS,
);
function ErrorDetailsModal() {
const sheetRef = useRef<BottomSheetRef>(null);
const navigation = useNavigation<AppStackNavigationProp>();
const { height: screenHeight } = useWindowDimensions();
const { styles } = useStyles(styleSheet, {
screenHeight,
});
const {
errorMessage,
providerName,
providerSupportUrl,
showChangeProvider,
amount,
} = useParams<ErrorDetailsModalParams>();
const surfaceClass = useElevatedSurface();
const handleClose = useCallback(() => {
sheetRef.current?.onCloseBottomSheet();
}, []);
const handleContactSupport = useCallback(async () => {
if (!providerSupportUrl) return;
try {
if (await InAppBrowser.isAvailable()) {
handleClose();
await InAppBrowser.open(providerSupportUrl);
} else {
handleClose();
navigation.navigate('Webview', {
screen: 'SimpleWebview',
params: {
url: providerSupportUrl,
title: providerName,
},
});
}
} catch (error) {
Logger.error(
error as Error,
'ErrorDetailsModal: Failed to open support URL',
);
}
}, [providerSupportUrl, providerName, handleClose, navigation]);
const handleChangeProvider = useCallback(() => {
navigation.replace(Routes.RAMP.MODALS.PROVIDER_SELECTION, { amount });
}, [navigation, amount]);
return (
<BottomSheet
ref={sheetRef}
goBack={navigation.goBack}
twClassName={surfaceClass}
>
<HeaderStandard
onClose={handleClose}
closeButtonProps={{ testID: 'error-details-close-button' }}
>
<View style={styles.headerContainer}>
<Icon
name={IconName.Danger}
size={IconSize.Md}
color={IconColor.ErrorDefault}
/>
<Text variant={TextVariant.HeadingMd}>
{strings('deposit.errors.error_details_title')}
</Text>
</View>
</HeaderStandard>
<ScrollView style={styles.scrollView}>
<View style={styles.contentContainer}>
<Text
variant={TextVariant.BodyMd}
color={TextColor.TextDefault}
style={styles.errorText}
>
{errorMessage}
</Text>
</View>
</ScrollView>
<View style={styles.buttonContainer}>
{showChangeProvider ? (
<Button
variant={ButtonVariant.Secondary}
size={ButtonBaseSize.Lg}
onPress={handleChangeProvider}
style={styles.button}
isFullWidth
>
{strings('fiat_on_ramp.change_provider_button')}
</Button>
) : null}
{!showChangeProvider && providerName && providerSupportUrl ? (
<Button
variant={ButtonVariant.Secondary}
size={ButtonBaseSize.Lg}
onPress={handleContactSupport}
style={styles.button}
isFullWidth
>
{strings('fiat_on_ramp.contact_provider_support', {
provider: providerName,
})}
</Button>
) : null}
<Button
variant={ButtonVariant.Primary}
size={ButtonBaseSize.Lg}
onPress={handleClose}
style={styles.button}
isFullWidth
>
{strings('fiat_on_ramp.got_it')}
</Button>
</View>
</BottomSheet>
);
}
export default ErrorDetailsModal;