2019-05-02 16:33:03 -04:00
|
|
|
/* global alert */
|
2018-01-30 22:42:38 +00:00
|
|
|
import React, { Component } from 'react';
|
2019-05-02 16:33:03 -04:00
|
|
|
import { View, Share, InteractionManager } from 'react-native';
|
2019-02-14 00:15:56 -05:00
|
|
|
import QRCode from 'react-native-qrcode-svg';
|
2018-12-11 22:52:46 +00:00
|
|
|
import bip21 from 'bip21';
|
2019-01-21 08:55:39 -05:00
|
|
|
import {
|
|
|
|
BlueLoading,
|
|
|
|
SafeBlueArea,
|
|
|
|
BlueCopyTextToClipboard,
|
|
|
|
BlueButton,
|
|
|
|
BlueButtonLink,
|
|
|
|
BlueNavigationStyle,
|
|
|
|
is,
|
|
|
|
} from '../../BlueComponents';
|
2018-03-17 23:09:33 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2019-02-27 20:29:13 -05:00
|
|
|
import Privacy from '../../Privacy';
|
2018-06-24 23:22:46 +01:00
|
|
|
/** @type {AppStorage} */
|
2018-03-17 23:09:33 +00:00
|
|
|
let BlueApp = require('../../BlueApp');
|
2018-05-28 20:18:11 +01:00
|
|
|
let loc = require('../../loc');
|
2018-07-22 15:49:59 +01:00
|
|
|
// let EV = require('../../events');
|
2018-01-30 22:42:38 +00:00
|
|
|
|
|
|
|
export default class ReceiveDetails extends Component {
|
2018-10-29 18:11:48 -04:00
|
|
|
static navigationOptions = ({ navigation }) => ({
|
|
|
|
...BlueNavigationStyle(navigation, true),
|
|
|
|
title: loc.receive.header,
|
|
|
|
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;
|
2018-07-22 15:49:59 +01:00
|
|
|
let secret = props.navigation.state.params.secret;
|
|
|
|
|
2018-01-30 22:42:38 +00:00
|
|
|
this.state = {
|
2018-03-17 22:39:21 +02:00
|
|
|
address: address,
|
2018-07-22 15:49:59 +01:00
|
|
|
secret: secret,
|
2018-09-29 11:35:04 -04:00
|
|
|
addressText: '',
|
2019-05-02 16:33:03 -04:00
|
|
|
bip21encoded: undefined,
|
2018-03-17 22:39:21 +02:00
|
|
|
};
|
2018-06-24 23:22:46 +01:00
|
|
|
}
|
|
|
|
|
2018-01-30 22:42:38 +00:00
|
|
|
async componentDidMount() {
|
2019-02-27 20:29:13 -05:00
|
|
|
Privacy.enableBlur();
|
2018-05-28 20:18:11 +01:00
|
|
|
console.log('receive/details - componentDidMount');
|
2018-07-22 15:49:59 +01:00
|
|
|
|
|
|
|
/** @type {AbstractWallet} */
|
|
|
|
let wallet;
|
|
|
|
let address = this.state.address;
|
|
|
|
for (let w of BlueApp.getWallets()) {
|
|
|
|
if ((address && w.getAddress() === this.state.address) || w.getSecret() === this.state.secret) {
|
|
|
|
// found our wallet
|
|
|
|
wallet = w;
|
|
|
|
}
|
|
|
|
}
|
2019-05-02 16:33:03 -04:00
|
|
|
if (wallet) {
|
|
|
|
if (wallet.getAddressAsync) {
|
2018-07-22 15:49:59 +01:00
|
|
|
address = await wallet.getAddressAsync();
|
2019-05-02 16:33:03 -04:00
|
|
|
}
|
|
|
|
BlueApp.saveToDisk(); // caching whatever getAddressAsync() generated internally
|
|
|
|
this.setState({
|
|
|
|
address: address,
|
|
|
|
addressText: address,
|
|
|
|
});
|
2018-07-22 15:49:59 +01:00
|
|
|
} else {
|
2019-05-02 16:33:03 -04:00
|
|
|
alert('There was a problem obtaining your receive address. Please, try again.');
|
|
|
|
this.props.navigation.goBack();
|
2018-07-22 15:49:59 +01:00
|
|
|
this.setState({
|
|
|
|
address,
|
2018-09-30 04:36:14 -04:00
|
|
|
addressText: address,
|
2018-07-22 15:49:59 +01:00
|
|
|
});
|
|
|
|
}
|
2019-05-02 16:33:03 -04:00
|
|
|
|
|
|
|
InteractionManager.runAfterInteractions(async () => {
|
|
|
|
const bip21encoded = bip21.encode(this.state.address);
|
|
|
|
this.setState({ bip21encoded });
|
|
|
|
});
|
2018-01-30 22:42:38 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 20:29:13 -05:00
|
|
|
componentWillUnmount() {
|
|
|
|
Privacy.disableBlur();
|
|
|
|
}
|
|
|
|
|
2018-01-30 22:42:38 +00:00
|
|
|
render() {
|
|
|
|
return (
|
2018-05-12 21:27:34 +01:00
|
|
|
<SafeBlueArea style={{ flex: 1 }}>
|
2018-09-29 11:35:04 -04:00
|
|
|
<View style={{ flex: 1, justifyContent: 'space-between', alignItems: 'center' }}>
|
2018-12-25 15:25:12 +01:00
|
|
|
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center', paddingHorizontal: 16 }}>
|
2019-05-02 16:33:03 -04:00
|
|
|
{this.state.bip21encoded === undefined ? (
|
|
|
|
<BlueLoading />
|
|
|
|
) : (
|
|
|
|
<QRCode
|
|
|
|
value={this.state.bip21encoded}
|
|
|
|
logo={require('../../img/qr-code.png')}
|
|
|
|
size={(is.ipad() && 300) || 300}
|
|
|
|
logoSize={90}
|
|
|
|
color={BlueApp.settings.foregroundColor}
|
|
|
|
logoBackgroundColor={BlueApp.settings.brandingColor}
|
|
|
|
/>
|
|
|
|
)}
|
2018-12-25 15:25:12 +01:00
|
|
|
</View>
|
2019-05-02 16:33:03 -04:00
|
|
|
<View style={{ alignItems: 'center' }}>
|
|
|
|
<BlueCopyTextToClipboard text={this.state.addressText} />
|
2018-12-25 15:25:12 +01:00
|
|
|
<BlueButtonLink
|
|
|
|
title={loc.receive.details.setAmount}
|
|
|
|
onPress={() => {
|
|
|
|
this.props.navigation.navigate('ReceiveAmount', {
|
|
|
|
address: this.state.address,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
2019-05-02 16:33:03 -04:00
|
|
|
<View syle={{ margin: 24 }}>
|
|
|
|
<BlueButton
|
|
|
|
icon={{
|
|
|
|
name: 'share-alternative',
|
|
|
|
type: 'entypo',
|
|
|
|
color: BlueApp.settings.buttonTextColor,
|
|
|
|
}}
|
|
|
|
onPress={async () => {
|
|
|
|
Share.share({
|
|
|
|
message: this.state.address,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
title={loc.receive.details.share}
|
|
|
|
/>
|
|
|
|
</View>
|
2018-12-25 15:25:12 +01:00
|
|
|
</View>
|
2018-06-28 02:43:28 +01:00
|
|
|
</View>
|
2018-01-30 22:42:38 +00:00
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-03-17 23:09:33 +00:00
|
|
|
|
|
|
|
ReceiveDetails.propTypes = {
|
|
|
|
navigation: PropTypes.shape({
|
2019-02-01 10:28:43 -05:00
|
|
|
goBack: PropTypes.func,
|
|
|
|
navigate: PropTypes.func,
|
2018-03-17 23:09:33 +00:00
|
|
|
state: PropTypes.shape({
|
|
|
|
params: PropTypes.shape({
|
|
|
|
address: PropTypes.string,
|
2018-07-22 15:49:59 +01:00
|
|
|
secret: PropTypes.string,
|
2018-03-17 23:09:33 +00:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
};
|