2018-01-30 23:42:38 +01:00
|
|
|
import React, { Component } from 'react';
|
2018-06-28 03:43:28 +02:00
|
|
|
import { Dimensions, View } from 'react-native';
|
2018-01-30 23:42:38 +01:00
|
|
|
import QRCode from 'react-native-qrcode';
|
2018-09-22 13:26:45 +02:00
|
|
|
import { BlueLoading, BlueFormInputAddress, SafeBlueArea, BlueCard, BlueHeaderDefaultSub, is } from '../../BlueComponents';
|
2018-03-18 00:09:33 +01:00
|
|
|
import PropTypes from 'prop-types';
|
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');
|
|
|
|
const { width } = Dimensions.get('window');
|
2018-01-30 23:42:38 +01:00
|
|
|
|
|
|
|
export default class ReceiveDetails extends Component {
|
|
|
|
static navigationOptions = {
|
2018-09-19 03:59:16 +02:00
|
|
|
header: ({ navigation }) => {
|
2018-09-29 00:17:26 +02:00
|
|
|
return <BlueHeaderDefaultSub leftText={loc.receive.header} onClose={() => navigation.goBack(null)} />;
|
2018-09-19 03:59:16 +02:00
|
|
|
},
|
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;
|
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 = {
|
|
|
|
isLoading: true,
|
2018-03-17 21:39:21 +01:00
|
|
|
address: address,
|
2018-07-22 16:49:59 +02:00
|
|
|
secret: secret,
|
2018-03-17 21:39:21 +01:00
|
|
|
};
|
2018-06-25 00:22:46 +02:00
|
|
|
|
2018-07-22 16:49:59 +02:00
|
|
|
// EV(EV.enum.RECEIVE_ADDRESS_CHANGED, this.refreshFunction.bind(this));
|
2018-06-25 00:22:46 +02:00
|
|
|
}
|
|
|
|
|
2018-07-22 16:49:59 +02:00
|
|
|
/* refreshFunction(newAddress) {
|
2018-06-25 00:22:46 +02:00
|
|
|
console.log('newAddress =', newAddress);
|
|
|
|
this.setState({
|
|
|
|
address: newAddress,
|
|
|
|
});
|
2018-07-22 16:49:59 +02:00
|
|
|
} */
|
2018-01-30 23:42:38 +01:00
|
|
|
|
|
|
|
async componentDidMount() {
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wallet && wallet.getAddressAsync) {
|
|
|
|
setTimeout(async () => {
|
|
|
|
address = await wallet.getAddressAsync();
|
|
|
|
BlueApp.saveToDisk(); // caching whatever getAddressAsync() generated internally
|
|
|
|
this.setState({
|
|
|
|
address: address,
|
|
|
|
isLoading: false,
|
|
|
|
});
|
|
|
|
}, 1);
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
isLoading: false,
|
|
|
|
address,
|
|
|
|
});
|
|
|
|
}
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-07-22 16:49:59 +02:00
|
|
|
console.log('render() receive/details, address,secret=', this.state.address, ',', this.state.secret);
|
2018-01-30 23:42:38 +01:00
|
|
|
if (this.state.isLoading) {
|
2018-03-17 21:39:21 +01:00
|
|
|
return <BlueLoading />;
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2018-05-12 22:27:34 +02:00
|
|
|
<SafeBlueArea style={{ flex: 1 }}>
|
2018-07-14 20:57:35 +02:00
|
|
|
<BlueCard
|
|
|
|
containerStyle={{
|
|
|
|
alignItems: 'center',
|
|
|
|
flex: 1,
|
|
|
|
borderColor: 'red',
|
|
|
|
borderWidth: 7,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<BlueFormInputAddress editable value={this.state.address} />
|
|
|
|
</BlueCard>
|
|
|
|
|
2018-06-28 03:43:28 +02:00
|
|
|
<View
|
|
|
|
style={{
|
2018-07-22 16:49:59 +02:00
|
|
|
left: (width - ((is.ipad() && 250) || 312)) / 2,
|
2018-06-28 03:43:28 +02:00
|
|
|
}}
|
|
|
|
>
|
2018-01-30 23:42:38 +01:00
|
|
|
<QRCode
|
|
|
|
value={this.state.address}
|
2018-07-22 16:49:59 +02:00
|
|
|
size={(is.ipad() && 250) || 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-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.function,
|
|
|
|
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
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
};
|