|
| 1 | +import { Button, PrettyJSON, Spacer, Text } from '@/modules/ui-components' |
| 2 | +import React, { useEffect, useRef, useState } from 'react' |
| 3 | +import { View, Animated, Easing, StyleSheet, Vibration } from 'react-native' |
| 4 | + |
| 5 | +interface Prop { |
| 6 | + onCancel: () => void |
| 7 | + txResponse?: string |
| 8 | +} |
| 9 | + |
| 10 | +export function BroadcastingFailedView({ onCancel = () => {}, txResponse = '' }: Prop) { |
| 11 | + const shakeAnim = useRef(new Animated.Value(0)).current |
| 12 | + const fadeAnim = useRef(new Animated.Value(1)).current |
| 13 | + const scaleAnim = useRef(new Animated.Value(1)).current |
| 14 | + |
| 15 | + const [details, showDetails] = useState(false) |
| 16 | + |
| 17 | + useEffect(() => { |
| 18 | + Vibration.vibrate(500) |
| 19 | + |
| 20 | + Animated.sequence([ |
| 21 | + Animated.parallel([ |
| 22 | + Animated.sequence([ |
| 23 | + Animated.timing(shakeAnim, { |
| 24 | + toValue: 10, |
| 25 | + duration: 100, |
| 26 | + useNativeDriver: true |
| 27 | + }), |
| 28 | + Animated.timing(shakeAnim, { |
| 29 | + toValue: -10, |
| 30 | + duration: 100, |
| 31 | + useNativeDriver: true |
| 32 | + }), |
| 33 | + Animated.timing(shakeAnim, { |
| 34 | + toValue: 6, |
| 35 | + duration: 100, |
| 36 | + useNativeDriver: true |
| 37 | + }), |
| 38 | + Animated.timing(shakeAnim, { |
| 39 | + toValue: -6, |
| 40 | + duration: 100, |
| 41 | + useNativeDriver: true |
| 42 | + }), |
| 43 | + Animated.timing(shakeAnim, { |
| 44 | + toValue: 0, |
| 45 | + duration: 100, |
| 46 | + useNativeDriver: true |
| 47 | + }) |
| 48 | + ]), |
| 49 | + Animated.sequence([ |
| 50 | + Animated.timing(scaleAnim, { |
| 51 | + toValue: 1.2, |
| 52 | + duration: 300, |
| 53 | + useNativeDriver: true |
| 54 | + }), |
| 55 | + Animated.timing(scaleAnim, { |
| 56 | + toValue: 1, |
| 57 | + duration: 300, |
| 58 | + useNativeDriver: true |
| 59 | + }) |
| 60 | + ]) |
| 61 | + ]), |
| 62 | + Animated.timing(fadeAnim, { |
| 63 | + toValue: 1, |
| 64 | + duration: 500, |
| 65 | + easing: Easing.out(Easing.ease), |
| 66 | + useNativeDriver: true |
| 67 | + }) |
| 68 | + ]).start() |
| 69 | + // eslint-disable-next-line react-hooks/exhaustive-deps |
| 70 | + }, []) |
| 71 | + |
| 72 | + return ( |
| 73 | + <View style={styles.container}> |
| 74 | + <View style={styles.center}> |
| 75 | + <Animated.View |
| 76 | + style={[ |
| 77 | + styles.xCircle, |
| 78 | + { |
| 79 | + transform: [{ translateX: shakeAnim }, { scale: scaleAnim }], |
| 80 | + opacity: fadeAnim |
| 81 | + } |
| 82 | + ]} |
| 83 | + > |
| 84 | + <Text.Body style={styles.statusText}>✕</Text.Body> |
| 85 | + </Animated.View> |
| 86 | + </View> |
| 87 | + <Text.Body style={styles.statusText}>Transaction Failed</Text.Body> |
| 88 | + <Spacer space={56} /> |
| 89 | + <Button color="tertirary" onPress={() => showDetails(!details)}> |
| 90 | + Show details... |
| 91 | + </Button> |
| 92 | + |
| 93 | + {details && <PrettyJSON data={JSON.parse(txResponse)} />} |
| 94 | + |
| 95 | + <View style={styles.middleScreen}> |
| 96 | + <View style={styles.botton}> |
| 97 | + <Button color="primary" onPress={onCancel}> |
| 98 | + Try Again |
| 99 | + </Button> |
| 100 | + </View> |
| 101 | + </View> |
| 102 | + </View> |
| 103 | + ) |
| 104 | +} |
| 105 | +const styles = StyleSheet.create({ |
| 106 | + container: { |
| 107 | + flex: 1, |
| 108 | + paddingTop: 120 |
| 109 | + }, |
| 110 | + middleScreen: { |
| 111 | + flex: 1, |
| 112 | + alignContent: 'flex-end', |
| 113 | + marginTop: 42 |
| 114 | + }, |
| 115 | + center: { |
| 116 | + alignItems: 'center', |
| 117 | + textAlign: 'center' |
| 118 | + }, |
| 119 | + failedText: { |
| 120 | + fontSize: 18, |
| 121 | + fontWeight: '600', |
| 122 | + marginTop: 10 |
| 123 | + }, |
| 124 | + xCircle: { |
| 125 | + width: 80, |
| 126 | + height: 80, |
| 127 | + backgroundColor: '#e74c3c', |
| 128 | + borderRadius: 40, |
| 129 | + justifyContent: 'center', |
| 130 | + alignItems: 'center', |
| 131 | + shadowColor: '#e74c3c', |
| 132 | + shadowOpacity: 0.4, |
| 133 | + shadowRadius: 10, |
| 134 | + shadowOffset: { width: 0, height: 4 }, |
| 135 | + marginBottom: 20 |
| 136 | + }, |
| 137 | + statusText: { |
| 138 | + color: '#fff', |
| 139 | + fontWeight: 'bold', |
| 140 | + textAlign: 'center' |
| 141 | + }, |
| 142 | + botton: { |
| 143 | + flex: 1, |
| 144 | + alignContent: 'center', |
| 145 | + justifyContent: 'flex-end' |
| 146 | + } |
| 147 | +}) |
0 commit comments