BlueWallet/screen/wallets/export.js

113 lines
3 KiB
JavaScript
Raw Normal View History

2018-01-30 22:42:38 +00:00
import React, { Component } from 'react';
2019-02-14 18:15:38 -05:00
import { Dimensions, ActivityIndicator, View } from 'react-native';
2019-02-14 00:15:56 -05:00
import QRCode from 'react-native-qrcode-svg';
2019-01-06 14:28:02 -05:00
import { BlueSpacing20, SafeBlueArea, BlueNavigationStyle, BlueText } from '../../BlueComponents';
2018-03-18 02:48:23 +00:00
import PropTypes from 'prop-types';
import Privacy from '../../Privacy';
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
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);
2018-03-17 22:39:21 +02:00
let address = props.navigation.state.params.address;
let secret = props.navigation.state.params.secret;
2018-03-17 22:39:21 +02:00
let wallet;
for (let w of BlueApp.getWallets()) {
if ((address && w.getAddress() === address) || w.getSecret() === secret) {
2018-03-17 22:39:21 +02:00
// found our wallet
wallet = w;
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
}
2019-01-06 14:28:02 -05:00
componentDidMount() {
Privacy.enableBlur();
2018-01-30 22:42:38 +00:00
this.setState({
isLoading: false,
2018-03-17 22:39:21 +02:00
});
2018-01-30 22:42:38 +00:00
}
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 (
2019-01-06 14:28:02 -05:00
<View style={{ flex: 1, paddingTop: 20 }} onLayout={this.onLayout}>
2018-01-30 22:42:38 +00:00
<ActivityIndicator />
</View>
);
}
return (
2018-03-17 22:39:21 +02:00
<SafeBlueArea style={{ flex: 1, paddingTop: 20 }}>
2019-01-06 14:28:02 -05:00
<View style={{ alignItems: 'center', flex: 1, justifyContent: 'center', paddingHorizontal: 0 }} onLayout={this.onLayout}>
<View>
<BlueText>{this.state.wallet.typeReadable}</BlueText>
</View>
{(() => {
if (this.state.wallet.getAddress()) {
return (
<View>
<BlueText>{this.state.wallet.getAddress()}</BlueText>
</View>
);
}
})()}
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={90}
color={BlueApp.settings.foregroundColor}
logoBackgroundColor={BlueApp.settings.brandingColor}
ecl={'H'}
/>
2019-01-06 14:28:02 -05:00
<BlueSpacing20 />
2019-01-06 14:28:02 -05:00
<BlueText style={{ alignItems: 'center', paddingHorizontal: 8 }}>{this.state.wallet.getSecret()}</BlueText>
</View>
2018-01-30 22:42:38 +00:00
</SafeBlueArea>
);
}
}
2018-03-18 02:48:23 +00:00
WalletExport.propTypes = {
navigation: PropTypes.shape({
state: PropTypes.shape({
params: PropTypes.shape({
address: PropTypes.string,
secret: PropTypes.string,
2018-03-18 02:48:23 +00:00
}),
}),
navigate: PropTypes.func,
goBack: PropTypes.func,
}),
};