BlueWallet/screen/receive/details.js

116 lines
2.7 KiB
JavaScript
Raw Normal View History

2018-01-30 22:42:38 +00:00
import React, { Component } from 'react';
2018-06-28 02:43:28 +01:00
import { Dimensions, View } from 'react-native';
2018-01-30 22:42:38 +00:00
import QRCode from 'react-native-qrcode';
import {
2018-03-17 22:39:21 +02:00
BlueLoading,
2018-05-12 21:27:34 +01:00
BlueFormInputAddress,
2018-03-17 22:39:21 +02:00
SafeBlueArea,
BlueCard,
2018-06-28 02:43:28 +01:00
BlueHeaderDefaultSub,
BlueSpacing,
BlueSpacing40,
2018-03-17 22:39:21 +02:00
} 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');
2018-06-24 23:22:46 +01:00
let EV = require('../../events');
2018-05-12 21:27:34 +01:00
const { height, width } = Dimensions.get('window');
const aspectRatio = height / width;
let isIpad;
if (aspectRatio > 1.6) {
isIpad = false;
} else {
isIpad = true;
}
2018-01-30 22:42:38 +00:00
export default class ReceiveDetails extends Component {
static navigationOptions = {
2018-06-24 23:22:46 +01:00
tabBarVisible: false,
2018-03-17 22:39:21 +02:00
};
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;
2018-01-30 22:42:38 +00:00
this.state = {
isLoading: true,
2018-03-17 22:39:21 +02:00
address: address,
};
console.log(JSON.stringify(address));
2018-06-24 23:22:46 +01:00
EV(EV.enum.RECEIVE_ADDRESS_CHANGED, this.refreshFunction.bind(this));
}
refreshFunction(newAddress) {
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');
2018-01-30 22:42:38 +00:00
this.setState({
isLoading: false,
2018-03-17 22:39:21 +02:00
});
2018-01-30 22:42:38 +00:00
}
render() {
2018-06-24 23:22:46 +01:00
console.log('render() receive/details, address=', this.state.address);
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 }}>
2018-06-28 02:43:28 +01:00
{(() => {
if (isIpad) {
return <BlueSpacing40 />;
} else {
return <BlueSpacing />;
2018-05-12 21:27:34 +01:00
}
2018-06-28 02:43:28 +01:00
})()}
<BlueHeaderDefaultSub
leftText={loc.receive.list.header}
onClose={() => this.props.navigation.goBack()}
2018-06-24 23:22:46 +01:00
/>
2018-05-12 21:27:34 +01:00
2018-06-28 02:43:28 +01:00
<View
style={{
left: (width - ((isIpad && 250) || 312)) / 2,
}}
>
2018-01-30 22:42:38 +00:00
<QRCode
value={this.state.address}
2018-05-12 21:27:34 +01:00
size={(isIpad && 250) || 312}
2018-05-22 18:10:53 +01:00
bgColor={BlueApp.settings.foregroundColor}
2018-03-17 22:39:21 +02:00
fgColor={BlueApp.settings.brandingColor}
/>
2018-06-28 02:43:28 +01:00
</View>
<BlueCard
containerStyle={{
alignItems: 'center',
flex: 1,
borderColor: 'red',
borderWidth: 7,
}}
>
2018-06-24 23:22:46 +01:00
<BlueFormInputAddress editable value={this.state.address} />
2018-01-30 22:42:38 +00:00
</BlueCard>
</SafeBlueArea>
);
}
}
2018-03-17 23:09:33 +00:00
ReceiveDetails.propTypes = {
navigation: PropTypes.shape({
goBack: PropTypes.function,
state: PropTypes.shape({
params: PropTypes.shape({
address: PropTypes.string,
}),
}),
}),
};