2019-05-02 22:33:03 +02:00
|
|
|
/* global alert */
|
2018-01-30 23:42:38 +01:00
|
|
|
import React, { Component } from 'react';
|
2019-05-02 22:33:03 +02:00
|
|
|
import { View, Share, InteractionManager } from 'react-native';
|
2019-02-14 06:15:56 +01:00
|
|
|
import QRCode from 'react-native-qrcode-svg';
|
2018-12-11 23:52:46 +01:00
|
|
|
import bip21 from 'bip21';
|
2019-01-21 14:55:39 +01:00
|
|
|
import {
|
|
|
|
BlueLoading,
|
|
|
|
SafeBlueArea,
|
|
|
|
BlueCopyTextToClipboard,
|
|
|
|
BlueButton,
|
|
|
|
BlueButtonLink,
|
|
|
|
BlueNavigationStyle,
|
|
|
|
is,
|
|
|
|
} from '../../BlueComponents';
|
2018-03-18 00:09:33 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2019-02-28 02:29:13 +01:00
|
|
|
import Privacy from '../../Privacy';
|
2018-06-25 00:22:46 +02:00
|
|
|
/** @type {AppStorage} */
|
2018-03-18 00:09:33 +01:00
|
|
|
let BlueApp = require('../../BlueApp');
|
2018-05-28 21:18:11 +02:00
|
|
|
let loc = require('../../loc');
|
2018-07-22 16:49:59 +02:00
|
|
|
// let EV = require('../../events');
|
2018-01-30 23:42:38 +01:00
|
|
|
|
|
|
|
export default class ReceiveDetails extends Component {
|
2018-10-29 23:11:48 +01:00
|
|
|
static navigationOptions = ({ navigation }) => ({
|
|
|
|
...BlueNavigationStyle(navigation, true),
|
|
|
|
title: loc.receive.header,
|
|
|
|
headerLeft: null,
|
|
|
|
});
|
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;
|
2018-07-22 16:49:59 +02:00
|
|
|
let secret = props.navigation.state.params.secret;
|
|
|
|
|
2018-01-30 23:42:38 +01:00
|
|
|
this.state = {
|
2018-03-17 21:39:21 +01:00
|
|
|
address: address,
|
2018-07-22 16:49:59 +02:00
|
|
|
secret: secret,
|
2018-09-29 17:35:04 +02:00
|
|
|
addressText: '',
|
2019-05-02 22:33:03 +02:00
|
|
|
bip21encoded: undefined,
|
2018-03-17 21:39:21 +01:00
|
|
|
};
|
2018-06-25 00:22:46 +02:00
|
|
|
}
|
|
|
|
|
2018-01-30 23:42:38 +01:00
|
|
|
async componentDidMount() {
|
2019-02-28 02:29:13 +01:00
|
|
|
Privacy.enableBlur();
|
2018-05-28 21:18:11 +02:00
|
|
|
console.log('receive/details - componentDidMount');
|
2018-07-22 16:49:59 +02: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 22:33:03 +02:00
|
|
|
if (wallet) {
|
|
|
|
if (wallet.getAddressAsync) {
|
2018-07-22 16:49:59 +02:00
|
|
|
address = await wallet.getAddressAsync();
|
2019-05-02 22:33:03 +02:00
|
|
|
}
|
|
|
|
BlueApp.saveToDisk(); // caching whatever getAddressAsync() generated internally
|
|
|
|
this.setState({
|
|
|
|
address: address,
|
|
|
|
addressText: address,
|
|
|
|
});
|
2018-07-22 16:49:59 +02:00
|
|
|
} else {
|
2019-05-02 22:33:03 +02:00
|
|
|
alert('There was a problem obtaining your receive address. Please, try again.');
|
|
|
|
this.props.navigation.goBack();
|
2018-07-22 16:49:59 +02:00
|
|
|
this.setState({
|
|
|
|
address,
|
2018-09-30 10:36:14 +02:00
|
|
|
addressText: address,
|
2018-07-22 16:49:59 +02:00
|
|
|
});
|
|
|
|
}
|
2019-05-02 22:33:03 +02:00
|
|
|
|
|
|
|
InteractionManager.runAfterInteractions(async () => {
|
|
|
|
const bip21encoded = bip21.encode(this.state.address);
|
|
|
|
this.setState({ bip21encoded });
|
|
|
|
});
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
|
2019-02-28 02:29:13 +01:00
|
|
|
componentWillUnmount() {
|
|
|
|
Privacy.disableBlur();
|
|
|
|
}
|
|
|
|
|
2018-01-30 23:42:38 +01:00
|
|
|
render() {
|
|
|
|
return (
|
2018-05-12 22:27:34 +02:00
|
|
|
<SafeBlueArea style={{ flex: 1 }}>
|
2018-09-29 17:35:04 +02: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 22:33:03 +02: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 22:33:03 +02: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 22:33:03 +02: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 03:43:28 +02:00
|
|
|
</View>
|
2018-01-30 23:42:38 +01:00
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-03-18 00:09:33 +01:00
|
|
|
|
|
|
|
ReceiveDetails.propTypes = {
|
|
|
|
navigation: PropTypes.shape({
|
2019-02-01 16:28:43 +01:00
|
|
|
goBack: PropTypes.func,
|
|
|
|
navigate: PropTypes.func,
|
2018-03-18 00:09:33 +01:00
|
|
|
state: PropTypes.shape({
|
|
|
|
params: PropTypes.shape({
|
|
|
|
address: PropTypes.string,
|
2018-07-22 16:49:59 +02:00
|
|
|
secret: PropTypes.string,
|
2018-03-18 00:09:33 +01:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
};
|