BlueWallet/screen/wallets/pleaseBackupLNDHub.js

81 lines
2.7 KiB
JavaScript
Raw Normal View History

2021-02-03 12:49:31 -05:00
import React, { useCallback, useContext, useEffect, useState } from 'react';
2023-10-23 21:28:44 -04:00
import { useNavigation, useRoute } from '@react-navigation/native';
2021-09-27 12:40:58 -04:00
import { View, StyleSheet, ScrollView, BackHandler } from 'react-native';
2020-12-25 19:09:53 +03:00
2023-11-15 04:40:22 -04:00
import { BlueCopyTextToClipboard, BlueSpacing20, BlueTextCentered, SafeBlueArea } from '../../BlueComponents';
2020-12-25 19:09:53 +03:00
import navigationStyle from '../../components/navigationStyle';
2021-01-18 22:44:55 -05:00
import Privacy from '../../blue_modules/Privacy';
2020-07-20 16:38:46 +03:00
import loc from '../../loc';
2020-12-02 20:36:48 -05:00
import { BlueStorageContext } from '../../blue_modules/storage-context';
2021-08-26 21:31:36 -04:00
import QRCodeComponent from '../../components/QRCodeComponent';
2023-10-23 21:28:44 -04:00
import { useTheme } from '../../components/themes';
2023-11-15 04:40:22 -04:00
import Button from '../../components/Button';
const PleaseBackupLNDHub = () => {
2020-12-02 20:36:48 -05:00
const { wallets } = useContext(BlueStorageContext);
const { walletID } = useRoute().params;
const wallet = wallets.find(w => w.getID() === walletID);
const navigation = useNavigation();
2020-07-15 13:32:59 -04:00
const { colors } = useTheme();
2021-02-03 12:49:31 -05:00
const [qrCodeSize, setQRCodeSize] = useState(90);
const handleBackButton = useCallback(() => {
2023-11-11 07:33:50 -04:00
navigation.getParent().pop();
return true;
}, [navigation]);
2020-07-15 13:32:59 -04:00
const styles = StyleSheet.create({
root: {
backgroundColor: colors.elevated,
},
scrollViewContent: {
flexGrow: 1,
backgroundColor: colors.elevated,
justifyContent: 'center',
alignItems: 'center',
padding: 20,
2020-07-15 13:32:59 -04:00
},
});
useEffect(() => {
Privacy.enableBlur();
BackHandler.addEventListener('hardwareBackPress', handleBackButton);
return () => {
Privacy.disableBlur();
BackHandler.removeEventListener('hardwareBackPress', handleBackButton);
};
}, [handleBackButton]);
2023-11-11 07:33:50 -04:00
const pop = () => navigation.getParent().pop();
2021-02-03 12:49:31 -05:00
const onLayout = e => {
2021-02-24 20:49:14 -05:00
const { height, width } = e.nativeEvent.layout;
setQRCodeSize(height > width ? width - 40 : e.nativeEvent.layout.width / 1.5);
2021-02-03 12:49:31 -05:00
};
return (
2021-02-03 12:49:31 -05:00
<SafeBlueArea style={styles.root} onLayout={onLayout}>
<ScrollView centerContent contentContainerStyle={styles.scrollViewContent}>
<View>
<BlueTextCentered>{loc.pleasebackup.text_lnd}</BlueTextCentered>
2020-12-29 15:01:38 +00:00
<BlueSpacing20 />
</View>
<BlueSpacing20 />
2021-08-26 21:31:36 -04:00
<QRCodeComponent value={wallet.getSecret()} size={qrCodeSize} />
2021-01-13 12:48:46 -05:00
<BlueCopyTextToClipboard text={wallet.getSecret()} />
<BlueSpacing20 />
2023-11-15 04:40:22 -04:00
<Button onPress={pop} title={loc.pleasebackup.ok_lnd} />
</ScrollView>
</SafeBlueArea>
);
};
2021-02-15 11:03:54 +03:00
PleaseBackupLNDHub.navigationOptions = navigationStyle(
{
gestureEnabled: false,
swipeEnabled: false,
2023-11-11 07:33:50 -04:00
headerBackVisible: false,
2021-02-15 11:03:54 +03:00
},
2021-09-14 01:36:00 -04:00
opts => ({ ...opts, headerTitle: loc.pleasebackup.title }),
2021-02-15 11:03:54 +03:00
);
export default PleaseBackupLNDHub;