import React, {createRef} from 'react'; import {Clipboard, Text, View} from 'react-native'; import QRCode from 'react-native-qrcode-svg'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import RNFetchBlob from 'rn-fetch-blob'; import {LOGO_BASE64} from '../../assets/images/assets'; import {eSubscribeEvent, eUnSubscribeEvent, ToastEvent} from '../../services/EventManager'; import {eOpenRecoveryKeyDialog} from '../../utils/Events'; import {dWidth} from '../../utils'; import ActionSheet from '../ActionSheet'; import {Button} from '../Button'; import Seperator from '../Seperator'; import {Toast} from '../Toast'; import {SIZE, WEIGHT} from "../../utils/SizeUtils"; import {db} from "../../utils/DB"; class RecoveryKeyDialog extends React.Component { constructor(props) { super(props); this.state = { key: null, }; this.actionSheetRef = createRef(); this.svg = createRef(); } open = () => { this.actionSheetRef.current?._setModalVisible(true); }; close = () => { this.actionSheetRef.current?._setModalVisible(false); }; async componentDidMount() { eSubscribeEvent(eOpenRecoveryKeyDialog, this.open); let k = await db.user.key(); if (k) { this.setState({ key: k.key, }); } } async componentWillUnmount() { eUnSubscribeEvent(eOpenRecoveryKeyDialog, this.open); } componentDidUpdate() {} saveQRCODE = () => { this.svg.current?.toDataURL((data) => { RNFetchBlob.fs .writeFile( RNFetchBlob.fs.dirs.SDCardDir + '/Notesnook/nn_recovery_key_qrcode.png', data, 'base64', ) .then((res) => { RNFetchBlob.fs .scanFile([ { path: RNFetchBlob.fs.dirs.SDCardDir + '/Notesnook/nn_recovery_key_qrcode.png', mime: 'image/png', }, ]) .then((r) => { ToastEvent.show( 'Recovery key saved to Gallery as ' + RNFetchBlob.fs.dirs.SDCardDir + '/Notesnook/nn_recovery_key_qrcode.png', 'success', 'local', ); }); }); }); }; render() { const {colors} = this.props; return ( Your Recovery Key {this.state.key} {this.state.key ? ( ) : null}