2018-10-20 23:10:21 +02:00
|
|
|
/* global alert */
|
2018-01-30 23:42:38 +01:00
|
|
|
import React, { Component } from 'react';
|
2018-03-17 21:39:21 +01:00
|
|
|
import {
|
2018-10-20 23:10:21 +02:00
|
|
|
ActivityIndicator,
|
|
|
|
View,
|
|
|
|
TextInput,
|
|
|
|
TouchableOpacity,
|
|
|
|
KeyboardAvoidingView,
|
|
|
|
Keyboard,
|
|
|
|
TouchableWithoutFeedback,
|
|
|
|
StyleSheet,
|
2018-12-11 23:52:46 +01:00
|
|
|
Platform,
|
2018-10-20 23:10:21 +02:00
|
|
|
Slider,
|
|
|
|
} from 'react-native';
|
|
|
|
import { Text, Icon } from 'react-native-elements';
|
2018-10-29 23:11:48 +01:00
|
|
|
import { BlueNavigationStyle, BlueButton } from '../../BlueComponents';
|
2018-03-18 03:48:23 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2018-10-20 23:10:21 +02:00
|
|
|
import Modal from 'react-native-modal';
|
|
|
|
import NetworkTransactionFees, { NetworkTransactionFee } from '../../models/networkTransactionFees';
|
|
|
|
import BitcoinBIP70TransactionDecode from '../../bip70/bip70';
|
|
|
|
import { BitcoinUnit } from '../../models/bitcoinUnits';
|
2018-12-11 23:52:46 +01:00
|
|
|
import { HDSegwitP2SHWallet } from '../../class';
|
2018-12-13 17:50:18 +01:00
|
|
|
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
2018-03-24 22:24:20 +01:00
|
|
|
const bip21 = require('bip21');
|
2018-03-17 21:39:21 +01:00
|
|
|
let EV = require('../../events');
|
2018-01-30 23:42:38 +01:00
|
|
|
let BigNumber = require('bignumber.js');
|
2018-08-08 02:05:34 +02:00
|
|
|
/** @type {AppStorage} */
|
2018-03-18 03:48:23 +01:00
|
|
|
let BlueApp = require('../../BlueApp');
|
2018-05-28 21:18:11 +02:00
|
|
|
let loc = require('../../loc');
|
2018-10-20 23:10:21 +02:00
|
|
|
let bitcoin = require('bitcoinjs-lib');
|
2018-10-27 17:13:09 +02:00
|
|
|
let currency = require('../../currency');
|
2018-01-30 23:42:38 +01:00
|
|
|
|
2018-03-24 22:24:20 +01:00
|
|
|
const btcAddressRx = /^[a-zA-Z0-9]{26,35}$/;
|
2018-03-20 01:49:32 +01:00
|
|
|
|
2018-01-30 23:42:38 +01:00
|
|
|
export default class SendDetails extends Component {
|
2018-10-29 23:11:48 +01:00
|
|
|
static navigationOptions = ({ navigation }) => ({
|
|
|
|
...BlueNavigationStyle(navigation, true),
|
|
|
|
title: loc.send.header,
|
|
|
|
});
|
2018-01-30 23:42:38 +01:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-09-01 01:28:19 +02:00
|
|
|
console.log('props.navigation.state.params=', props.navigation.state.params);
|
2018-03-17 21:39:21 +01:00
|
|
|
let startTime = Date.now();
|
|
|
|
let address;
|
2018-07-07 15:04:32 +02:00
|
|
|
if (props.navigation.state.params) address = props.navigation.state.params.address;
|
2018-09-01 01:28:19 +02:00
|
|
|
let memo = false;
|
|
|
|
if (props.navigation.state.params) memo = props.navigation.state.params.memo;
|
2018-03-17 21:39:21 +01:00
|
|
|
let fromAddress;
|
2018-07-07 15:04:32 +02:00
|
|
|
if (props.navigation.state.params) fromAddress = props.navigation.state.params.fromAddress;
|
2018-08-08 02:05:34 +02:00
|
|
|
let fromSecret;
|
2018-10-27 17:13:09 +02:00
|
|
|
if (props.navigation.state.params) fromSecret = props.navigation.state.params.fromSecret;
|
2018-12-12 15:52:49 +01:00
|
|
|
let fromWallet = null;
|
|
|
|
|
|
|
|
const wallets = BlueApp.getWallets();
|
2018-03-17 21:39:21 +01:00
|
|
|
|
|
|
|
let startTime2 = Date.now();
|
2018-12-12 15:52:49 +01:00
|
|
|
for (let w of wallets) {
|
2018-08-08 02:05:34 +02:00
|
|
|
if (w.getSecret() === fromSecret) {
|
|
|
|
fromWallet = w;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-01-30 23:42:38 +01:00
|
|
|
if (w.getAddress() === fromAddress) {
|
2018-03-17 21:39:21 +01:00
|
|
|
fromWallet = w;
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-12 15:52:49 +01:00
|
|
|
// fallback to first wallet if it exists
|
|
|
|
if (!fromWallet && wallets[0]) fromWallet = wallets[0];
|
|
|
|
|
|
|
|
let amount = '';
|
|
|
|
let parsedBitcoinUri = null;
|
|
|
|
if (props.navigation.state.params.uri) {
|
|
|
|
try {
|
|
|
|
parsedBitcoinUri = bip21.decode(props.navigation.state.params.uri);
|
|
|
|
|
|
|
|
address = parsedBitcoinUri.address ? parsedBitcoinUri.address : address;
|
|
|
|
amount = parsedBitcoinUri.options.amount ? parsedBitcoinUri.options.amount : amount;
|
|
|
|
memo = parsedBitcoinUri.options.label ? parsedBitcoinUri.options.label : memo;
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
alert('Error: Unable to decode Bitcoin address');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-17 21:39:21 +01:00
|
|
|
let endTime2 = Date.now();
|
|
|
|
console.log('getAddress() took', (endTime2 - startTime2) / 1000, 'sec');
|
2018-09-01 01:28:19 +02:00
|
|
|
console.log({ memo });
|
2018-01-30 23:42:38 +01:00
|
|
|
|
|
|
|
this.state = {
|
2018-10-20 23:10:21 +02:00
|
|
|
isFeeSelectionModalVisible: false,
|
2018-01-30 23:42:38 +01:00
|
|
|
fromAddress: fromAddress,
|
|
|
|
fromWallet: fromWallet,
|
2018-08-08 02:05:34 +02:00
|
|
|
fromSecret: fromSecret,
|
2018-01-30 23:42:38 +01:00
|
|
|
isLoading: true,
|
2018-03-17 21:39:21 +01:00
|
|
|
address: address,
|
2018-12-12 15:52:49 +01:00
|
|
|
amount,
|
2018-09-01 01:28:19 +02:00
|
|
|
memo,
|
2018-10-20 23:10:21 +02:00
|
|
|
fee: 1,
|
|
|
|
networkTransactionFees: new NetworkTransactionFee(1, 1, 1),
|
|
|
|
feeSliderValue: 1,
|
|
|
|
bip70TransactionExpiration: null,
|
2018-03-17 21:39:21 +01:00
|
|
|
};
|
2018-01-30 23:42:38 +01:00
|
|
|
|
2018-03-17 21:39:21 +01:00
|
|
|
let endTime = Date.now();
|
|
|
|
console.log('constructor took', (endTime - startTime) / 1000, 'sec');
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount() {
|
2018-12-11 23:52:46 +01:00
|
|
|
EV(
|
|
|
|
EV.enum.CREATE_TRANSACTION_NEW_DESTINATION_ADDRESS,
|
|
|
|
data => {
|
|
|
|
if (btcAddressRx.test(data) || data.indexOf('bc1') === 0) {
|
|
|
|
this.setState({
|
|
|
|
address: data,
|
|
|
|
bip70TransactionExpiration: null,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
let address, options;
|
|
|
|
try {
|
|
|
|
const decoded = bip21.decode(data);
|
|
|
|
address = decoded.address;
|
|
|
|
options = decoded.options;
|
|
|
|
} catch (Err) {
|
|
|
|
console.log(Err);
|
|
|
|
}
|
|
|
|
console.log(options);
|
|
|
|
if (btcAddressRx.test(address)) {
|
|
|
|
this.setState({
|
|
|
|
address,
|
|
|
|
amount: options.amount,
|
|
|
|
memo: options.label || options.message,
|
|
|
|
bip70TransactionExpiration: null,
|
|
|
|
});
|
|
|
|
} else if (BitcoinBIP70TransactionDecode.matchesPaymentURL(data)) {
|
|
|
|
BitcoinBIP70TransactionDecode.decode(data)
|
|
|
|
.then(response => {
|
|
|
|
this.setState({
|
|
|
|
address: response.address,
|
|
|
|
amount: loc.formatBalanceWithoutSuffix(response.amount, BitcoinUnit.BTC),
|
|
|
|
memo: response.memo,
|
|
|
|
fee: response.fee,
|
|
|
|
bip70TransactionExpiration: response.expires,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(error => alert(error.errorMessage));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
);
|
2018-10-20 23:10:21 +02:00
|
|
|
let recommendedFees = await NetworkTransactionFees.recommendedFees().catch(response => {
|
2018-12-11 23:52:46 +01:00
|
|
|
this.setState({
|
|
|
|
fee: response.halfHourFee,
|
|
|
|
networkTransactionFees: response,
|
|
|
|
feeSliderValue: response.halfHourFee,
|
|
|
|
isLoading: false,
|
|
|
|
});
|
2018-10-20 23:10:21 +02:00
|
|
|
});
|
2018-12-11 23:52:46 +01:00
|
|
|
if (recommendedFees) {
|
|
|
|
this.setState({
|
|
|
|
fee: recommendedFees.halfHourFee,
|
|
|
|
networkTransactionFees: recommendedFees,
|
|
|
|
feeSliderValue: recommendedFees.halfHourFee,
|
|
|
|
isLoading: false,
|
|
|
|
});
|
|
|
|
}
|
2018-03-17 21:39:21 +01:00
|
|
|
let startTime = Date.now();
|
|
|
|
console.log('send/details - componentDidMount');
|
|
|
|
let endTime = Date.now();
|
|
|
|
console.log('componentDidMount took', (endTime - startTime) / 1000, 'sec');
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
recalculateAvailableBalance(balance, amount, fee) {
|
2018-03-17 21:39:21 +01:00
|
|
|
if (!amount) amount = 0;
|
|
|
|
if (!fee) fee = 0;
|
|
|
|
let availableBalance;
|
2018-01-30 23:42:38 +01:00
|
|
|
try {
|
2018-03-17 21:39:21 +01:00
|
|
|
availableBalance = new BigNumber(balance);
|
2018-10-20 23:10:21 +02:00
|
|
|
availableBalance = availableBalance.minus(amount);
|
|
|
|
availableBalance = availableBalance.minus(fee);
|
2018-03-17 21:39:21 +01:00
|
|
|
availableBalance = availableBalance.toString(10);
|
2018-01-30 23:42:38 +01:00
|
|
|
} catch (err) {
|
2018-03-17 21:39:21 +01:00
|
|
|
return balance;
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
2018-08-18 17:49:36 +02:00
|
|
|
|
2018-03-17 21:39:21 +01:00
|
|
|
return (availableBalance === 'NaN' && balance) || availableBalance;
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
|
2018-12-11 23:52:46 +01:00
|
|
|
calculateFee(utxos, txhex, utxoIsInSatoshis) {
|
2018-11-04 22:01:40 +01:00
|
|
|
let index = {};
|
|
|
|
let c = 1;
|
|
|
|
index[0] = 0;
|
|
|
|
for (let utxo of utxos) {
|
2018-12-11 23:52:46 +01:00
|
|
|
if (!utxoIsInSatoshis) {
|
|
|
|
utxo.amount = new BigNumber(utxo.amount).multipliedBy(100000000).toNumber();
|
|
|
|
}
|
2018-11-04 22:01:40 +01:00
|
|
|
index[c] = utxo.amount + index[c - 1];
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
|
|
|
|
let tx = bitcoin.Transaction.fromHex(txhex);
|
|
|
|
let totalInput = index[tx.ins.length];
|
|
|
|
// ^^^ dumb way to calculate total input. we assume that signer uses utxos sequentially
|
|
|
|
// so total input == sum of yongest used inputs (and num of used inputs is `tx.ins.length`)
|
|
|
|
// TODO: good candidate to refactor and move to appropriate class. some day
|
|
|
|
|
|
|
|
let totalOutput = 0;
|
|
|
|
for (let o of tx.outs) {
|
|
|
|
totalOutput += o.value * 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new BigNumber(totalInput - totalOutput).dividedBy(100000000).toNumber();
|
|
|
|
}
|
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
async createTransaction() {
|
2018-10-27 21:38:22 +02:00
|
|
|
this.setState({ isLoading: true });
|
2018-10-20 23:10:21 +02:00
|
|
|
let error = false;
|
|
|
|
let requestedSatPerByte = this.state.fee.toString().replace(/\D/g, '');
|
2018-02-24 15:30:22 +01:00
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
console.log({ requestedSatPerByte });
|
2018-02-24 15:30:22 +01:00
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
if (!this.state.amount || this.state.amount === '0' || parseFloat(this.state.amount) === 0) {
|
|
|
|
error = loc.send.details.amount_field_is_not_valid;
|
|
|
|
console.log('validation error');
|
|
|
|
} else if (!this.state.fee || !requestedSatPerByte || parseFloat(requestedSatPerByte) < 1) {
|
|
|
|
error = loc.send.details.fee_field_is_not_valid;
|
|
|
|
console.log('validation error');
|
|
|
|
} else if (!this.state.address) {
|
|
|
|
error = loc.send.details.address_field_is_not_valid;
|
|
|
|
console.log('validation error');
|
|
|
|
} else if (this.recalculateAvailableBalance(this.state.fromWallet.getBalance(), this.state.amount, 0) < 0) {
|
|
|
|
// first sanity check is that sending amount is not bigger than available balance
|
|
|
|
error = loc.send.details.total_exceeds_balance;
|
|
|
|
console.log('validation error');
|
|
|
|
} else if (BitcoinBIP70TransactionDecode.isExpired(this.state.bip70TransactionExpiration)) {
|
|
|
|
error = 'Transaction has expired.';
|
2018-02-24 15:30:22 +01:00
|
|
|
console.log('validation error');
|
|
|
|
}
|
|
|
|
|
2018-10-27 21:38:22 +02:00
|
|
|
try {
|
|
|
|
bitcoin.address.toOutputScript(this.state.address);
|
|
|
|
} catch (err) {
|
|
|
|
console.log('validation error');
|
|
|
|
console.log(err);
|
|
|
|
error = loc.send.details.address_field_is_not_valid;
|
|
|
|
}
|
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
if (error) {
|
2018-10-27 21:38:22 +02:00
|
|
|
this.setState({ isLoading: false });
|
2018-10-20 23:10:21 +02:00
|
|
|
alert(error);
|
2018-12-13 17:50:18 +01:00
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', false);
|
2018-08-18 17:49:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
this.setState({ isLoading: true }, async () => {
|
|
|
|
let utxo;
|
|
|
|
let actualSatoshiPerByte;
|
|
|
|
let tx, txid;
|
|
|
|
let tries = 1;
|
|
|
|
let fee = 0.000001; // initial fee guess
|
|
|
|
|
|
|
|
try {
|
|
|
|
await this.state.fromWallet.fetchUtxo();
|
|
|
|
if (this.state.fromWallet.getChangeAddressAsync) {
|
|
|
|
await this.state.fromWallet.getChangeAddressAsync(); // to refresh internal pointer to next free address
|
|
|
|
}
|
|
|
|
if (this.state.fromWallet.getAddressAsync) {
|
|
|
|
await this.state.fromWallet.getAddressAsync(); // to refresh internal pointer to next free address
|
|
|
|
}
|
|
|
|
|
|
|
|
utxo = this.state.fromWallet.utxo;
|
|
|
|
|
|
|
|
do {
|
|
|
|
console.log('try #', tries, 'fee=', fee);
|
|
|
|
if (this.recalculateAvailableBalance(this.state.fromWallet.getBalance(), this.state.amount, fee) < 0) {
|
|
|
|
// we could not add any fee. user is trying to send all he's got. that wont work
|
|
|
|
throw new Error(loc.send.details.total_exceeds_balance);
|
|
|
|
}
|
|
|
|
|
|
|
|
let startTime = Date.now();
|
2018-10-27 21:38:22 +02:00
|
|
|
tx = this.state.fromWallet.createTx(utxo, this.state.amount, fee, this.state.address, this.state.memo);
|
2018-10-20 23:10:21 +02:00
|
|
|
let endTime = Date.now();
|
|
|
|
console.log('create tx ', (endTime - startTime) / 1000, 'sec');
|
2018-02-24 15:30:22 +01:00
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
let txDecoded = bitcoin.Transaction.fromHex(tx);
|
|
|
|
txid = txDecoded.getId();
|
|
|
|
console.log('txid', txid);
|
|
|
|
console.log('txhex', tx);
|
|
|
|
|
|
|
|
let feeSatoshi = new BigNumber(fee).multipliedBy(100000000);
|
|
|
|
actualSatoshiPerByte = feeSatoshi.dividedBy(Math.round(tx.length / 2));
|
|
|
|
actualSatoshiPerByte = actualSatoshiPerByte.toNumber();
|
|
|
|
console.log({ satoshiPerByte: actualSatoshiPerByte });
|
|
|
|
|
|
|
|
if (Math.round(actualSatoshiPerByte) !== requestedSatPerByte * 1 || Math.floor(actualSatoshiPerByte) < 1) {
|
|
|
|
console.log('fee is not correct, retrying');
|
|
|
|
fee = feeSatoshi
|
|
|
|
.multipliedBy(requestedSatPerByte / actualSatoshiPerByte)
|
|
|
|
.plus(10)
|
|
|
|
.dividedBy(100000000)
|
|
|
|
.toNumber();
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (tries++ < 5);
|
|
|
|
|
|
|
|
BlueApp.tx_metadata = BlueApp.tx_metadata || {};
|
|
|
|
BlueApp.tx_metadata[txid] = {
|
|
|
|
txhex: tx,
|
|
|
|
memo: this.state.memo,
|
|
|
|
};
|
|
|
|
await BlueApp.saveToDisk();
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
2018-12-13 17:50:18 +01:00
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', false);
|
2018-10-27 21:38:22 +02:00
|
|
|
alert(err);
|
2018-10-20 23:10:21 +02:00
|
|
|
this.setState({ isLoading: false });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({ isLoading: false }, () =>
|
2018-10-27 17:13:09 +02:00
|
|
|
this.props.navigation.navigate('Confirm', {
|
2018-10-20 23:10:21 +02:00
|
|
|
amount: this.state.amount,
|
2018-12-11 23:52:46 +01:00
|
|
|
// HD wallet's utxo is in sats, classic segwit wallet utxos are in btc
|
|
|
|
fee: this.calculateFee(utxo, tx, this.state.fromWallet.type === new HDSegwitP2SHWallet().type),
|
2018-10-20 23:10:21 +02:00
|
|
|
address: this.state.address,
|
|
|
|
memo: this.state.memo,
|
|
|
|
fromWallet: this.state.fromWallet,
|
|
|
|
tx: tx,
|
|
|
|
satoshiPerByte: actualSatoshiPerByte.toFixed(2),
|
|
|
|
}),
|
|
|
|
);
|
2018-03-17 21:39:21 +01:00
|
|
|
});
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
renderFeeSelectionModal = () => {
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
isVisible={this.state.isFeeSelectionModalVisible}
|
|
|
|
style={styles.bottomModal}
|
|
|
|
onBackdropPress={() => this.setState({ isFeeSelectionModalVisible: false })}
|
|
|
|
>
|
2018-12-11 23:52:46 +01:00
|
|
|
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'position' : null}>
|
2018-10-20 23:10:21 +02:00
|
|
|
<View style={styles.modalContent}>
|
|
|
|
<TouchableOpacity style={styles.satoshisTextInput} onPress={() => this.textInput.focus()}>
|
|
|
|
<TextInput
|
|
|
|
keyboardType="numeric"
|
|
|
|
ref={ref => {
|
|
|
|
this.textInput = ref;
|
|
|
|
}}
|
|
|
|
value={this.state.fee.toString()}
|
|
|
|
onChangeText={value => {
|
|
|
|
let newValue = value.replace(/\D/g, '');
|
|
|
|
if (newValue.length === 0) {
|
|
|
|
newValue = 1;
|
|
|
|
}
|
|
|
|
this.setState({ fee: newValue, feeSliderValue: newValue });
|
|
|
|
}}
|
|
|
|
maxLength={9}
|
|
|
|
editable={!this.state.isLoading}
|
|
|
|
placeholderTextColor="#37c0a1"
|
|
|
|
placeholder={this.state.networkTransactionFees.halfHourFee.toString()}
|
|
|
|
style={{ fontWeight: '600', color: '#37c0a1', marginBottom: 0, marginRight: 4, textAlign: 'right', fontSize: 36 }}
|
|
|
|
/>
|
|
|
|
<Text
|
|
|
|
style={{
|
|
|
|
fontWeight: '600',
|
|
|
|
color: '#37c0a1',
|
|
|
|
paddingRight: 4,
|
|
|
|
textAlign: 'left',
|
|
|
|
fontSize: 16,
|
|
|
|
alignSelf: 'flex-end',
|
|
|
|
marginBottom: 14,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
sat/b
|
|
|
|
</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
{this.state.networkTransactionFees.fastestFee > 1 && (
|
|
|
|
<View style={{ flex: 1, marginTop: 32, minWidth: 240, width: 240 }}>
|
|
|
|
<Slider
|
2018-12-12 17:24:23 +01:00
|
|
|
onValueChange={value => this.setState({ feeSliderValue: value.toFixed(0), fee: value.toFixed(0) })}
|
2018-10-20 23:10:21 +02:00
|
|
|
minimumValue={1}
|
|
|
|
maximumValue={this.state.networkTransactionFees.fastestFee}
|
|
|
|
value={Number(this.state.feeSliderValue)}
|
|
|
|
maximumTrackTintColor="#d8d8d8"
|
|
|
|
minimumTrackTintColor="#37c0a1"
|
|
|
|
style={{ flex: 1 }}
|
|
|
|
/>
|
|
|
|
<View style={{ flex: 1, flexDirection: 'row', justifyContent: 'space-between', marginTop: 14 }}>
|
|
|
|
<Text style={{ fontWeight: '500', fontSize: 13, color: '#37c0a1' }}>slow</Text>
|
|
|
|
<Text style={{ fontWeight: '500', fontSize: 13, color: '#37c0a1' }}>fast</Text>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
)}
|
|
|
|
</View>
|
|
|
|
</KeyboardAvoidingView>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
renderCreateButton = () => {
|
|
|
|
return (
|
|
|
|
<View style={{ paddingHorizontal: 56, paddingVertical: 16, alignContent: 'center', backgroundColor: '#FFFFFF' }}>
|
|
|
|
{this.state.isLoading ? (
|
2018-01-30 23:42:38 +01:00
|
|
|
<ActivityIndicator />
|
2018-10-20 23:10:21 +02:00
|
|
|
) : (
|
|
|
|
<BlueButton onPress={() => this.createTransaction()} title={loc.send.details.create} />
|
|
|
|
)}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
2018-01-30 23:42:38 +01:00
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
render() {
|
2018-01-30 23:42:38 +01:00
|
|
|
if (!this.state.fromWallet.getAddress) {
|
|
|
|
return (
|
2018-03-17 21:39:21 +01:00
|
|
|
<View style={{ flex: 1, paddingTop: 20 }}>
|
2018-07-07 15:04:32 +02:00
|
|
|
<Text>System error: Source wallet not found (this should never happen)</Text>
|
2018-01-30 23:42:38 +01:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2018-10-20 23:10:21 +02:00
|
|
|
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
|
|
|
|
<View style={{ flex: 1, backgroundColor: '#FFFFFF' }}>
|
|
|
|
<KeyboardAvoidingView behavior="position">
|
|
|
|
<View style={{ flexDirection: 'row', justifyContent: 'center', paddingTop: 16, paddingBottom: 16 }}>
|
|
|
|
<TextInput
|
|
|
|
keyboardType="numeric"
|
|
|
|
onChangeText={text => this.setState({ amount: text.replace(',', '.') })}
|
|
|
|
placeholder="0"
|
|
|
|
maxLength={10}
|
|
|
|
editable={!this.state.isLoading}
|
|
|
|
value={this.state.amount + ''}
|
|
|
|
placeholderTextColor="#0f5cc0"
|
|
|
|
style={{
|
|
|
|
color: '#0f5cc0',
|
|
|
|
fontSize: 36,
|
|
|
|
fontWeight: '600',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Text
|
|
|
|
style={{
|
|
|
|
color: '#0f5cc0',
|
|
|
|
fontSize: 16,
|
|
|
|
marginHorizontal: 4,
|
|
|
|
paddingBottom: 6,
|
|
|
|
fontWeight: '600',
|
|
|
|
alignSelf: 'flex-end',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{' ' + BitcoinUnit.BTC}
|
|
|
|
</Text>
|
|
|
|
</View>
|
2018-10-27 17:13:09 +02:00
|
|
|
<View style={{ alignItems: 'center', marginBottom: 22, marginTop: 4 }}>
|
|
|
|
<Text style={{ fontSize: 18, color: '#d4d4d4', fontWeight: '600' }}>
|
|
|
|
{currency.satoshiToLocalCurrency(loc.formatBalanceWithoutSuffix(this.state.amount || 0, BitcoinUnit.SATOSHIS))}
|
|
|
|
</Text>
|
|
|
|
</View>
|
2018-10-20 23:10:21 +02:00
|
|
|
<View
|
|
|
|
style={{
|
|
|
|
flexDirection: 'row',
|
|
|
|
borderColor: '#d2d2d2',
|
|
|
|
borderBottomColor: '#d2d2d2',
|
|
|
|
borderWidth: 1.0,
|
|
|
|
borderBottomWidth: 0.5,
|
|
|
|
backgroundColor: '#f5f5f5',
|
|
|
|
minHeight: 44,
|
|
|
|
height: 44,
|
|
|
|
marginHorizontal: 20,
|
|
|
|
alignItems: 'center',
|
|
|
|
marginVertical: 8,
|
|
|
|
borderRadius: 4,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
onChangeText={text => {
|
|
|
|
if (BitcoinBIP70TransactionDecode.matchesPaymentURL(text)) {
|
|
|
|
this.setState(
|
|
|
|
{
|
|
|
|
isLoading: true,
|
|
|
|
},
|
|
|
|
() => {
|
2018-10-23 00:51:30 +02:00
|
|
|
Keyboard.dismiss();
|
2018-10-20 23:10:21 +02:00
|
|
|
BitcoinBIP70TransactionDecode.decode(text).then(response => {
|
|
|
|
this.setState({
|
|
|
|
address: response.address,
|
|
|
|
amount: loc.formatBalanceWithoutSuffix(response.amount, BitcoinUnit.BTC),
|
|
|
|
memo: response.memo,
|
|
|
|
fee: response.fee,
|
|
|
|
bip70TransactionExpiration: response.expires,
|
|
|
|
isLoading: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.setState({ address: text.replace(' ', ''), isLoading: false, bip70TransactionExpiration: null });
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
placeholder={loc.send.details.address}
|
|
|
|
numberOfLines={1}
|
|
|
|
value={this.state.address}
|
2018-12-11 23:52:46 +01:00
|
|
|
style={{ flex: 1, marginHorizontal: 8, minHeight: 33 }}
|
2018-10-20 23:10:21 +02:00
|
|
|
editable={!this.state.isLoading}
|
|
|
|
/>
|
|
|
|
<TouchableOpacity
|
|
|
|
disabled={this.state.isLoading}
|
|
|
|
onPress={() => this.props.navigation.navigate('ScanQrAddress')}
|
|
|
|
style={{
|
|
|
|
width: 75,
|
|
|
|
height: 36,
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
backgroundColor: '#bebebe',
|
|
|
|
borderRadius: 4,
|
|
|
|
paddingVertical: 4,
|
|
|
|
paddingHorizontal: 8,
|
|
|
|
marginHorizontal: 4,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Icon name="qrcode" size={22} type="font-awesome" color="#FFFFFF" />
|
|
|
|
<Text style={{ color: '#FFFFFF' }}>{loc.send.details.scan}</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
|
|
|
<View
|
|
|
|
hide={!this.state.showMemoRow}
|
|
|
|
style={{
|
|
|
|
flexDirection: 'row',
|
|
|
|
borderColor: '#d2d2d2',
|
|
|
|
borderBottomColor: '#d2d2d2',
|
|
|
|
borderWidth: 1.0,
|
|
|
|
borderBottomWidth: 0.5,
|
|
|
|
backgroundColor: '#f5f5f5',
|
|
|
|
minHeight: 44,
|
|
|
|
height: 44,
|
|
|
|
marginHorizontal: 20,
|
|
|
|
alignItems: 'center',
|
|
|
|
marginVertical: 8,
|
|
|
|
borderRadius: 4,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
onChangeText={text => this.setState({ memo: text })}
|
|
|
|
placeholder={loc.send.details.note_placeholder}
|
|
|
|
value={this.state.memo}
|
|
|
|
numberOfLines={1}
|
2018-12-11 23:52:46 +01:00
|
|
|
style={{ flex: 1, marginHorizontal: 8, minHeight: 33 }}
|
2018-10-20 23:10:21 +02:00
|
|
|
editable={!this.state.isLoading}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
<TouchableOpacity
|
|
|
|
onPress={() => this.setState({ isFeeSelectionModalVisible: true })}
|
|
|
|
disabled={this.state.isLoading}
|
|
|
|
style={{ flexDirection: 'row', marginHorizontal: 20, justifyContent: 'space-between', alignItems: 'center' }}
|
|
|
|
>
|
|
|
|
<Text style={{ color: '#81868e', fontSize: 14 }}>Fee</Text>
|
|
|
|
<View
|
|
|
|
style={{
|
|
|
|
backgroundColor: '#d2f8d6',
|
|
|
|
minWidth: 40,
|
|
|
|
height: 25,
|
|
|
|
borderRadius: 4,
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
paddingHorizontal: 10,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Text style={{ color: '#37c0a1', marginBottom: 0, marginRight: 4, textAlign: 'right' }}>{this.state.fee}</Text>
|
|
|
|
<Text style={{ color: '#37c0a1', paddingRight: 4, textAlign: 'left' }}>sat/b</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
{this.renderCreateButton()}
|
|
|
|
{this.renderFeeSelectionModal()}
|
|
|
|
</KeyboardAvoidingView>
|
2018-01-30 23:42:38 +01:00
|
|
|
</View>
|
2018-10-20 23:10:21 +02:00
|
|
|
</TouchableWithoutFeedback>
|
2018-01-30 23:42:38 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-03-18 03:48:23 +01:00
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
modalContent: {
|
|
|
|
backgroundColor: '#FFFFFF',
|
|
|
|
padding: 22,
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
|
|
|
borderTopLeftRadius: 16,
|
|
|
|
borderTopRightRadius: 16,
|
|
|
|
borderColor: 'rgba(0, 0, 0, 0.1)',
|
|
|
|
minHeight: 200,
|
|
|
|
height: 200,
|
|
|
|
},
|
|
|
|
bottomModal: {
|
|
|
|
justifyContent: 'flex-end',
|
|
|
|
margin: 0,
|
|
|
|
},
|
|
|
|
satoshisTextInput: {
|
|
|
|
backgroundColor: '#d2f8d6',
|
|
|
|
minWidth: 127,
|
|
|
|
height: 60,
|
|
|
|
borderRadius: 8,
|
|
|
|
flexDirection: 'row',
|
|
|
|
justifyContent: 'center',
|
|
|
|
paddingHorizontal: 8,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-03-18 03:48:23 +01:00
|
|
|
SendDetails.propTypes = {
|
|
|
|
navigation: PropTypes.shape({
|
|
|
|
goBack: PropTypes.function,
|
|
|
|
navigate: PropTypes.func,
|
|
|
|
state: PropTypes.shape({
|
|
|
|
params: PropTypes.shape({
|
|
|
|
address: PropTypes.string,
|
|
|
|
fromAddress: PropTypes.string,
|
2018-10-27 17:13:09 +02:00
|
|
|
satoshiPerByte: PropTypes.string,
|
|
|
|
fromSecret: PropTypes.fromSecret,
|
2018-09-01 01:28:19 +02:00
|
|
|
memo: PropTypes.string,
|
2018-12-12 15:52:49 +01:00
|
|
|
uri: PropTypes.string,
|
2018-03-18 03:48:23 +01:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
};
|