BlueWallet/screen/receive/details.js

117 lines
3.1 KiB
JavaScript
Raw Normal View History

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';
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');
// 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 = {
header: ({ navigation }) => {
return <BlueHeaderDefaultSub leftText={loc.receive.header} onClose={() => navigation.goBack(null)} />;
},
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;
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,
secret: secret,
2018-03-17 21:39:21 +01:00
};
2018-06-25 00:22:46 +02:00
// EV(EV.enum.RECEIVE_ADDRESS_CHANGED, this.refreshFunction.bind(this));
2018-06-25 00:22:46 +02:00
}
/* refreshFunction(newAddress) {
2018-06-25 00:22:46 +02:00
console.log('newAddress =', newAddress);
this.setState({
address: newAddress,
});
} */
2018-01-30 23:42:38 +01:00
async componentDidMount() {
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;
}
}
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() {
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 }}>
<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={{
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}
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,
secret: PropTypes.string,
2018-03-18 00:09:33 +01:00
}),
}),
}),
};