BlueWallet/screen/receive/details.js

141 lines
3.9 KiB
JavaScript
Raw Normal View History

2018-01-30 22:42:38 +00:00
import React, { Component } from 'react';
2019-01-21 08:55:39 -05:00
import { View, Share } from 'react-native';
import { QRCode } from 'react-native-custom-qr-codes';
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';
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');
// let EV = require('../../events');
2018-01-30 22:42:38 +00:00
export default class ReceiveDetails extends Component {
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;
let secret = props.navigation.state.params.secret;
2018-01-30 22:42:38 +00:00
this.state = {
isLoading: true,
2018-03-17 22:39:21 +02:00
address: address,
secret: secret,
addressText: '',
2018-03-17 22:39:21 +02:00
};
2018-06-24 23:22:46 +01:00
// EV(EV.enum.RECEIVE_ADDRESS_CHANGED, this.refreshFunction.bind(this));
2018-06-24 23:22:46 +01:00
}
/* refreshFunction(newAddress) {
2018-06-24 23:22:46 +01:00
console.log('newAddress =', newAddress);
this.setState({
address: newAddress,
});
} */
2018-01-30 22:42:38 +00:00
async componentDidMount() {
2018-05-28 20:18:11 +01: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;
}
}
if (wallet && wallet.getAddressAsync) {
setTimeout(async () => {
address = await wallet.getAddressAsync();
BlueApp.saveToDisk(); // caching whatever getAddressAsync() generated internally
this.setState({
address: address,
addressText: address,
isLoading: false,
});
}, 1);
} else {
this.setState({
isLoading: false,
address,
addressText: address,
});
}
2018-01-30 22:42:38 +00:00
}
render() {
console.log('render() receive/details, address,secret=', this.state.address, ',', this.state.secret);
2018-01-30 22:42:38 +00:00
if (this.state.isLoading) {
2018-03-17 22:39:21 +02:00
return <BlueLoading />;
2018-01-30 22:42:38 +00:00
}
return (
2018-05-12 21:27:34 +01:00
<SafeBlueArea style={{ flex: 1 }}>
<View style={{ flex: 1, justifyContent: 'space-between', alignItems: 'center' }}>
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center', paddingHorizontal: 16 }}>
<QRCode
content={bip21.encode(this.state.address)}
size={(is.ipad() && 300) || 300}
color={BlueApp.settings.foregroundColor}
backgroundColor={BlueApp.settings.brandingColor}
logo={require('../../img/qr-code.png')}
/>
2019-01-21 08:55:39 -05:00
<BlueCopyTextToClipboard text={this.state.addressText} />
</View>
2018-12-27 14:48:00 +01:00
<View style={{ marginBottom: 24, alignItems: 'center' }}>
<BlueButtonLink
title={loc.receive.details.setAmount}
onPress={() => {
this.props.navigation.navigate('ReceiveAmount', {
address: this.state.address,
});
}}
/>
<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-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({
goBack: PropTypes.function,
navigate: PropTypes.function,
2018-03-17 23:09:33 +00:00
state: PropTypes.shape({
params: PropTypes.shape({
address: PropTypes.string,
secret: PropTypes.string,
2018-03-17 23:09:33 +00:00
}),
}),
}),
};