BlueWallet/screen/wallets/export.js

149 lines
4 KiB
JavaScript
Raw Normal View History

2018-01-30 22:42:38 +00:00
import React, { Component } from 'react';
import { Dimensions, ScrollView, ActivityIndicator, View, StyleSheet } from 'react-native';
2019-02-14 00:15:56 -05:00
import QRCode from 'react-native-qrcode-svg';
import { BlueSpacing20, SafeBlueArea, BlueNavigationStyle, BlueText, BlueCopyTextToClipboard, BlueCard } from '../../BlueComponents';
2018-03-18 02:48:23 +00:00
import PropTypes from 'prop-types';
import Privacy from '../../Privacy';
import Biometric from '../../class/biometrics';
import { LegacyWallet, LightningCustodianWallet, SegwitBech32Wallet, SegwitP2SHWallet, WatchOnlyWallet } from '../../class';
2018-03-18 02:48:23 +00:00
/** @type {AppStorage} */
let BlueApp = require('../../BlueApp');
2018-05-28 20:18:11 +01:00
let loc = require('../../loc');
2018-06-28 23:17:14 +01:00
const { height, width } = Dimensions.get('window');
2018-01-30 22:42:38 +00:00
const styles = StyleSheet.create({
loading: {
flex: 1,
paddingTop: 20,
},
root: {
flex: 1,
},
scrollViewContent: {
alignItems: 'center',
justifyContent: 'center',
flexGrow: 1,
},
type: {
fontSize: 17,
fontWeight: '700',
color: '#0c2550',
},
secret: {
alignItems: 'center',
paddingHorizontal: 16,
fontSize: 16,
color: '#0C2550',
lineHeight: 24,
},
});
2018-01-30 22:42:38 +00:00
export default class WalletExport extends Component {
static navigationOptions = ({ navigation }) => ({
...BlueNavigationStyle(navigation, true),
title: loc.wallets.export.title,
headerLeft: null,
});
2018-01-30 22:42:38 +00:00
constructor(props) {
super(props);
2020-05-27 14:12:17 +03:00
let wallet = props.route.params.wallet;
2018-01-30 22:42:38 +00:00
this.state = {
isLoading: true,
2019-01-10 14:58:22 +00:00
qrCodeHeight: height > width ? width - 40 : width / 2,
2018-03-17 22:39:21 +02:00
wallet,
};
2018-01-30 22:42:38 +00:00
}
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();
},
);
2018-01-30 22:42:38 +00:00
}
async componentWillUnmount() {
Privacy.disableBlur();
}
2019-01-06 14:28:02 -05:00
onLayout = () => {
const { height } = Dimensions.get('window');
2019-01-10 14:58:22 +00:00
this.setState({ qrCodeHeight: height > width ? width - 40 : width / 2 });
};
2018-01-30 22:42:38 +00:00
render() {
if (this.state.isLoading) {
return (
<View style={styles.loading} onLayout={this.onLayout}>
2018-01-30 22:42:38 +00:00
<ActivityIndicator />
</View>
);
}
return (
<SafeBlueArea style={styles.root}>
<ScrollView contentContainerStyle={styles.scrollViewContent} onLayout={this.onLayout}>
<View>
<BlueText style={styles.type}>{this.state.wallet.typeReadable}</BlueText>
</View>
{(() => {
2020-03-12 17:26:05 +00:00
if ([LegacyWallet.type, SegwitBech32Wallet.type, SegwitP2SHWallet.type].includes(this.state.wallet.type)) {
return (
<BlueCard>
<BlueText>{this.state.wallet.getAddress()}</BlueText>
</BlueCard>
);
}
})()}
2019-01-06 14:28:02 -05:00
<BlueSpacing20 />
<QRCode
value={this.state.wallet.getSecret()}
logo={require('../../img/qr-code.png')}
size={this.state.qrCodeHeight}
logoSize={70}
color={BlueApp.settings.foregroundColor}
logoBackgroundColor={BlueApp.settings.brandingColor}
ecl={'H'}
/>
2019-01-06 14:28:02 -05:00
<BlueSpacing20 />
{this.state.wallet.type === LightningCustodianWallet.type || this.state.wallet.type === WatchOnlyWallet.type ? (
<BlueCopyTextToClipboard text={this.state.wallet.getSecret()} />
) : (
<BlueText style={styles.secret}>{this.state.wallet.getSecret()}</BlueText>
)}
</ScrollView>
2018-01-30 22:42:38 +00:00
</SafeBlueArea>
);
}
}
2018-03-18 02:48:23 +00:00
WalletExport.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
goBack: PropTypes.func,
}),
2020-05-27 14:12:17 +03:00
route: PropTypes.shape({
name: PropTypes.string,
params: PropTypes.shape({
wallet: PropTypes.object.isRequired,
}),
}),
2018-03-18 02:48:23 +00:00
};