BlueWallet/screen/wallets/pleaseBackup.js

139 lines
3.8 KiB
JavaScript
Raw Normal View History

2020-10-29 10:26:39 +01:00
import React, { useEffect, useState, useCallback, useContext } from 'react';
2020-06-24 05:17:27 +02:00
import { ActivityIndicator, View, BackHandler, Text, ScrollView, StyleSheet, StatusBar } from 'react-native';
2020-07-15 19:32:59 +02:00
import { useNavigation, useRoute, useTheme } from '@react-navigation/native';
2020-12-04 14:39:47 +01:00
import { BlueSpacing20, SafeBlueArea, BlueNavigationStyle, BlueText, BlueButton } from '../../BlueComponents';
import Privacy from '../../Privacy';
2020-07-20 15:38:46 +02:00
import loc from '../../loc';
2020-10-29 10:26:39 +01:00
import { BlueStorageContext } from '../../blue_modules/storage-context';
2020-04-28 01:10:42 +02:00
const PleaseBackup = () => {
2020-10-29 10:26:39 +01:00
const { wallets } = useContext(BlueStorageContext);
2020-04-28 01:10:42 +02:00
const [isLoading, setIsLoading] = useState(true);
2020-10-29 10:26:39 +01:00
const { walletID } = useRoute().params;
const wallet = wallets.find(w => w.getID() === walletID);
2020-05-27 13:12:17 +02:00
const navigation = useNavigation();
2020-07-15 19:32:59 +02:00
const { colors } = useTheme();
2020-10-29 10:26:39 +01:00
const stylesHook = StyleSheet.create({
2020-07-15 19:32:59 +02:00
flex: {
backgroundColor: colors.elevated,
},
word: {
backgroundColor: colors.inputBackgroundColor,
},
wortText: {
color: colors.labelText,
},
2020-10-29 10:26:39 +01:00
2020-07-15 19:32:59 +02:00
successText: {
color: colors.foregroundColor,
},
pleaseText: {
color: colors.foregroundColor,
},
});
2020-04-28 01:10:42 +02:00
const handleBackButton = useCallback(() => {
2020-05-27 13:12:17 +02:00
navigation.dangerouslyGetParent().pop();
return true;
2020-05-27 13:12:17 +02:00
}, [navigation]);
2020-04-28 01:10:42 +02:00
useEffect(() => {
Privacy.enableBlur();
2020-04-28 01:10:42 +02:00
setIsLoading(false);
BackHandler.addEventListener('hardwareBackPress', handleBackButton);
2020-04-28 01:10:42 +02:00
return () => {
Privacy.disableBlur();
BackHandler.removeEventListener('hardwareBackPress', handleBackButton);
};
2020-10-29 10:26:39 +01:00
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
2020-04-28 01:10:42 +02:00
const renderSecret = () => {
const component = [];
2020-10-29 10:26:39 +01:00
for (const [index, secret] of wallet.getSecret().split(/\s/).entries()) {
const text = `${index + 1}. ${secret} `;
2020-04-28 01:10:42 +02:00
component.push(
2020-10-29 10:26:39 +01:00
<View style={[styles.word, stylesHook.word]} key={`${index}`}>
<Text style={[styles.wortText, stylesHook.wortText]} textBreakStrategy="simple">
{text}
2020-05-03 20:17:49 +02:00
</Text>
2020-04-28 01:10:42 +02:00
</View>,
);
}
2020-04-28 01:10:42 +02:00
return component;
};
2020-04-28 01:10:42 +02:00
return isLoading ? (
<View style={[styles.loading, stylesHook.flex]}>
2020-04-28 01:10:42 +02:00
<ActivityIndicator />
</View>
) : (
2020-10-29 10:26:39 +01:00
<SafeBlueArea style={[styles.flex, stylesHook.flex]}>
2020-07-15 19:32:59 +02:00
<StatusBar barStyle="default" />
2020-10-29 10:26:39 +01:00
<ScrollView testID="PleaseBackupScrollView">
<View style={styles.please}>
2020-10-29 10:26:39 +01:00
<BlueText style={[styles.successText, stylesHook.successText]}>{loc.pleasebackup.success}</BlueText>
<BlueText style={[styles.pleaseText, stylesHook.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
<BlueSpacing20 />
<BlueButton testID="PleasebackupOk" onPress={handleBackButton} title={loc.pleasebackup.ok} />
2020-04-28 01:10:42 +02:00
</View>
</ScrollView>
</SafeBlueArea>
);
};
2020-04-28 01:10:42 +02:00
2020-12-04 14:39:47 +01:00
PleaseBackup.navigationOptions = ({ navigation }) => ({
...BlueNavigationStyle(navigation, true),
2020-04-28 01:10:42 +02:00
title: loc.pleasebackup.title,
headerLeft: null,
headerRight: null,
gestureEnabled: false,
swipeEnabled: false,
2020-04-28 01:10:42 +02:00
});
2020-10-29 10:26:39 +01:00
const styles = StyleSheet.create({
flex: {
flex: 1,
},
loading: {
flex: 1,
justifyContent: 'center',
2020-10-29 10:26:39 +01:00
},
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,
},
});
2020-04-28 01:10:42 +02:00
export default PleaseBackup;