BlueWallet/screen/wallets/pleaseBackup.js

134 lines
3.4 KiB
JavaScript
Raw Normal View History

2020-04-27 19:10:42 -04:00
import React, { useEffect, useState, useCallback } from 'react';
import { ActivityIndicator, View, BackHandler, Text, ScrollView, StyleSheet } from 'react-native';
2020-05-27 14:12:17 +03:00
import { useNavigation, useRoute } from '@react-navigation/native';
import { BlueSpacing20, SafeBlueArea, BlueNavigationStyle, BlueText, BlueButton } from '../../BlueComponents';
import Privacy from '../../Privacy';
2020-04-27 19:10:42 -04:00
const loc = require('../../loc');
const styles = StyleSheet.create({
2020-05-30 10:47:32 +03:00
flex: {
flex: 1,
},
loading: {
flex: 1,
paddingTop: 20,
},
word: {
width: 'auto',
marginRight: 8,
marginBottom: 8,
backgroundColor: '#f5f5f5',
paddingTop: 6,
paddingBottom: 6,
paddingLeft: 8,
paddingRight: 8,
borderRadius: 4,
},
wortText: {
color: '#81868E',
fontWeight: 'bold',
},
scrollViewContent: {
justifyContent: 'space-between',
},
please: {
alignItems: 'center',
paddingHorizontal: 16,
},
successText: {
textAlign: 'center',
fontWeight: 'bold',
color: '#0C2550',
},
pleaseText: {
paddingBottom: 10,
paddingRight: 0,
paddingLeft: 0,
color: '#0C2550',
},
secret: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
flexWrap: 'wrap',
marginTop: 14,
},
ok: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
flexWrap: 'wrap',
},
});
2020-04-27 19:10:42 -04:00
const PleaseBackup = () => {
const [isLoading, setIsLoading] = useState(true);
2020-05-27 14:12:17 +03:00
const route = useRoute();
const words = route.params.secret.split(' ');
const navigation = useNavigation();
2020-04-27 19:10:42 -04:00
const handleBackButton = useCallback(() => {
2020-05-27 14:12:17 +03:00
navigation.dangerouslyGetParent().pop();
return true;
2020-05-27 14:12:17 +03:00
}, [navigation]);
2020-04-27 19:10:42 -04:00
useEffect(() => {
Privacy.enableBlur();
2020-04-27 19:10:42 -04:00
setIsLoading(false);
BackHandler.addEventListener('hardwareBackPress', handleBackButton);
2020-04-27 19:10:42 -04:00
return () => {
Privacy.disableBlur();
BackHandler.removeEventListener('hardwareBackPress', handleBackButton);
};
}, [handleBackButton, words]);
2020-04-27 19:10:42 -04:00
const renderSecret = () => {
const component = [];
2020-04-27 19:10:42 -04:00
for (const [index, secret] of words.entries()) {
component.push(
<View style={styles.word} key={`${secret}${index}`}>
<Text style={styles.wortText}>
2020-05-28 11:42:08 -04:00
{`${index + 1}`}. {secret}
2020-05-03 14:17:49 -04:00
</Text>
2020-04-27 19:10:42 -04:00
</View>,
);
}
2020-04-27 19:10:42 -04:00
return component;
};
2020-04-27 19:10:42 -04:00
return isLoading ? (
<View style={styles.loading}>
2020-04-27 19:10:42 -04:00
<ActivityIndicator />
</View>
) : (
<SafeBlueArea style={styles.flex}>
<ScrollView contentContainerStyle={styles.scrollViewContent} testID="PleaseBackupScrollView">
<View style={styles.please}>
<BlueText style={styles.successText}>{loc.pleasebackup.success}</BlueText>
<BlueText style={styles.pleaseText}>{loc.pleasebackup.text}</BlueText>
2019-11-02 21:58:55 +01:00
<View style={styles.secret}>{renderSecret()}</View>
2019-11-02 21:58:55 +01:00
<View style={styles.ok}>
<View style={styles.flex}>
2020-04-27 19:10:42 -04:00
<BlueSpacing20 />
2020-05-27 14:12:17 +03:00
<BlueButton testID="PleasebackupOk" onPress={handleBackButton} title={loc.pleasebackup.ok} />
</View>
</View>
2020-04-27 19:10:42 -04:00
</View>
</ScrollView>
</SafeBlueArea>
);
};
2020-04-27 19:10:42 -04:00
PleaseBackup.navigationOptions = ({ navigation }) => ({
...BlueNavigationStyle(navigation, true),
title: loc.pleasebackup.title,
headerLeft: null,
headerRight: null,
gestureEnabled: false,
swipeEnabled: false,
2020-04-27 19:10:42 -04:00
});
export default PleaseBackup;