BlueWallet/screen/receive/details.js

145 lines
4.0 KiB
JavaScript
Raw Normal View History

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';
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';
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');
// let EV = require('../../events');
2018-01-30 23:42:38 +01:00
export default class ReceiveDetails extends Component {
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;
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,
secret: secret,
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() {
Privacy.enableBlur();
2018-05-28 21:18:11 +02:00
console.log('receive/details - componentDidMount');
/** @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) {
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,
});
} 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();
this.setState({
address,
addressText: address,
});
}
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
}
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 }}>
<View style={{ }}>
<View style={{ marginTop:32, 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}
/>
)}
</View>
<View style={{ alignItems: 'center', marginTop: 0 }}>
2019-05-02 22:33:03 +02:00
<BlueCopyTextToClipboard text={this.state.addressText} />
<BlueButtonLink
title={loc.receive.details.setAmount}
onPress={() => {
this.props.navigation.navigate('ReceiveAmount', {
address: this.state.address,
});
}}
/>
<View>
2019-05-02 22:33:03 +02:00
<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>
</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({
goBack: PropTypes.func,
navigate: PropTypes.func,
2018-03-18 00:09:33 +01:00
state: PropTypes.shape({
params: PropTypes.shape({
address: PropTypes.string,
secret: PropTypes.string,
2018-03-18 00:09:33 +01:00
}),
}),
}),
};