diff --git a/screen/wallets/export.js b/screen/wallets/export.js index a370fe4b5..bdf40b0ec 100644 --- a/screen/wallets/export.js +++ b/screen/wallets/export.js @@ -1,16 +1,14 @@ -import React, { Component } from 'react'; -import { Dimensions, ScrollView, ActivityIndicator, StatusBar, View, StyleSheet } from 'react-native'; +import React, { useState, useCallback } from 'react'; +import { useWindowDimensions, InteractionManager, ScrollView, ActivityIndicator, StatusBar, View, StyleSheet } from 'react-native'; import QRCode from 'react-native-qrcode-svg'; import { BlueSpacing20, SafeBlueArea, BlueNavigationStyle, BlueText, BlueCopyTextToClipboard, BlueCard } from '../../BlueComponents'; -import PropTypes from 'prop-types'; import Privacy from '../../Privacy'; import Biometric from '../../class/biometrics'; import { LegacyWallet, LightningCustodianWallet, SegwitBech32Wallet, SegwitP2SHWallet, WatchOnlyWallet } from '../../class'; import loc from '../../loc'; -import { BlueCurrentTheme } from '../../components/themes'; +import { useTheme, useNavigation, useFocusEffect, useRoute } from '@react-navigation/native'; /** @type {AppStorage} */ const BlueApp = require('../../BlueApp'); -const { height, width } = Dimensions.get('window'); const styles = StyleSheet.create({ loading: { @@ -19,7 +17,6 @@ const styles = StyleSheet.create({ }, root: { flex: 1, - backgroundColor: BlueCurrentTheme.colors.elevated, }, scrollViewContent: { alignItems: 'center', @@ -30,123 +27,109 @@ const styles = StyleSheet.create({ type: { fontSize: 17, fontWeight: '700', - color: BlueCurrentTheme.colors.foregroundColor, }, secret: { alignItems: 'center', paddingHorizontal: 16, fontSize: 16, - color: BlueCurrentTheme.colors.foregroundColor, lineHeight: 24, }, }); -export default class WalletExport extends Component { - constructor(props) { - super(props); - const wallet = props.route.params.wallet; - this.state = { - isLoading: true, - qrCodeHeight: height > width ? width - 40 : width / 2, - wallet, - }; - } - - async componentDidMount() { - Privacy.enableBlur(); - const isBiometricsEnabled = await Biometric.isBiometricUseCapableAndEnabled(); - - if (isBiometricsEnabled) { - if (!(await Biometric.unlockWithBiometrics())) { - return this.props.navigation.goBack(); - } - } - - this.setState( - { - isLoading: false, - }, - () => { - this.state.wallet.setUserHasSavedExport(true); - BlueApp.saveToDisk(); - }, - ); - } - - async componentWillUnmount() { - Privacy.disableBlur(); - } - - onLayout = () => { - const { height } = Dimensions.get('window'); - this.setState({ qrCodeHeight: height > width ? width - 40 : width / 2 }); +const WalletExport = () => { + const { wallet } = useRoute().params; + const [isLoading, setIsLoading] = useState(true); + const { goBack } = useNavigation(); + const { colors } = useTheme(); + const { width, height } = useWindowDimensions(); + const stylesHook = { + ...styles, + loading: { + ...styles.loading, + backgroundColor: colors.elevated, + }, + root: { + ...styles.root, + backgroundColor: colors.elevated, + }, + type: { ...styles.type, color: colors.foregroundColor }, + secret: { ...styles.secret, color: colors.foregroundColor }, }; - render() { - if (this.state.isLoading) { - return ( - - - - ); - } + useFocusEffect( + useCallback(() => { + Privacy.enableBlur(); + const task = InteractionManager.runAfterInteractions(async () => { + if (wallet) { + const isBiometricsEnabled = await Biometric.isBiometricUseCapableAndEnabled(); - return ( - - - - - {this.state.wallet.typeReadable} - - - {(() => { - if ([LegacyWallet.type, SegwitBech32Wallet.type, SegwitP2SHWallet.type].includes(this.state.wallet.type)) { - return ( - - {this.state.wallet.getAddress()} - - ); + if (isBiometricsEnabled) { + if (!(await Biometric.unlockWithBiometrics())) { + return goBack(); } - })()} - - - - - - {this.state.wallet.type === LightningCustodianWallet.type || this.state.wallet.type === WatchOnlyWallet.type ? ( - - ) : ( - {this.state.wallet.getSecret()} - )} - - - ); - } -} + } -WalletExport.propTypes = { - navigation: PropTypes.shape({ - navigate: PropTypes.func, - goBack: PropTypes.func, - }), - route: PropTypes.shape({ - name: PropTypes.string, - params: PropTypes.shape({ - wallet: PropTypes.object.isRequired, - }), - }), + setIsLoading(false); + } + }); + return () => { + task.cancel(); + Privacy.disableBlur(); + wallet.setUserHasSavedExport(true); + BlueApp.saveToDisk(); + }; + }, [goBack, wallet]), + ); + + return isLoading ? ( + + + + ) : ( + + + + + {wallet.typeReadable} + + + {(() => { + if ([LegacyWallet.type, SegwitBech32Wallet.type, SegwitP2SHWallet.type].includes(wallet.type)) { + return ( + + {wallet.getAddress()} + + ); + } + })()} + + + width ? width - 40 : width / 2} + logoSize={70} + color="#000000" + logoBackgroundColor={colors.brandingColor} + backgroundColor="#FFFFFF" + ecl="H" + /> + + + {wallet.type === LightningCustodianWallet.type || wallet.type === WatchOnlyWallet.type ? ( + + ) : ( + {wallet.getSecret()} + )} + + + ); }; + WalletExport.navigationOptions = ({ navigation }) => ({ ...BlueNavigationStyle(navigation, true), title: loc.wallets.export_title, headerLeft: null, }); + +export default WalletExport; diff --git a/screen/wallets/xpub.js b/screen/wallets/xpub.js index 7e7b5e770..cad790e26 100644 --- a/screen/wallets/xpub.js +++ b/screen/wallets/xpub.js @@ -5,7 +5,6 @@ import { BlueSpacing20, SafeBlueArea, BlueText, BlueNavigationStyle, BlueCopyTex import Privacy from '../../Privacy'; import Biometric from '../../class/biometrics'; import loc from '../../loc'; -import { BlueCurrentTheme } from '../../components/themes'; import { useFocusEffect, useRoute, useNavigation, useTheme } from '@react-navigation/native'; /** @type {AppStorage} */ const BlueApp = require('../../BlueApp'); @@ -14,7 +13,6 @@ const styles = StyleSheet.create({ root: { flex: 1, paddingTop: 20, - backgroundColor: BlueCurrentTheme.colors.elevated, }, container: { alignItems: 'center',