-
Notifications
You must be signed in to change notification settings - Fork 6
/
ErrorModal.tsx
104 lines (94 loc) · 4.35 KB
/
ErrorModal.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
import React, { FC, useState, useEffect } from 'react'
import { View, ScrollView, LayoutAnimation, Platform, UIManager } from 'react-native'
import { BottomModal, Button, Icon, ListItem, Text } from '../components'
import AppError from '../utils/AppError'
import { spacing, useThemeColor, colors } from '../theme'
import { isObj } from '@cashu/cashu-ts/src/utils'
import JSONTree from 'react-native-json-tree'
if (Platform.OS === 'android' &&
UIManager.setLayoutAnimationEnabledExperimental) {
UIManager.setLayoutAnimationEnabledExperimental(true)
}
type ErrorModalProps = {
error: AppError
}
export const ErrorModal: FC<ErrorModalProps> = function ({ error }) {
const [isErrorVisible, setIsErrorVisible] = useState<boolean>(true)
const [isParamsVisible, setIsParamsVisible] = useState<boolean>(false)
// needed for error to re-appear
useEffect(() => {
setIsErrorVisible(true)
}, [error])
const toggleParams = () => {
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
setIsParamsVisible(previousState => !previousState)
}
const onClose = () => {
setIsErrorVisible(false)
}
const backgroundColor = useThemeColor('error')
return (
<BottomModal
isVisible={isErrorVisible}
onBackdropPress={onClose}
onBackButtonPress={onClose}
style={{ backgroundColor }}
ContentComponent={
<>
<View style={{ flexDirection: 'row', alignItems: 'center', marginBottom: spacing.small }}>
<Icon icon="faInfoCircle" size={spacing.large} color="white" />
<Text style={{ color: 'white', marginLeft: spacing.small }}>{error.name}</Text>
</View>
<View>
<Text style={{ color: 'white', marginBottom: spacing.small }}>{error.message}</Text>
</View>
{error.params && isObj(error.params) && (
<View>
{isParamsVisible ? (
<>
<View style={{borderRadius: spacing.small, backgroundColor: '#fff', padding: spacing.tiny}}>
<JSONTree
hideRoot
data={error.params}
theme={{
scheme: 'codeschool',
author: 'brettof86',
base00: '#000000',
base01: '#2e2f30',
base02: '#515253',
base03: '#737475',
base04: '#959697',
base05: '#b7b8b9',
base06: '#dadbdc',
base07: '#fcfdfe',
base08: '#e31a1c',
base09: '#e6550d',
base0A: '#dca060',
base0B: '#31a354',
base0C: '#80b1d3',
base0D: '#3182bd',
base0E: '#756bb1',
base0F: '#b15928'
}}
/>
</View>
<Button
onPress={toggleParams}
text='Hide details'
preset='tertiary'
/>
</>
) : (
<Button
onPress={toggleParams}
text='Show details'
preset='tertiary'
/>
)}
</View>
)}
</>
}
/>
)
}