BlueWallet/screen/wallets/pleaseBackupLNDHub.js

98 lines
3.3 KiB
JavaScript
Raw Normal View History

2021-02-03 18:49:31 +01:00
import React, { useCallback, useContext, useEffect, useState } from 'react';
2020-07-15 19:32:59 +02:00
import { useNavigation, useRoute, useTheme } from '@react-navigation/native';
2021-02-03 18:49:31 +01:00
import { View, StyleSheet, BackHandler, StatusBar } from 'react-native';
import QRCode from 'react-native-qrcode-svg';
2020-12-04 14:39:47 +01:00
import { ScrollView } from 'react-native-gesture-handler';
2020-12-25 17:09:53 +01:00
2021-01-05 19:55:22 +01:00
import { BlueButton, BlueCopyTextToClipboard, BlueSpacing20, BlueText, BlueTextCentered, SafeBlueArea } from '../../BlueComponents';
2020-12-25 17:09:53 +01:00
import navigationStyle from '../../components/navigationStyle';
2021-01-19 04:44:55 +01:00
import Privacy from '../../blue_modules/Privacy';
2020-07-20 15:38:46 +02:00
import loc from '../../loc';
2020-12-03 02:36:48 +01:00
import { BlueStorageContext } from '../../blue_modules/storage-context';
2020-12-29 17:44:57 +01:00
import { LightningCustodianWallet } from '../../class';
const PleaseBackupLNDHub = () => {
2020-12-03 02:36:48 +01:00
const { wallets } = useContext(BlueStorageContext);
const { walletID } = useRoute().params;
const wallet = wallets.find(w => w.getID() === walletID);
const navigation = useNavigation();
2020-07-15 19:32:59 +02:00
const { colors } = useTheme();
2021-02-03 18:49:31 +01:00
const [qrCodeSize, setQRCodeSize] = useState(90);
const handleBackButton = useCallback(() => {
navigation.dangerouslyGetParent().pop();
return true;
}, [navigation]);
2020-07-15 19:32:59 +02:00
const styles = StyleSheet.create({
root: {
flex: 1,
backgroundColor: colors.elevated,
},
scrollViewContent: {
flexGrow: 1,
backgroundColor: colors.elevated,
justifyContent: 'center',
alignItems: 'center',
padding: 20,
2020-07-15 19:32:59 +02:00
},
2020-08-03 19:26:16 +02:00
qrCodeContainer: { borderWidth: 6, borderRadius: 8, borderColor: '#FFFFFF' },
2020-07-15 19:32:59 +02:00
});
useEffect(() => {
Privacy.enableBlur();
BackHandler.addEventListener('hardwareBackPress', handleBackButton);
return () => {
Privacy.disableBlur();
BackHandler.removeEventListener('hardwareBackPress', handleBackButton);
};
}, [handleBackButton]);
const pop = () => navigation.dangerouslyGetParent().pop();
2021-02-03 18:49:31 +01:00
const onLayout = e => {
2021-02-25 02:49:14 +01:00
const { height, width } = e.nativeEvent.layout;
setQRCodeSize(height > width ? width - 40 : e.nativeEvent.layout.width / 1.5);
2021-02-03 18:49:31 +01:00
};
return (
2021-02-03 18:49:31 +01:00
<SafeBlueArea style={styles.root} onLayout={onLayout}>
2021-01-03 17:44:01 +01:00
<StatusBar barStyle="light-content" />
<ScrollView centerContent contentContainerStyle={styles.scrollViewContent}>
<View>
<BlueTextCentered>{loc.pleasebackup.text_lnd}</BlueTextCentered>
2020-12-29 16:01:38 +01:00
<BlueSpacing20 />
2021-01-04 17:13:45 +01:00
{wallet.getBaseURI() === LightningCustodianWallet.defaultBaseUri && <BlueText>- {loc.pleasebackup.text_lnd2}</BlueText>}
</View>
<BlueSpacing20 />
<View style={styles.qrCodeContainer}>
<QRCode
value={wallet.secret}
logo={require('../../img/qr-code.png')}
logoSize={90}
color="#000000"
logoBackgroundColor={colors.brandingColor}
backgroundColor="#FFFFFF"
ecl="H"
2021-02-03 18:49:31 +01:00
size={qrCodeSize}
/>
</View>
2021-01-13 18:48:46 +01:00
<BlueCopyTextToClipboard text={wallet.getSecret()} />
<BlueSpacing20 />
<BlueButton onPress={pop} title={loc.pleasebackup.ok_lnd} />
</ScrollView>
</SafeBlueArea>
);
};
2021-02-15 09:03:54 +01:00
PleaseBackupLNDHub.navigationOptions = navigationStyle(
{
closeButton: true,
headerLeft: null,
headerRight: null,
gestureEnabled: false,
swipeEnabled: false,
},
opts => ({ ...opts, title: loc.pleasebackup.title }),
);
export default PleaseBackupLNDHub;