BlueWallet/screen/wallets/pleaseBackupLdk.js

83 lines
2.8 KiB
JavaScript
Raw Normal View History

2024-05-31 13:18:01 -04:00
import React, { useCallback, useEffect } from 'react';
2023-10-23 21:28:44 -04:00
import { useNavigation, useRoute } from '@react-navigation/native';
2024-05-20 10:54:13 +01:00
import { BackHandler, ScrollView, StyleSheet, useWindowDimensions, View } from 'react-native';
2021-09-09 12:00:11 +01:00
import QRCode from 'react-native-qrcode-svg';
2024-05-20 10:54:13 +01:00
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 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';
2021-09-09 12:00:11 +01:00
const PleaseBackupLdk = () => {
const { wallets } = useStorage();
2021-09-09 12:00:11 +01:00
const { walletID } = useRoute().params;
/** @type {LightningLdkWallet} */
const wallet = wallets.find(w => w.getID() === walletID);
const navigation = useNavigation();
const { colors } = useTheme();
const { height, width } = useWindowDimensions();
2024-02-20 13:40:16 -04:00
const { enableBlur, disableBlur } = usePrivacy();
2021-09-09 12:00:11 +01:00
const handleBackButton = useCallback(() => {
2023-11-11 07:33:50 -04:00
navigation.getParent().pop();
2021-09-09 12:00:11 +01:00
return true;
}, [navigation]);
const styles = StyleSheet.create({
root: {
flex: 1,
backgroundColor: colors.elevated,
},
scrollViewContent: {
flexGrow: 1,
backgroundColor: colors.elevated,
justifyContent: 'center',
alignItems: 'center',
padding: 20,
},
qrCodeContainer: { borderWidth: 6, borderRadius: 8, borderColor: '#FFFFFF' },
});
useEffect(() => {
2024-02-20 13:40:16 -04:00
enableBlur();
2021-09-09 12:00:11 +01:00
BackHandler.addEventListener('hardwareBackPress', handleBackButton);
return () => {
2024-02-20 13:40:16 -04:00
disableBlur();
2021-09-09 12:00:11 +01:00
BackHandler.removeEventListener('hardwareBackPress', handleBackButton);
};
2024-02-20 13:40:16 -04:00
}, [disableBlur, enableBlur, handleBackButton]);
2021-09-09 12:00:11 +01:00
2023-11-11 07:33:50 -04:00
const pop = () => navigation.getParent().pop();
2021-09-09 12:00:11 +01:00
return (
<SafeArea style={styles.root}>
2021-09-09 12:00:11 +01:00
<ScrollView centerContent contentContainerStyle={styles.scrollViewContent}>
<View>
<BlueTextCentered>Please save this wallet backup. It allows you to restore all your channels on other device.</BlueTextCentered>
<BlueSpacing20 />
</View>
<BlueSpacing20 />
<View style={styles.qrCodeContainer}>
<QRCode
value={wallet.secret}
logo={require('../../img/qr-code.png')}
logoSize={90}
size={height > width ? width - 40 : width / 2}
color="#000000"
logoBackgroundColor={colors.brandingColor}
backgroundColor="#FFFFFF"
ecl="H"
/>
</View>
<CopyTextToClipboard text={wallet.getSecret()} />
2021-09-09 12:00:11 +01:00
<BlueSpacing20 />
2023-11-15 04:40:22 -04:00
<Button onPress={pop} title={loc.pleasebackup.ok_lnd} />
2021-09-09 12:00:11 +01:00
</ScrollView>
</SafeArea>
2021-09-09 12:00:11 +01:00
);
};
export default PleaseBackupLdk;