BlueWallet/screen/wallets/export.js

123 lines
3.8 KiB
JavaScript
Raw Normal View History

2018-01-30 23:42:38 +01:00
import React, { Component } from 'react';
import { Dimensions, ScrollView, ActivityIndicator, View } from 'react-native';
2019-02-14 06:15:56 +01:00
import QRCode from 'react-native-qrcode-svg';
import { BlueSpacing20, SafeBlueArea, BlueNavigationStyle, BlueText, BlueCopyTextToClipboard, BlueCard } from '../../BlueComponents';
2018-03-18 03:48:23 +01: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 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 {
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
}
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 23:42:38 +01:00
}
async componentWillUnmount() {
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-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 (
<SafeBlueArea style={{ flex: 1 }}>
2020-03-26 23:51:56 +01:00
<ScrollView contentContainerStyle={{ alignItems: 'center', justifyContent: 'center', flexGrow: 1 }} onLayout={this.onLayout}>
<View>
2020-03-26 23:51:56 +01:00
<BlueText style={{ fontSize: 17, fontWeight: '700', color: '#0c2550' }}>{this.state.wallet.typeReadable}</BlueText>
</View>
{(() => {
2020-03-12 18:26:05 +01: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 20:28:02 +01: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 20:28:02 +01:00
<BlueSpacing20 />
{this.state.wallet.type === LightningCustodianWallet.type || this.state.wallet.type === WatchOnlyWallet.type ? (
<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>
)}
</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,
}),
};