BlueWallet/screen/wallets/pleaseBackupLNDHub.js

74 lines
2.5 KiB
JavaScript
Raw Normal View History

2023-10-23 21:28:44 -04:00
import { useNavigation, useRoute } from '@react-navigation/native';
2024-05-31 13:18:01 -04:00
import React, { useCallback, useEffect, useState } from 'react';
2024-05-20 10:54:13 +01:00
import { BackHandler, ScrollView, StyleSheet, View } from 'react-native';
import { BlueSpacing20, BlueTextCentered } from '../../BlueComponents';
2023-11-15 04:40:22 -04:00
import Button from '../../components/Button';
2024-05-20 10:54:13 +01:00
import CopyTextToClipboard from '../../components/CopyTextToClipboard';
import QRCodeComponent from '../../components/QRCodeComponent';
import SafeArea from '../../components/SafeArea';
2024-05-20 10:54:13 +01:00
import { useTheme } from '../../components/themes';
2024-02-20 13:40:16 -04:00
import usePrivacy from '../../hooks/usePrivacy';
2024-05-20 10:54:13 +01:00
import loc from '../../loc';
2024-05-31 13:18:01 -04:00
import { useStorage } from '../../hooks/context/useStorage';
const PleaseBackupLNDHub = () => {
const { wallets } = useStorage();
2020-12-02 20:36:48 -05:00
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);
2024-02-20 13:40:16 -04:00
const { enableBlur, disableBlur } = usePrivacy();
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(() => {
2024-02-20 13:40:16 -04:00
enableBlur();
BackHandler.addEventListener('hardwareBackPress', handleBackButton);
return () => {
2024-02-20 13:40:16 -04:00
disableBlur();
BackHandler.removeEventListener('hardwareBackPress', handleBackButton);
};
2024-02-20 13:40:16 -04:00
}, [disableBlur, enableBlur, 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 (
<SafeArea 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} />
<CopyTextToClipboard text={wallet.getSecret()} />
<BlueSpacing20 />
2023-11-15 04:40:22 -04:00
<Button onPress={pop} title={loc.pleasebackup.ok_lnd} />
</ScrollView>
</SafeArea>
);
};
export default PleaseBackupLNDHub;