BlueWallet/screen/wallets/xpub.js

113 lines
2.9 KiB
JavaScript
Raw Normal View History

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';
import PropTypes from 'prop-types';
/** @type {AppStorage} */
let BlueApp = require('../../BlueApp');
let loc = require('../../loc');
const { height, width } = Dimensions.get('window');
export default class WalletXpub extends Component {
static navigationOptions = ({ navigation }) => ({
...BlueNavigationStyle(navigation, true),
title: loc.wallets.xpub.title,
headerLeft: null,
});
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(),
xpubText: wallet.getXpub(),
2019-01-10 15:58:22 +01:00
qrCodeHeight: height > width ? width - 40 : width / 2,
};
}
async componentDidMount() {
this.setState({
isLoading: false,
showQr: false,
});
setTimeout(() => {
this.setState({ showQr: true });
}, 1000);
}
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
};
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}>
<View>
<BlueText>{this.state.wallet.typeReadable}</BlueText>
</View>
2019-01-06 20:28:02 +01:00
<BlueSpacing20 />
{(() => {
if (this.state.showQr) {
2019-02-15 00:15:38 +01:00
return (
<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'}
/>
);
} else {
return (
<View>
<ActivityIndicator />
</View>
);
}
})()}
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>
</SafeBlueArea>
);
}
}
WalletXpub.propTypes = {
navigation: PropTypes.shape({
state: PropTypes.shape({
params: PropTypes.shape({
secret: PropTypes.string,
}),
}),
navigate: PropTypes.func,
goBack: PropTypes.func,
}),
};