import React, { useEffect, useState, useCallback, useContext } from 'react'; import { ActivityIndicator, View, BackHandler, Text, ScrollView, StyleSheet, StatusBar } from 'react-native'; import { useNavigation, useRoute, useTheme } from '@react-navigation/native'; import { BlueSpacing20, SafeBlueArea, BlueNavigationStyle, BlueText, BlueButton } from '../../BlueComponents'; import Privacy from '../../Privacy'; import loc from '../../loc'; import { BlueStorageContext } from '../../blue_modules/storage-context'; const PleaseBackup = () => { const { wallets } = useContext(BlueStorageContext); const [isLoading, setIsLoading] = useState(true); const { walletID } = useRoute().params; const wallet = wallets.find(w => w.getID() === walletID); const navigation = useNavigation(); const { colors } = useTheme(); const stylesHook = StyleSheet.create({ flex: { backgroundColor: colors.elevated, }, word: { backgroundColor: colors.inputBackgroundColor, }, wortText: { color: colors.labelText, }, successText: { color: colors.foregroundColor, }, pleaseText: { color: colors.foregroundColor, }, }); const handleBackButton = useCallback(() => { navigation.dangerouslyGetParent().pop(); return true; }, [navigation]); useEffect(() => { Privacy.enableBlur(); setIsLoading(false); BackHandler.addEventListener('hardwareBackPress', handleBackButton); return () => { Privacy.disableBlur(); BackHandler.removeEventListener('hardwareBackPress', handleBackButton); }; // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const renderSecret = () => { const component = []; for (const [index, secret] of wallet.getSecret().split(/\s/).entries()) { const text = `${index + 1}. ${secret} `; component.push( {text} , ); } return component; }; return isLoading ? ( ) : ( {loc.pleasebackup.success} {loc.pleasebackup.text} {renderSecret()} ); }; PleaseBackup.navigationOptions = ({ navigation }) => ({ ...BlueNavigationStyle(navigation, true), title: loc.pleasebackup.title, headerLeft: null, headerRight: null, gestureEnabled: false, swipeEnabled: false, }); const styles = StyleSheet.create({ flex: { flex: 1, }, loading: { flex: 1, paddingTop: 20, }, word: { marginRight: 8, marginBottom: 8, paddingTop: 6, paddingBottom: 6, paddingLeft: 8, paddingRight: 8, borderRadius: 4, }, wortText: { fontWeight: 'bold', textAlign: 'left', }, please: { alignItems: 'center', paddingHorizontal: 16, }, successText: { textAlign: 'center', fontWeight: 'bold', }, pleaseText: { paddingBottom: 10, paddingRight: 0, paddingLeft: 0, }, secret: { flexDirection: 'row', justifyContent: 'center', flexWrap: 'wrap', marginTop: 14, }, }); export default PleaseBackup;