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