2018-10-20 23:10:21 +02:00
|
|
|
/* global alert */
|
2018-01-30 23:42:38 +01:00
|
|
|
import React, { Component } from 'react';
|
2018-10-20 23:10:21 +02:00
|
|
|
import { TextInput, ActivityIndicator, TouchableOpacity, Clipboard, StyleSheet, ScrollView } from 'react-native';
|
|
|
|
import { Text } from 'react-native-elements';
|
|
|
|
import { BlueButton, SafeBlueArea, BlueCard, BlueText } from '../../BlueComponents';
|
2018-03-18 03:48:23 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2018-08-08 02:05:34 +02:00
|
|
|
/** @type {AppStorage} */
|
2018-10-20 23:10:21 +02:00
|
|
|
// let BlueApp = require('../../BlueApp');
|
2018-05-28 21:18:11 +02:00
|
|
|
let loc = require('../../loc');
|
2018-10-03 02:54:55 +02:00
|
|
|
let EV = require('../../events');
|
2018-01-30 23:42:38 +01:00
|
|
|
|
|
|
|
export default class SendCreate extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-03-17 21:39:21 +01:00
|
|
|
console.log('send/create constructor');
|
2018-10-20 23:10:21 +02:00
|
|
|
|
2018-01-30 23:42:38 +01:00
|
|
|
this.state = {
|
2018-10-20 23:10:21 +02:00
|
|
|
isLoading: false,
|
2018-01-30 23:42:38 +01:00
|
|
|
amount: props.navigation.state.params.amount,
|
|
|
|
fee: props.navigation.state.params.fee,
|
|
|
|
address: props.navigation.state.params.address,
|
|
|
|
memo: props.navigation.state.params.memo,
|
2018-10-20 23:10:21 +02:00
|
|
|
size: Math.round(props.navigation.getParam('tx').length / 2),
|
|
|
|
tx: props.navigation.getParam('tx'),
|
|
|
|
satoshiPerByte: props.navigation.getParam('satoshiPerByte'),
|
|
|
|
fromWallet: props.navigation.getParam('fromWallet'),
|
2018-03-17 21:39:21 +01:00
|
|
|
};
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount() {
|
2018-03-17 21:39:21 +01:00
|
|
|
console.log('send/create - componentDidMount');
|
|
|
|
console.log('address = ', this.state.address);
|
2018-10-20 23:10:21 +02:00
|
|
|
}
|
2018-03-17 21:39:21 +01:00
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
broadcast() {
|
|
|
|
this.setState({ isLoading: true }, async () => {
|
|
|
|
let result = await this.state.fromWallet.broadcastTx(this.state.tx);
|
|
|
|
console.log('broadcast result = ', result);
|
|
|
|
if (typeof result === 'string') {
|
|
|
|
result = JSON.parse(result);
|
2018-08-08 02:05:34 +02:00
|
|
|
}
|
2018-10-20 23:10:21 +02:00
|
|
|
this.setState({ isLoading: false });
|
|
|
|
if (result && result.error) {
|
|
|
|
alert(JSON.stringify(result.error));
|
|
|
|
} else {
|
|
|
|
EV(EV.enum.REMOTE_TRANSACTIONS_COUNT_CHANGED); // someone should fetch txs
|
|
|
|
alert('Transaction has been successfully broadcasted. Your transaction ID is: ' + JSON.stringify(result.result));
|
|
|
|
this.props.navigation.navigate('Wallets');
|
2018-08-08 02:05:34 +02:00
|
|
|
}
|
2018-03-17 21:39:21 +01:00
|
|
|
});
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-10-20 23:10:21 +02:00
|
|
|
return (
|
|
|
|
<SafeBlueArea style={{ flex: 1, paddingTop: 19 }}>
|
|
|
|
<ScrollView>
|
2018-08-19 00:10:12 +02:00
|
|
|
<BlueCard style={{ alignItems: 'center', flex: 1 }}>
|
2018-10-20 23:10:21 +02:00
|
|
|
<BlueText style={{ color: '#0c2550', fontWeight: '500' }}>{loc.send.create.this_is_hex}</BlueText>
|
|
|
|
|
|
|
|
<TextInput
|
|
|
|
style={{
|
|
|
|
borderColor: '#ebebeb',
|
|
|
|
backgroundColor: '#d2f8d6',
|
|
|
|
borderRadius: 4,
|
|
|
|
marginTop: 20,
|
|
|
|
color: '#37c0a1',
|
|
|
|
fontWeight: '500',
|
|
|
|
fontSize: 14,
|
|
|
|
paddingHorizontal: 16,
|
|
|
|
paddingBottom: 16,
|
|
|
|
paddingTop: 16,
|
|
|
|
}}
|
|
|
|
height={72}
|
|
|
|
multiline
|
|
|
|
editable={false}
|
|
|
|
value={this.state.tx}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<TouchableOpacity style={{ marginVertical: 24 }} onPress={() => Clipboard.setString(this.state.tx)}>
|
|
|
|
<Text style={{ color: '#0c2550', fontSize: 15, fontWeight: '500', alignSelf: 'center' }}>Copy and broadcast later</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
{this.state.isLoading ? (
|
|
|
|
<ActivityIndicator />
|
|
|
|
) : (
|
|
|
|
<BlueButton onPress={() => this.broadcast()} title={loc.send.details.send} style={{ maxWidth: 263, paddingHorizontal: 56 }} />
|
|
|
|
)}
|
2018-01-30 23:42:38 +01:00
|
|
|
</BlueCard>
|
2018-10-20 23:10:21 +02:00
|
|
|
<BlueCard>
|
|
|
|
<Text style={styles.transactionDetailsTitle}>{loc.send.create.to}</Text>
|
|
|
|
<Text style={styles.transactionDetailsSubtitle}>{this.state.address}</Text>
|
2018-01-30 23:42:38 +01:00
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
<Text style={styles.transactionDetailsTitle}>{loc.send.create.amount}</Text>
|
|
|
|
<Text style={styles.transactionDetailsSubtitle}>{this.state.amount} BTC</Text>
|
2018-01-30 23:42:38 +01:00
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
<Text style={styles.transactionDetailsTitle}>{loc.send.create.fee}</Text>
|
|
|
|
<Text style={styles.transactionDetailsSubtitle}>{this.state.fee} BTC</Text>
|
2018-08-19 00:10:12 +02:00
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
<Text style={styles.transactionDetailsTitle}>{loc.send.create.tx_size}</Text>
|
|
|
|
<Text style={styles.transactionDetailsSubtitle}>{this.state.size} bytes</Text>
|
2018-01-30 23:42:38 +01:00
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
<Text style={styles.transactionDetailsTitle}>{loc.send.create.satoshi_per_byte}</Text>
|
|
|
|
<Text style={styles.transactionDetailsSubtitle}>{this.state.satoshiPerByte} Sat/B</Text>
|
2018-01-30 23:42:38 +01:00
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
<Text style={styles.transactionDetailsTitle}>{loc.send.create.memo}</Text>
|
|
|
|
<Text style={styles.transactionDetailsSubtitle}>{this.state.memo}</Text>
|
|
|
|
</BlueCard>
|
|
|
|
</ScrollView>
|
2018-01-30 23:42:38 +01:00
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-03-18 03:48:23 +01:00
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
transactionDetailsTitle: {
|
|
|
|
color: '#0c2550',
|
|
|
|
fontWeight: '500',
|
|
|
|
fontSize: 17,
|
|
|
|
marginBottom: 2,
|
|
|
|
},
|
|
|
|
transactionDetailsSubtitle: {
|
|
|
|
color: '#9aa0aa',
|
|
|
|
fontWeight: '500',
|
|
|
|
fontSize: 15,
|
|
|
|
marginBottom: 20,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-03-18 03:48:23 +01:00
|
|
|
SendCreate.propTypes = {
|
|
|
|
navigation: PropTypes.shape({
|
|
|
|
goBack: PropTypes.function,
|
2018-10-20 23:10:21 +02:00
|
|
|
getParam: PropTypes.function,
|
|
|
|
navigate: PropTypes.function,
|
2018-03-18 03:48:23 +01:00
|
|
|
state: PropTypes.shape({
|
|
|
|
params: PropTypes.shape({
|
|
|
|
amount: PropTypes.string,
|
2018-10-20 23:10:21 +02:00
|
|
|
fee: PropTypes.number,
|
2018-03-18 03:48:23 +01:00
|
|
|
address: PropTypes.string,
|
|
|
|
memo: PropTypes.string,
|
2018-10-20 23:10:21 +02:00
|
|
|
fromWallet: PropTypes.shape({
|
|
|
|
fromAddress: PropTypes.string,
|
|
|
|
fromSecret: PropTypes.string,
|
|
|
|
}),
|
2018-03-18 03:48:23 +01:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
};
|