BlueWallet/screen/wallets/export.js

114 lines
2.9 KiB
JavaScript
Raw Normal View History

2018-01-30 23:42:38 +01:00
import React, { Component } from 'react';
2018-06-29 00:17:14 +02:00
import { Dimensions, ActivityIndicator, View } from 'react-native';
2018-01-30 23:42:38 +01:00
import QRCode from 'react-native-qrcode';
import { BlueSpacing, BlueSpacing40, SafeBlueArea, BlueCard, BlueText, BlueHeaderDefaultSub } from '../../BlueComponents';
2018-03-18 03:48:23 +01:00
import PropTypes from 'prop-types';
/** @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');
const aspectRatio = height / width;
let isIpad;
if (aspectRatio > 1.6) {
isIpad = false;
} else {
isIpad = true;
}
2018-01-30 23:42:38 +01:00
export default class WalletExport extends Component {
static navigationOptions = {
2018-06-29 00:17:14 +02:00
tabBarVisible: false,
2018-03-17 21:39:21 +01:00
};
2018-01-30 23:42:38 +01:00
constructor(props) {
super(props);
2018-03-17 21:39:21 +01:00
let address = props.navigation.state.params.address;
let secret = props.navigation.state.params.secret;
2018-03-17 21:39:21 +01:00
let wallet;
2018-01-30 23:42:38 +01:00
2018-03-17 21:39:21 +01:00
for (let w of BlueApp.getWallets()) {
if ((address && w.getAddress() === address) || w.getSecret() === secret) {
2018-03-17 21:39:21 +01:00
// found our wallet
wallet = w;
2018-01-30 23:42:38 +01:00
}
}
this.state = {
isLoading: true,
2018-03-17 21:39:21 +01:00
wallet,
};
2018-01-30 23:42:38 +01:00
}
async componentDidMount() {
this.setState({
isLoading: false,
2018-03-17 21:39:21 +01:00
});
2018-01-30 23:42:38 +01:00
}
render() {
if (this.state.isLoading) {
return (
2018-03-17 21:39:21 +01:00
<View style={{ flex: 1, paddingTop: 20 }}>
2018-01-30 23:42:38 +01:00
<ActivityIndicator />
</View>
);
}
/*
<BlueText style={{marginBottom: 10}}>
WIF stands for Wallet Import Format. Backup your WIF (also shown on QR) in a safe place.
</BlueText>
<Divider style={{ backgroundColor: '#ebebeb', marginBottom:20, }} />
*/
return (
2018-03-17 21:39:21 +01:00
<SafeBlueArea style={{ flex: 1, paddingTop: 20 }}>
2018-06-29 00:17:14 +02:00
{(() => {
if (isIpad) {
return <BlueSpacing40 />;
} else {
return <BlueSpacing />;
}
})()}
2018-07-07 15:04:32 +02:00
<BlueHeaderDefaultSub leftText={loc.wallets.export.title} onClose={() => this.props.navigation.goBack()} />
2018-06-29 00:17:14 +02:00
<BlueCard style={{ alignItems: 'center', flex: 1 }}>
{(() => {
if (this.state.wallet.getAddress()) {
return (
<View>
<BlueText>{this.state.wallet.getAddress()}</BlueText>
</View>
);
}
})()}
2018-01-30 23:42:38 +01:00
<QRCode
value={this.state.wallet.getSecret()}
size={312}
2018-05-22 19:10:53 +02:00
bgColor={BlueApp.settings.foregroundColor}
2018-03-17 21:39:21 +01:00
fgColor={BlueApp.settings.brandingColor}
/>
2018-07-07 15:04:32 +02:00
<BlueText>{this.state.wallet.getSecret()} [Wallet Import Format]</BlueText>
2018-01-30 23:42:38 +01:00
</BlueCard>
</SafeBlueArea>
);
}
}
2018-03-18 03:48:23 +01:00
WalletExport.propTypes = {
navigation: PropTypes.shape({
state: PropTypes.shape({
params: PropTypes.shape({
address: PropTypes.string,
secret: PropTypes.string,
2018-03-18 03:48:23 +01:00
}),
}),
navigate: PropTypes.func,
goBack: PropTypes.func,
}),
};