2018-12-27 16:37:12 +01:00
|
|
|
import React, { Component } from 'react';
|
2019-02-15 00:15:38 +01:00
|
|
|
import { Dimensions, ActivityIndicator, View } from 'react-native';
|
2019-02-14 06:15:56 +01:00
|
|
|
import QRCode from 'react-native-qrcode-svg';
|
2019-01-21 14:55:39 +01:00
|
|
|
import { BlueSpacing20, SafeBlueArea, BlueText, BlueNavigationStyle, BlueCopyTextToClipboard } from '../../BlueComponents';
|
2018-12-27 16:37:12 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2019-02-28 02:29:13 +01:00
|
|
|
import Privacy from '../../Privacy';
|
2019-09-25 05:42:21 +02:00
|
|
|
import Biometric from '../../class/biometrics';
|
2018-12-27 16:37:12 +01:00
|
|
|
/** @type {AppStorage} */
|
|
|
|
let BlueApp = require('../../BlueApp');
|
|
|
|
let loc = require('../../loc');
|
|
|
|
const { height, width } = Dimensions.get('window');
|
|
|
|
|
|
|
|
export default class WalletXpub extends Component {
|
2018-12-28 00:33:39 +01:00
|
|
|
static navigationOptions = ({ navigation }) => ({
|
|
|
|
...BlueNavigationStyle(navigation, true),
|
|
|
|
title: loc.wallets.xpub.title,
|
|
|
|
headerLeft: null,
|
|
|
|
});
|
2018-12-27 16:37:12 +01:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
let secret = props.navigation.state.params.secret;
|
|
|
|
let wallet;
|
|
|
|
|
|
|
|
for (let w of BlueApp.getWallets()) {
|
|
|
|
if (w.getSecret() === secret) {
|
|
|
|
// found our wallet
|
|
|
|
wallet = w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
isLoading: true,
|
|
|
|
wallet,
|
|
|
|
xpub: wallet.getXpub(),
|
2018-12-27 19:29:02 +01:00
|
|
|
xpubText: wallet.getXpub(),
|
2019-01-10 15:58:22 +01:00
|
|
|
qrCodeHeight: height > width ? width - 40 : width / 2,
|
2018-12-27 16:37:12 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount() {
|
2019-02-28 02:29:13 +01:00
|
|
|
Privacy.enableBlur();
|
2019-09-25 05:42:21 +02:00
|
|
|
const isBiometricsEnabled = await Biometric.isBiometricUseCapableAndEnabled();
|
|
|
|
|
|
|
|
if (isBiometricsEnabled) {
|
|
|
|
if (!(await Biometric.unlockWithBiometrics())) {
|
|
|
|
return this.props.navigation.goBack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-27 16:37:12 +01:00
|
|
|
this.setState({
|
|
|
|
isLoading: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-25 08:13:41 +02:00
|
|
|
async componentWillUnmount() {
|
2019-02-28 02:29:13 +01:00
|
|
|
Privacy.disableBlur();
|
|
|
|
}
|
|
|
|
|
2019-01-06 20:28:02 +01:00
|
|
|
onLayout = () => {
|
|
|
|
const { height } = Dimensions.get('window');
|
2019-01-10 15:58:22 +01:00
|
|
|
this.setState({ qrCodeHeight: height > width ? width - 40 : width / 2 });
|
2019-01-06 20:28:02 +01:00
|
|
|
};
|
|
|
|
|
2018-12-27 16:37:12 +01:00
|
|
|
render() {
|
|
|
|
if (this.state.isLoading) {
|
|
|
|
return (
|
|
|
|
<View style={{ flex: 1, paddingTop: 20 }}>
|
|
|
|
<ActivityIndicator />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<SafeBlueArea style={{ flex: 1, paddingTop: 20 }}>
|
2019-01-06 20:28:02 +01:00
|
|
|
<View style={{ alignItems: 'center', flex: 1, justifyContent: 'center' }} onLayout={this.onLayout}>
|
2018-12-27 16:37:12 +01:00
|
|
|
<View>
|
2018-12-28 16:52:06 +01:00
|
|
|
<BlueText>{this.state.wallet.typeReadable}</BlueText>
|
2018-12-27 16:37:12 +01:00
|
|
|
</View>
|
2019-01-06 20:28:02 +01:00
|
|
|
<BlueSpacing20 />
|
2018-12-27 16:37:12 +01:00
|
|
|
|
2019-05-19 21:49:42 +02:00
|
|
|
<QRCode
|
|
|
|
value={this.state.xpub}
|
|
|
|
logo={require('../../img/qr-code.png')}
|
|
|
|
size={this.state.qrCodeHeight}
|
|
|
|
logoSize={90}
|
|
|
|
color={BlueApp.settings.foregroundColor}
|
|
|
|
logoBackgroundColor={BlueApp.settings.brandingColor}
|
|
|
|
ecl={'H'}
|
|
|
|
/>
|
|
|
|
|
2019-01-06 20:28:02 +01:00
|
|
|
<BlueSpacing20 />
|
2019-01-21 14:55:39 +01:00
|
|
|
<BlueCopyTextToClipboard text={this.state.xpubText} />
|
2019-01-06 20:28:02 +01:00
|
|
|
</View>
|
2018-12-27 16:37:12 +01:00
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WalletXpub.propTypes = {
|
|
|
|
navigation: PropTypes.shape({
|
|
|
|
state: PropTypes.shape({
|
|
|
|
params: PropTypes.shape({
|
|
|
|
secret: PropTypes.string,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
navigate: PropTypes.func,
|
|
|
|
goBack: PropTypes.func,
|
|
|
|
}),
|
|
|
|
};
|