-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathPaymentSubmitLoading.tsx
More file actions
68 lines (61 loc) · 1.87 KB
/
PaymentSubmitLoading.tsx
File metadata and controls
68 lines (61 loc) · 1.87 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
import React, { memo, useCallback, useEffect, useState } from 'react'
import { StyleSheet } from 'react-native'
import Video from 'react-native-video'
import videoSource from '@assets/videos/paymentSent.mp4'
import { useTranslation } from 'react-i18next'
import Text from '@components/Text'
import Box from '@components/Box'
import ActivityIndicator from '@components/ActivityIndicator'
import FadeInOut from '@components/FadeInOut'
import globalStyles from '@theme/globalStyles'
type Props = {
onVideoEnd: () => void
}
const VIDEO_TIMEOUT_MS = 5000
const PaymentSubmitLoading = ({ onVideoEnd }: Props) => {
const { t } = useTranslation()
const [videoEnded, setVideoEnded] = useState(false)
const handleVideoEnded = useCallback(() => {
setVideoEnded(true)
onVideoEnd()
}, [onVideoEnd])
// Fallback timeout in case video onEnd never fires
useEffect(() => {
const timer = setTimeout(handleVideoEnded, VIDEO_TIMEOUT_MS)
return () => clearTimeout(timer)
}, [handleVideoEnded])
return (
<>
<Box style={StyleSheet.absoluteFill} justifyContent="center">
<Box aspectRatio={1}>
{!videoEnded && (
<FadeInOut style={globalStyles.container} slow>
<Video
resizeMode="contain"
source={videoSource}
style={StyleSheet.absoluteFill}
onEnd={handleVideoEnded}
/>
</FadeInOut>
)}
{videoEnded && (
<FadeInOut>
<ActivityIndicator />
</FadeInOut>
)}
</Box>
</Box>
<Box flex={1} justifyContent="flex-end">
<Text
variant="subtitle2"
textAlign="center"
color="secondaryText"
padding="xl"
>
{t('payment.sending')}
</Text>
</Box>
</>
)
}
export default memo(PaymentSubmitLoading)