2018-10-27 17:13:09 +02:00
|
|
|
/* global alert */
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { ActivityIndicator, TouchableOpacity, StyleSheet, View } from 'react-native';
|
|
|
|
import { Text } from 'react-native-elements';
|
2018-10-29 23:11:48 +01:00
|
|
|
import { BlueButton, SafeBlueArea, BlueCard, BlueSpacing40, BlueNavigationStyle } from '../../BlueComponents';
|
2018-10-27 17:13:09 +02:00
|
|
|
import { BitcoinUnit } from '../../models/bitcoinUnits';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-03-05 02:04:40 +01:00
|
|
|
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
2018-10-27 17:13:09 +02:00
|
|
|
let loc = require('../../loc');
|
|
|
|
let EV = require('../../events');
|
2018-12-11 23:52:46 +01:00
|
|
|
let currency = require('../../currency');
|
|
|
|
let Bignumber = require('bignumber.js');
|
2018-10-27 17:13:09 +02:00
|
|
|
|
|
|
|
export default class Confirm extends Component {
|
2018-10-29 23:11:48 +01:00
|
|
|
static navigationOptions = () => ({
|
|
|
|
...BlueNavigationStyle(null, false),
|
|
|
|
title: loc.send.confirm.header,
|
|
|
|
});
|
2018-10-27 17:13:09 +02:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
isLoading: false,
|
|
|
|
amount: props.navigation.getParam('amount'),
|
|
|
|
fee: props.navigation.getParam('fee'),
|
2018-12-11 23:52:46 +01:00
|
|
|
feeSatoshi: new Bignumber(props.navigation.getParam('fee')).multipliedBy(100000000).toNumber(),
|
2018-10-27 17:13:09 +02:00
|
|
|
address: props.navigation.getParam('address'),
|
|
|
|
memo: props.navigation.getParam('memo'),
|
|
|
|
size: Math.round(props.navigation.getParam('tx').length / 2),
|
|
|
|
tx: props.navigation.getParam('tx'),
|
|
|
|
satoshiPerByte: props.navigation.getParam('satoshiPerByte'),
|
|
|
|
fromWallet: props.navigation.getParam('fromWallet'),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount() {
|
2018-12-11 23:52:46 +01:00
|
|
|
console.log('send/confirm - componentDidMount');
|
2018-10-27 17:13:09 +02:00
|
|
|
console.log('address = ', this.state.address);
|
|
|
|
}
|
|
|
|
|
|
|
|
broadcast() {
|
|
|
|
this.setState({ isLoading: true }, async () => {
|
2019-02-28 03:50:31 +01:00
|
|
|
try {
|
|
|
|
let result = await this.state.fromWallet.broadcastTx(this.state.tx);
|
|
|
|
if (result && result.code) {
|
|
|
|
if (result.code === 1) {
|
|
|
|
const message = result.message.split('\n');
|
|
|
|
throw new Error(`${message[0]}: ${message[2]}`);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.log('broadcast result = ', result);
|
|
|
|
EV(EV.enum.REMOTE_TRANSACTIONS_COUNT_CHANGED); // someone should fetch txs
|
|
|
|
this.props.navigation.navigate('Success', {
|
|
|
|
fee: Number(this.state.fee),
|
|
|
|
amount: this.state.amount,
|
|
|
|
address: this.state.address,
|
|
|
|
dismissModal: () => this.props.navigation.dismiss(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2019-03-05 02:04:40 +01:00
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', false);
|
2019-02-28 03:50:31 +01:00
|
|
|
this.setState({ isLoading: false });
|
|
|
|
alert(error.message);
|
2018-10-27 17:13:09 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<SafeBlueArea style={{ flex: 1, paddingTop: 19 }}>
|
|
|
|
<BlueCard style={{ alignItems: 'center', flex: 1 }}>
|
|
|
|
<View style={{ flexDirection: 'row', justifyContent: 'center', paddingTop: 16, paddingBottom: 16 }}>
|
|
|
|
<Text
|
|
|
|
style={{
|
|
|
|
color: '#0f5cc0',
|
|
|
|
fontSize: 36,
|
|
|
|
fontWeight: '600',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{this.state.amount}
|
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
style={{
|
|
|
|
color: '#0f5cc0',
|
|
|
|
fontSize: 16,
|
|
|
|
marginHorizontal: 4,
|
|
|
|
paddingBottom: 6,
|
|
|
|
fontWeight: '600',
|
|
|
|
alignSelf: 'flex-end',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{' ' + BitcoinUnit.BTC}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
<Text
|
|
|
|
style={{
|
|
|
|
color: '#37c0a1',
|
|
|
|
fontSize: 14,
|
|
|
|
marginHorizontal: 4,
|
|
|
|
paddingBottom: 6,
|
|
|
|
fontWeight: '500',
|
|
|
|
alignSelf: 'center',
|
|
|
|
}}
|
|
|
|
>
|
2018-12-11 23:52:46 +01:00
|
|
|
{loc.send.create.fee}: {loc.formatBalance(this.state.fee, BitcoinUnit.BTC)} (
|
|
|
|
{currency.satoshiToLocalCurrency(this.state.feeSatoshi)})
|
2018-10-27 17:13:09 +02:00
|
|
|
</Text>
|
|
|
|
</BlueCard>
|
|
|
|
<BlueCard>
|
|
|
|
<Text style={styles.transactionDetailsTitle}>{loc.send.create.to}</Text>
|
|
|
|
<Text style={styles.transactionDetailsSubtitle}>{this.state.address}</Text>
|
|
|
|
<BlueSpacing40 />
|
2019-01-30 01:50:50 +01:00
|
|
|
{this.state.isLoading ? <ActivityIndicator /> : <BlueButton onPress={() => this.broadcast()} title={loc.send.confirm.sendNow} />}
|
2018-10-27 17:13:09 +02:00
|
|
|
<TouchableOpacity
|
|
|
|
style={{ marginVertical: 24 }}
|
|
|
|
onPress={() =>
|
|
|
|
this.props.navigation.navigate('CreateTransaction', {
|
|
|
|
amount: this.state.amount,
|
|
|
|
fee: this.state.fee,
|
|
|
|
address: this.state.address,
|
|
|
|
memo: this.state.memo,
|
|
|
|
tx: this.state.tx,
|
|
|
|
satoshiPerByte: this.state.satoshiPerByte,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
>
|
2018-11-01 20:44:39 +01:00
|
|
|
<Text style={{ color: '#0c2550', fontSize: 15, fontWeight: '500', alignSelf: 'center' }}>
|
|
|
|
{loc.transactions.details.transaction_details}
|
|
|
|
</Text>
|
2018-10-27 17:13:09 +02:00
|
|
|
</TouchableOpacity>
|
|
|
|
</BlueCard>
|
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
transactionDetailsTitle: {
|
|
|
|
color: '#0c2550',
|
|
|
|
fontWeight: '500',
|
|
|
|
fontSize: 17,
|
|
|
|
marginBottom: 2,
|
|
|
|
},
|
|
|
|
transactionDetailsSubtitle: {
|
|
|
|
color: '#9aa0aa',
|
|
|
|
fontWeight: '500',
|
|
|
|
fontSize: 15,
|
|
|
|
marginBottom: 20,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Confirm.propTypes = {
|
|
|
|
navigation: PropTypes.shape({
|
2019-02-01 16:28:43 +01:00
|
|
|
goBack: PropTypes.func,
|
|
|
|
getParam: PropTypes.func,
|
|
|
|
navigate: PropTypes.func,
|
|
|
|
dismiss: PropTypes.func,
|
2018-10-27 17:13:09 +02:00
|
|
|
state: PropTypes.shape({
|
|
|
|
params: PropTypes.shape({
|
|
|
|
amount: PropTypes.string,
|
|
|
|
fee: PropTypes.number,
|
|
|
|
address: PropTypes.string,
|
|
|
|
memo: PropTypes.string,
|
|
|
|
fromWallet: PropTypes.shape({
|
|
|
|
fromAddress: PropTypes.string,
|
|
|
|
fromSecret: PropTypes.string,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
};
|