2018-10-20 23:10:21 +02:00
|
|
|
/* global alert */
|
2018-01-30 23:42:38 +01:00
|
|
|
import React, { Component } from 'react';
|
2020-07-20 15:38:46 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2018-03-17 21:39:21 +01:00
|
|
|
import {
|
2020-06-09 16:08:18 +02:00
|
|
|
ActivityIndicator,
|
2018-10-20 23:10:21 +02:00
|
|
|
View,
|
|
|
|
TextInput,
|
2019-08-07 07:45:27 +02:00
|
|
|
Alert,
|
2019-02-14 06:21:55 +01:00
|
|
|
StatusBar,
|
2018-10-20 23:10:21 +02:00
|
|
|
TouchableOpacity,
|
|
|
|
KeyboardAvoidingView,
|
|
|
|
Keyboard,
|
|
|
|
TouchableWithoutFeedback,
|
|
|
|
StyleSheet,
|
2019-09-03 05:28:52 +02:00
|
|
|
Dimensions,
|
2018-12-11 23:52:46 +01:00
|
|
|
Platform,
|
2019-09-03 05:28:52 +02:00
|
|
|
ScrollView,
|
2018-12-24 01:44:31 +01:00
|
|
|
Text,
|
2018-10-20 23:10:21 +02:00
|
|
|
} from 'react-native';
|
2018-12-24 01:44:31 +01:00
|
|
|
import { Icon } from 'react-native-elements';
|
2019-05-02 22:33:03 +02:00
|
|
|
import AsyncStorage from '@react-native-community/async-storage';
|
2019-02-17 10:23:12 +01:00
|
|
|
import {
|
2019-09-03 05:28:52 +02:00
|
|
|
BlueCreateTxNavigationStyle,
|
2019-02-17 10:23:12 +01:00
|
|
|
BlueButton,
|
|
|
|
BlueBitcoinAmount,
|
|
|
|
BlueAddressInput,
|
|
|
|
BlueDismissKeyboardInputAccessory,
|
2020-06-09 16:08:18 +02:00
|
|
|
BlueLoading,
|
2019-08-05 17:25:36 +02:00
|
|
|
BlueUseAllFundsButton,
|
2019-09-03 05:28:52 +02:00
|
|
|
BlueListItem,
|
|
|
|
BlueText,
|
2019-02-17 10:23:12 +01:00
|
|
|
} from '../../BlueComponents';
|
2018-10-20 23:10:21 +02:00
|
|
|
import Modal from 'react-native-modal';
|
2020-07-20 15:38:46 +02:00
|
|
|
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
2020-09-14 12:49:08 +02:00
|
|
|
import BigNumber from 'bignumber.js';
|
|
|
|
import RNFS from 'react-native-fs';
|
|
|
|
import * as bitcoin from 'bitcoinjs-lib';
|
2020-07-20 15:38:46 +02:00
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
import NetworkTransactionFees, { NetworkTransactionFee } from '../../models/networkTransactionFees';
|
2019-02-26 02:33:29 +01:00
|
|
|
import { BitcoinUnit, Chain } from '../../models/bitcoinUnits';
|
2020-04-28 16:48:36 +02:00
|
|
|
import { AppStorage, HDSegwitBech32Wallet, LightningCustodianWallet, WatchOnlyWallet } from '../../class';
|
2019-09-03 05:28:52 +02:00
|
|
|
import { BitcoinTransaction } from '../../models/bitcoinTransactionInfo';
|
2020-01-01 04:31:04 +01:00
|
|
|
import DocumentPicker from 'react-native-document-picker';
|
2020-04-28 16:48:36 +02:00
|
|
|
import DeeplinkSchemaMatch from '../../class/deeplink-schema-match';
|
2020-07-20 15:38:46 +02:00
|
|
|
import loc from '../../loc';
|
2020-07-15 19:32:59 +02:00
|
|
|
import { BlueCurrentTheme } from '../../components/themes';
|
2020-06-09 16:08:18 +02:00
|
|
|
const currency = require('../../blue_modules/currency');
|
2020-06-01 14:54:23 +02:00
|
|
|
const BlueApp: AppStorage = require('../../BlueApp');
|
2020-09-14 12:49:08 +02:00
|
|
|
const prompt = require('../../blue_modules/prompt');
|
2018-01-30 23:42:38 +01:00
|
|
|
|
2018-03-24 22:24:20 +01:00
|
|
|
const btcAddressRx = /^[a-zA-Z0-9]{26,35}$/;
|
2019-02-03 10:09:46 +01:00
|
|
|
|
2020-05-24 11:17:26 +02:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
loading: {
|
|
|
|
flex: 1,
|
|
|
|
paddingTop: 20,
|
2020-07-15 19:32:59 +02:00
|
|
|
backgroundColor: BlueCurrentTheme.colors.background,
|
2020-05-24 11:17:26 +02:00
|
|
|
},
|
|
|
|
root: {
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: 'space-between',
|
2020-07-15 19:32:59 +02:00
|
|
|
backgroundColor: BlueCurrentTheme.colors.elevated,
|
2020-05-24 11:17:26 +02:00
|
|
|
},
|
|
|
|
scrollViewContent: {
|
|
|
|
flexWrap: 'wrap',
|
|
|
|
flexDirection: 'row',
|
|
|
|
},
|
|
|
|
modalContent: {
|
2020-07-15 19:32:59 +02:00
|
|
|
backgroundColor: BlueCurrentTheme.colors.modal,
|
2020-05-24 11:17:26 +02:00
|
|
|
padding: 22,
|
|
|
|
borderTopLeftRadius: 16,
|
|
|
|
borderTopRightRadius: 16,
|
2020-07-15 19:32:59 +02:00
|
|
|
borderTopColor: BlueCurrentTheme.colors.borderTopColor,
|
|
|
|
borderWidth: BlueCurrentTheme.colors.borderWidth,
|
2020-05-24 11:17:26 +02:00
|
|
|
minHeight: 200,
|
|
|
|
},
|
|
|
|
advancedTransactionOptionsModalContent: {
|
2020-07-15 19:32:59 +02:00
|
|
|
backgroundColor: BlueCurrentTheme.colors.modal,
|
2020-05-24 11:17:26 +02:00
|
|
|
padding: 22,
|
|
|
|
borderTopLeftRadius: 16,
|
|
|
|
borderTopRightRadius: 16,
|
2020-07-15 19:32:59 +02:00
|
|
|
borderTopColor: BlueCurrentTheme.colors.borderTopColor,
|
|
|
|
borderWidth: BlueCurrentTheme.colors.borderWidth,
|
2020-05-24 11:17:26 +02:00
|
|
|
minHeight: 130,
|
|
|
|
},
|
|
|
|
bottomModal: {
|
|
|
|
justifyContent: 'flex-end',
|
|
|
|
margin: 0,
|
|
|
|
},
|
2020-09-14 12:49:08 +02:00
|
|
|
feeModalItem: {
|
|
|
|
paddingHorizontal: 16,
|
|
|
|
paddingVertical: 8,
|
|
|
|
marginBottom: 10,
|
|
|
|
},
|
|
|
|
feeModalItemActive: {
|
2020-05-24 11:17:26 +02:00
|
|
|
borderRadius: 8,
|
2020-09-14 12:49:08 +02:00
|
|
|
backgroundColor: BlueCurrentTheme.colors.feeLabel,
|
|
|
|
},
|
|
|
|
feeModalRow: {
|
|
|
|
justifyContent: 'space-between',
|
2020-05-24 11:17:26 +02:00
|
|
|
flexDirection: 'row',
|
2020-09-14 12:49:08 +02:00
|
|
|
alignItems: 'center',
|
2020-05-24 11:17:26 +02:00
|
|
|
},
|
2020-09-14 12:49:08 +02:00
|
|
|
feeModalLabel: {
|
|
|
|
fontSize: 22,
|
|
|
|
color: BlueCurrentTheme.colors.successColor,
|
2020-05-24 11:17:26 +02:00
|
|
|
fontWeight: '600',
|
|
|
|
},
|
2020-09-14 12:49:08 +02:00
|
|
|
feeModalTime: {
|
|
|
|
backgroundColor: BlueCurrentTheme.colors.successColor,
|
|
|
|
borderRadius: 5,
|
|
|
|
paddingHorizontal: 6,
|
|
|
|
paddingVertical: 3,
|
2020-05-24 11:17:26 +02:00
|
|
|
},
|
2020-09-14 12:49:08 +02:00
|
|
|
feeModalTimeText: {
|
|
|
|
color: BlueCurrentTheme.colors.background,
|
2020-05-24 11:17:26 +02:00
|
|
|
},
|
2020-09-14 12:49:08 +02:00
|
|
|
feeModalValue: {
|
|
|
|
color: BlueCurrentTheme.colors.successColor,
|
2020-05-24 11:17:26 +02:00
|
|
|
},
|
2020-09-14 12:49:08 +02:00
|
|
|
feeModalCustom: {
|
|
|
|
height: 60,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
2020-05-24 11:17:26 +02:00
|
|
|
},
|
2020-09-14 12:49:08 +02:00
|
|
|
feeModalCustomText: {
|
|
|
|
color: BlueCurrentTheme.colors.buttonAlternativeTextColor,
|
|
|
|
fontSize: 15,
|
|
|
|
fontWeight: '600',
|
2020-05-24 11:17:26 +02:00
|
|
|
},
|
|
|
|
createButton: {
|
|
|
|
marginHorizontal: 56,
|
|
|
|
marginVertical: 16,
|
2020-09-07 03:36:59 +02:00
|
|
|
alignItems: 'center',
|
2020-05-24 11:17:26 +02:00
|
|
|
minHeight: 44,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
marginBottom: 24,
|
|
|
|
alignItems: 'center',
|
|
|
|
},
|
|
|
|
selectTouch: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
},
|
|
|
|
selectText: {
|
|
|
|
color: '#9aa0aa',
|
|
|
|
fontSize: 14,
|
|
|
|
marginRight: 8,
|
|
|
|
},
|
|
|
|
selectWrap: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
marginVertical: 4,
|
|
|
|
},
|
|
|
|
selectLabel: {
|
2020-07-15 19:32:59 +02:00
|
|
|
color: BlueCurrentTheme.colors.buttonTextColor,
|
2020-05-24 11:17:26 +02:00
|
|
|
fontSize: 14,
|
|
|
|
},
|
|
|
|
of: {
|
|
|
|
alignSelf: 'flex-end',
|
|
|
|
marginRight: 18,
|
|
|
|
marginVertical: 8,
|
2020-07-15 19:32:59 +02:00
|
|
|
color: BlueCurrentTheme.colors.feeText,
|
2020-05-24 11:17:26 +02:00
|
|
|
},
|
|
|
|
memo: {
|
|
|
|
flexDirection: 'row',
|
2020-07-15 19:32:59 +02:00
|
|
|
borderColor: BlueCurrentTheme.colors.formBorder,
|
|
|
|
borderBottomColor: BlueCurrentTheme.colors.formBorder,
|
2020-05-24 11:17:26 +02:00
|
|
|
borderWidth: 1,
|
|
|
|
borderBottomWidth: 0.5,
|
2020-07-15 19:32:59 +02:00
|
|
|
backgroundColor: BlueCurrentTheme.colors.inputBackgroundColor,
|
2020-05-24 11:17:26 +02:00
|
|
|
minHeight: 44,
|
|
|
|
height: 44,
|
|
|
|
marginHorizontal: 20,
|
|
|
|
alignItems: 'center',
|
|
|
|
marginVertical: 8,
|
|
|
|
borderRadius: 4,
|
|
|
|
},
|
|
|
|
memoText: {
|
|
|
|
flex: 1,
|
|
|
|
marginHorizontal: 8,
|
|
|
|
minHeight: 33,
|
2020-06-09 14:23:21 +02:00
|
|
|
color: '#81868e',
|
2020-05-24 11:17:26 +02:00
|
|
|
},
|
|
|
|
fee: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
marginHorizontal: 20,
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
alignItems: 'center',
|
|
|
|
},
|
|
|
|
feeLabel: {
|
2020-07-15 19:32:59 +02:00
|
|
|
color: BlueCurrentTheme.colors.feeText,
|
2020-05-24 11:17:26 +02:00
|
|
|
fontSize: 14,
|
|
|
|
},
|
|
|
|
feeRow: {
|
2020-07-15 19:32:59 +02:00
|
|
|
backgroundColor: BlueCurrentTheme.colors.feeLabel,
|
2020-05-24 11:17:26 +02:00
|
|
|
minWidth: 40,
|
|
|
|
height: 25,
|
|
|
|
borderRadius: 4,
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
paddingHorizontal: 10,
|
|
|
|
},
|
|
|
|
feeValue: {
|
2020-07-15 19:32:59 +02:00
|
|
|
color: BlueCurrentTheme.colors.feeValue,
|
2020-05-24 11:17:26 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-01-30 23:42:38 +01:00
|
|
|
export default class SendDetails extends Component {
|
2020-01-01 04:31:04 +01:00
|
|
|
state = { isLoading: true };
|
|
|
|
|
2018-01-30 23:42:38 +01:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2019-09-03 05:28:52 +02:00
|
|
|
|
2020-01-01 04:31:04 +01:00
|
|
|
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow);
|
|
|
|
this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide);
|
|
|
|
|
2020-04-28 16:48:36 +02:00
|
|
|
/** @type {LegacyWallet} */
|
2018-12-12 15:52:49 +01:00
|
|
|
let fromWallet = null;
|
2020-05-27 13:12:17 +02:00
|
|
|
if (props.route.params) fromWallet = props.route.params.fromWallet;
|
2018-12-12 15:52:49 +01:00
|
|
|
|
2019-02-21 02:16:48 +01:00
|
|
|
const wallets = BlueApp.getWallets().filter(wallet => wallet.type !== LightningCustodianWallet.type);
|
2018-03-17 21:39:21 +01:00
|
|
|
|
2019-02-18 08:25:27 +01:00
|
|
|
if (wallets.length === 0) {
|
2020-07-20 15:38:46 +02:00
|
|
|
alert(loc.send.details_wallet_before_tx);
|
2019-02-18 08:25:27 +01:00
|
|
|
return props.navigation.goBack(null);
|
|
|
|
} else {
|
2019-02-21 02:16:48 +01:00
|
|
|
if (!fromWallet && wallets.length > 0) {
|
|
|
|
fromWallet = wallets[0];
|
|
|
|
}
|
2019-02-18 08:25:27 +01:00
|
|
|
this.state = {
|
2019-08-06 00:25:36 +02:00
|
|
|
isLoading: false,
|
2019-08-04 21:33:15 +02:00
|
|
|
showSendMax: false,
|
2019-02-18 08:25:27 +01:00
|
|
|
isFeeSelectionModalVisible: false,
|
2019-09-03 05:28:52 +02:00
|
|
|
isAdvancedTransactionOptionsVisible: false,
|
2019-12-11 05:13:40 +01:00
|
|
|
isTransactionReplaceable: fromWallet.type === HDSegwitBech32Wallet.type,
|
2019-09-03 05:28:52 +02:00
|
|
|
recipientsScrollIndex: 0,
|
2019-02-18 08:25:27 +01:00
|
|
|
fromWallet,
|
2019-09-03 05:28:52 +02:00
|
|
|
addresses: [],
|
2020-06-09 16:08:18 +02:00
|
|
|
units: [],
|
2019-09-03 05:28:52 +02:00
|
|
|
memo: '',
|
2019-02-18 08:25:27 +01:00
|
|
|
networkTransactionFees: new NetworkTransactionFee(1, 1, 1),
|
2020-09-14 12:49:08 +02:00
|
|
|
fee: '1',
|
|
|
|
feePrecalc: {
|
|
|
|
current: null,
|
|
|
|
slowFee: null,
|
|
|
|
mediumFee: null,
|
|
|
|
fastestFee: null,
|
|
|
|
},
|
|
|
|
feeUnit: fromWallet.getPreferredBalanceUnit(),
|
2020-06-09 16:08:18 +02:00
|
|
|
amountUnit: fromWallet.preferredBalanceUnit, // default for whole screen
|
2019-02-18 08:25:27 +01:00
|
|
|
renderWalletSelectionButtonHidden: false,
|
2020-09-08 18:06:41 +02:00
|
|
|
width: Dimensions.get('window').width - 320,
|
2019-02-18 08:25:27 +01:00
|
|
|
};
|
|
|
|
}
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
|
2019-09-03 05:28:52 +02:00
|
|
|
renderNavigationHeader() {
|
|
|
|
this.props.navigation.setParams({
|
2019-11-10 21:25:28 +01:00
|
|
|
withAdvancedOptionsMenuButton: this.state.fromWallet.allowBatchSend() || this.state.fromWallet.allowSendMax(),
|
2019-09-03 05:28:52 +02:00
|
|
|
advancedOptionsMenuButtonAction: () => {
|
|
|
|
Keyboard.dismiss();
|
|
|
|
this.setState({ isAdvancedTransactionOptionsVisible: true });
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-02-10 21:50:41 +01:00
|
|
|
/**
|
|
|
|
* TODO: refactor this mess, get rid of regexp, use https://github.com/bitcoinjs/bitcoinjs-lib/issues/890 etc etc
|
|
|
|
*
|
|
|
|
* @param data {String} Can be address or `bitcoin:xxxxxxx` uri scheme, or invalid garbage
|
|
|
|
*/
|
2019-01-24 08:36:01 +01:00
|
|
|
processAddressData = data => {
|
2019-09-03 05:28:52 +02:00
|
|
|
this.setState({ isLoading: true }, async () => {
|
2020-06-15 03:15:58 +02:00
|
|
|
const recipients = this.state.addresses;
|
|
|
|
const dataWithoutSchema = data.replace('bitcoin:', '').replace('BITCOIN:', '');
|
|
|
|
if (this.state.fromWallet.isAddressValid(dataWithoutSchema)) {
|
|
|
|
recipients[[this.state.recipientsScrollIndex]].address = dataWithoutSchema;
|
|
|
|
const units = this.state.units;
|
|
|
|
units[this.state.recipientsScrollIndex] = BitcoinUnit.BTC; // also resetting current unit to BTC
|
2019-09-03 05:28:52 +02:00
|
|
|
this.setState({
|
2020-06-15 03:15:58 +02:00
|
|
|
address: recipients,
|
2019-10-12 01:19:08 +02:00
|
|
|
isLoading: false,
|
2020-06-09 16:08:18 +02:00
|
|
|
amountUnit: BitcoinUnit.BTC,
|
2020-06-15 03:15:58 +02:00
|
|
|
units,
|
2019-09-03 05:28:52 +02:00
|
|
|
});
|
|
|
|
} else {
|
2020-06-15 03:15:58 +02:00
|
|
|
let address = '';
|
|
|
|
let options;
|
|
|
|
try {
|
|
|
|
if (!data.toLowerCase().startsWith('bitcoin:')) {
|
|
|
|
data = `bitcoin:${data}`;
|
|
|
|
}
|
|
|
|
const decoded = DeeplinkSchemaMatch.bip21decode(data);
|
|
|
|
address = decoded.address;
|
|
|
|
options = decoded.options;
|
|
|
|
} catch (error) {
|
|
|
|
data = data.replace(/(amount)=([^&]+)/g, '').replace(/(amount)=([^&]+)&/g, '');
|
|
|
|
const decoded = DeeplinkSchemaMatch.bip21decode(data);
|
|
|
|
decoded.options.amount = 0;
|
|
|
|
address = decoded.address;
|
|
|
|
options = decoded.options;
|
|
|
|
this.setState({ isLoading: false });
|
|
|
|
}
|
|
|
|
console.log(options);
|
|
|
|
if (btcAddressRx.test(address) || address.indexOf('bc1') === 0 || address.indexOf('BC1') === 0) {
|
2020-06-09 16:08:18 +02:00
|
|
|
const units = this.state.units;
|
|
|
|
units[this.state.recipientsScrollIndex] = BitcoinUnit.BTC; // also resetting current unit to BTC
|
2020-06-15 03:15:58 +02:00
|
|
|
recipients[[this.state.recipientsScrollIndex]].address = address;
|
|
|
|
recipients[[this.state.recipientsScrollIndex]].amount = options.amount;
|
2019-09-03 05:28:52 +02:00
|
|
|
this.setState({
|
2020-06-15 03:15:58 +02:00
|
|
|
addresses: recipients,
|
|
|
|
memo: options.label || options.message,
|
2019-09-03 05:28:52 +02:00
|
|
|
isLoading: false,
|
2020-06-09 16:08:18 +02:00
|
|
|
amountUnit: BitcoinUnit.BTC,
|
|
|
|
units,
|
2019-09-03 05:28:52 +02:00
|
|
|
});
|
2019-01-24 08:36:01 +01:00
|
|
|
} else {
|
2020-06-15 03:15:58 +02:00
|
|
|
this.setState({ isLoading: false });
|
2019-01-24 08:36:01 +01:00
|
|
|
}
|
2019-09-03 05:28:52 +02:00
|
|
|
}
|
|
|
|
});
|
2019-01-24 08:36:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
async componentDidMount() {
|
2019-09-03 05:28:52 +02:00
|
|
|
this.renderNavigationHeader();
|
2019-07-19 02:22:26 +02:00
|
|
|
console.log('send/details - componentDidMount');
|
2020-06-09 16:08:18 +02:00
|
|
|
/** @type {BitcoinTransaction[]} */
|
2020-06-01 14:54:23 +02:00
|
|
|
const addresses = [];
|
2019-09-03 05:28:52 +02:00
|
|
|
let initialMemo = '';
|
2020-05-27 13:12:17 +02:00
|
|
|
if (this.props.route.params.uri) {
|
|
|
|
const uri = this.props.route.params.uri;
|
2020-06-15 03:15:58 +02:00
|
|
|
try {
|
|
|
|
const { address, amount, memo } = this.decodeBitcoinUri(uri);
|
|
|
|
addresses.push(new BitcoinTransaction(address, amount, currency.btcToSatoshi(amount)));
|
2019-09-03 05:28:52 +02:00
|
|
|
initialMemo = memo;
|
2020-06-15 03:15:58 +02:00
|
|
|
this.setState({ addresses, memo: initialMemo, isLoading: false, amountUnit: BitcoinUnit.BTC });
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
2020-07-20 15:38:46 +02:00
|
|
|
alert(loc.send.details_error_decode);
|
2019-09-03 05:28:52 +02:00
|
|
|
}
|
2020-05-27 13:12:17 +02:00
|
|
|
} else if (this.props.route.params.address) {
|
|
|
|
addresses.push(new BitcoinTransaction(this.props.route.params.address));
|
|
|
|
if (this.props.route.params.memo) initialMemo = this.props.route.params.memo;
|
2020-06-09 16:08:18 +02:00
|
|
|
this.setState({ addresses, memo: initialMemo, isLoading: false, amountUnit: BitcoinUnit.BTC });
|
2019-09-03 05:28:52 +02:00
|
|
|
} else {
|
|
|
|
this.setState({ addresses: [new BitcoinTransaction()], isLoading: false });
|
|
|
|
}
|
|
|
|
|
2019-02-01 07:58:12 +01:00
|
|
|
try {
|
|
|
|
const cachedNetworkTransactionFees = JSON.parse(await AsyncStorage.getItem(NetworkTransactionFee.StorageKey));
|
2019-02-01 07:19:09 +01:00
|
|
|
|
2020-09-14 12:49:08 +02:00
|
|
|
if (cachedNetworkTransactionFees && 'fastestFee' in cachedNetworkTransactionFees) {
|
2019-02-01 07:58:12 +01:00
|
|
|
this.setState({
|
2020-09-14 12:49:08 +02:00
|
|
|
fee: cachedNetworkTransactionFees.fastestFee.toString(),
|
2019-02-01 07:58:12 +01:00
|
|
|
networkTransactionFees: cachedNetworkTransactionFees,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (_) {}
|
2019-02-01 07:19:09 +01:00
|
|
|
|
2020-09-14 12:49:08 +02:00
|
|
|
await this.reCalcTx();
|
|
|
|
|
2019-09-03 05:28:52 +02:00
|
|
|
try {
|
2020-06-01 14:54:23 +02:00
|
|
|
const recommendedFees = await NetworkTransactionFees.recommendedFees();
|
|
|
|
if (recommendedFees && 'fastestFee' in recommendedFees) {
|
2019-09-03 05:28:52 +02:00
|
|
|
await AsyncStorage.setItem(NetworkTransactionFee.StorageKey, JSON.stringify(recommendedFees));
|
|
|
|
this.setState({
|
2020-09-14 12:49:08 +02:00
|
|
|
fee: recommendedFees.fastestFee.toString(),
|
2019-09-03 05:28:52 +02:00
|
|
|
networkTransactionFees: recommendedFees,
|
|
|
|
});
|
2020-09-14 12:49:08 +02:00
|
|
|
}
|
|
|
|
} catch (_) {}
|
2018-12-22 15:25:34 +01:00
|
|
|
|
2020-09-14 12:49:08 +02:00
|
|
|
if (this.props.route.params.uri) {
|
|
|
|
try {
|
|
|
|
const { address, amount, memo } = this.decodeBitcoinUri(this.props.route.params.uri);
|
|
|
|
this.setState({ address, amount, memo });
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
alert(loc.send.details_error_decode);
|
2018-12-22 15:25:34 +01:00
|
|
|
}
|
2020-09-14 12:49:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
await this.state.fromWallet.fetchUtxo();
|
|
|
|
this.setState({ isLoading: false });
|
|
|
|
await this.reCalcTx();
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 05:00:12 +01:00
|
|
|
componentWillUnmount() {
|
|
|
|
this.keyboardDidShowListener.remove();
|
|
|
|
this.keyboardDidHideListener.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
_keyboardDidShow = () => {
|
2020-04-28 21:52:36 +02:00
|
|
|
this.setState({ renderWalletSelectionButtonHidden: true, isAmountToolbarVisibleForAndroid: true });
|
2019-01-30 05:00:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
_keyboardDidHide = () => {
|
2020-04-28 21:52:36 +02:00
|
|
|
this.setState({ renderWalletSelectionButtonHidden: false, isAmountToolbarVisibleForAndroid: false });
|
2019-01-30 05:00:12 +01:00
|
|
|
};
|
|
|
|
|
2019-01-26 06:39:22 +01:00
|
|
|
decodeBitcoinUri(uri) {
|
2019-03-02 13:13:12 +01:00
|
|
|
let amount = '';
|
|
|
|
let parsedBitcoinUri = null;
|
|
|
|
let address = uri || '';
|
|
|
|
let memo = '';
|
2019-01-26 06:39:22 +01:00
|
|
|
try {
|
2020-04-28 16:48:36 +02:00
|
|
|
parsedBitcoinUri = DeeplinkSchemaMatch.bip21decode(uri);
|
2020-06-01 14:54:23 +02:00
|
|
|
address = 'address' in parsedBitcoinUri ? parsedBitcoinUri.address : address;
|
|
|
|
if ('options' in parsedBitcoinUri) {
|
|
|
|
if ('amount' in parsedBitcoinUri.options) {
|
2019-01-26 06:39:22 +01:00
|
|
|
amount = parsedBitcoinUri.options.amount.toString();
|
2019-07-05 01:09:38 +02:00
|
|
|
amount = parsedBitcoinUri.options.amount;
|
2019-01-26 06:39:22 +01:00
|
|
|
}
|
2020-06-01 14:54:23 +02:00
|
|
|
if ('label' in parsedBitcoinUri.options) {
|
2019-01-26 06:39:22 +01:00
|
|
|
memo = parsedBitcoinUri.options.label || memo;
|
|
|
|
}
|
|
|
|
}
|
2019-03-02 13:13:12 +01:00
|
|
|
} catch (_) {}
|
|
|
|
return { address, amount, memo };
|
2019-01-26 06:39:22 +01:00
|
|
|
}
|
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
async createTransaction() {
|
2019-02-10 12:39:26 +01:00
|
|
|
Keyboard.dismiss();
|
2018-10-27 21:38:22 +02:00
|
|
|
this.setState({ isLoading: true });
|
2020-09-14 12:49:08 +02:00
|
|
|
const requestedSatPerByte = this.state.fee;
|
2019-09-03 05:28:52 +02:00
|
|
|
for (const [index, transaction] of this.state.addresses.entries()) {
|
2020-09-14 12:49:08 +02:00
|
|
|
let error;
|
2019-09-03 05:28:52 +02:00
|
|
|
if (!transaction.amount || transaction.amount < 0 || parseFloat(transaction.amount) === 0) {
|
2020-07-20 15:38:46 +02:00
|
|
|
error = loc.send.details_amount_field_is_not_valid;
|
2019-02-26 02:33:29 +01:00
|
|
|
console.log('validation error');
|
2020-09-14 12:49:08 +02:00
|
|
|
} else if (!requestedSatPerByte || parseFloat(requestedSatPerByte) < 1) {
|
2020-07-20 15:38:46 +02:00
|
|
|
error = loc.send.details_fee_field_is_not_valid;
|
2019-02-26 02:33:29 +01:00
|
|
|
console.log('validation error');
|
2019-09-03 05:28:52 +02:00
|
|
|
} else if (!transaction.address) {
|
2020-07-20 15:38:46 +02:00
|
|
|
error = loc.send.details_address_field_is_not_valid;
|
2019-09-03 05:28:52 +02:00
|
|
|
console.log('validation error');
|
2020-06-09 16:08:18 +02:00
|
|
|
} else if (this.state.fromWallet.getBalance() - transaction.amountSats < 0) {
|
2019-09-03 05:28:52 +02:00
|
|
|
// first sanity check is that sending amount is not bigger than available balance
|
2020-07-20 15:38:46 +02:00
|
|
|
error = loc.send.details_total_exceeds_balance;
|
2019-09-03 05:28:52 +02:00
|
|
|
console.log('validation error');
|
|
|
|
} else if (transaction.address) {
|
|
|
|
const address = transaction.address.trim().toLowerCase();
|
|
|
|
if (address.startsWith('lnb') || address.startsWith('lightning:lnb')) {
|
|
|
|
error =
|
|
|
|
'This address appears to be for a Lightning invoice. Please, go to your Lightning wallet in order to make a payment for this invoice.';
|
|
|
|
console.log('validation error');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!error) {
|
|
|
|
try {
|
|
|
|
bitcoin.address.toOutputScript(transaction.address);
|
|
|
|
} catch (err) {
|
|
|
|
console.log('validation error');
|
|
|
|
console.log(err);
|
2020-07-20 15:38:46 +02:00
|
|
|
error = loc.send.details_address_field_is_not_valid;
|
2019-09-03 05:28:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
if (index === 0) {
|
|
|
|
this.scrollView.scrollTo();
|
|
|
|
} else if (index === this.state.addresses.length - 1) {
|
|
|
|
this.scrollView.scrollToEnd();
|
|
|
|
} else {
|
2020-09-08 18:06:41 +02:00
|
|
|
const page = Math.round(this.state.width * (this.state.addresses.length - 2));
|
2019-09-03 05:28:52 +02:00
|
|
|
this.scrollView.scrollTo({ x: page, y: 0, animated: true });
|
|
|
|
}
|
|
|
|
this.setState({ isLoading: false, recipientsScrollIndex: index });
|
|
|
|
alert(error);
|
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
2020-09-14 19:24:27 +02:00
|
|
|
return;
|
2019-02-26 02:33:29 +01:00
|
|
|
}
|
2018-10-27 21:38:22 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 17:13:18 +02:00
|
|
|
try {
|
|
|
|
await this.createPsbtTransaction();
|
|
|
|
} catch (Err) {
|
|
|
|
this.setState({ isLoading: false }, () => {
|
|
|
|
alert(Err.message);
|
2019-05-03 14:36:11 +02:00
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
2019-12-12 04:17:09 +01:00
|
|
|
});
|
2020-04-22 17:13:18 +02:00
|
|
|
}
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
|
2020-09-14 12:49:08 +02:00
|
|
|
/**
|
|
|
|
* Recalculating fee options by creating skeleton of future tx.
|
|
|
|
*/
|
|
|
|
reCalcTx = async (all = false) => {
|
|
|
|
const wallet = this.state.fromWallet;
|
|
|
|
const fees = this.state.networkTransactionFees;
|
|
|
|
const changeAddress = await wallet.getChangeAddressAsync();
|
|
|
|
const requestedSatPerByte = Number(this.state.fee);
|
|
|
|
const feePrecalc = { ...this.state.feePrecalc };
|
|
|
|
|
|
|
|
const options = all
|
|
|
|
? [
|
|
|
|
{ key: 'current', fee: requestedSatPerByte },
|
|
|
|
{ key: 'slowFee', fee: fees.slowFee },
|
|
|
|
{ key: 'mediumFee', fee: fees.mediumFee },
|
|
|
|
{ key: 'fastestFee', fee: fees.fastestFee },
|
|
|
|
]
|
|
|
|
: [{ key: 'current', fee: requestedSatPerByte }];
|
|
|
|
|
|
|
|
for (const opt of options) {
|
|
|
|
let targets = [];
|
|
|
|
for (const transaction of this.state.addresses) {
|
|
|
|
if (transaction.amount === BitcoinUnit.MAX) {
|
|
|
|
// single output with MAX
|
|
|
|
targets = [{ address: transaction.address }];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const value = parseInt(transaction.amountSats);
|
|
|
|
if (value > 0) {
|
|
|
|
targets.push({ address: transaction.address, value });
|
|
|
|
} else if (transaction.amount) {
|
|
|
|
if (currency.btcToSatoshi(transaction.amount) > 0) {
|
|
|
|
targets.push({ address: transaction.address, value: currency.btcToSatoshi(transaction.amount) });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// replace wrong addresses with dump
|
|
|
|
targets = targets.map(t => {
|
|
|
|
try {
|
|
|
|
bitcoin.address.toOutputScript(t.address);
|
|
|
|
return t;
|
|
|
|
} catch (e) {
|
|
|
|
return { ...t, address: '36JxaUrpDzkEerkTf1FzwHNE1Hb7cCjgJV' };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let flag = false;
|
|
|
|
while (true) {
|
|
|
|
try {
|
|
|
|
const { fee } = wallet.coinselect(
|
|
|
|
wallet.getUtxo(),
|
|
|
|
targets,
|
|
|
|
opt.fee,
|
|
|
|
changeAddress,
|
|
|
|
this.state.isTransactionReplaceable ? HDSegwitBech32Wallet.defaultRBFSequence : HDSegwitBech32Wallet.finalRBFSequence,
|
|
|
|
);
|
|
|
|
|
|
|
|
feePrecalc[opt.key] = fee;
|
|
|
|
break;
|
|
|
|
} catch (e) {
|
|
|
|
if (e.message.includes('Not enough') && !flag) {
|
|
|
|
flag = true;
|
|
|
|
// if the outputs are too big, replace them with dust
|
|
|
|
targets = targets.map(t => ({ ...t, value: 546 }));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
feePrecalc[opt.key] = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({ feePrecalc });
|
|
|
|
};
|
|
|
|
|
2020-04-22 17:13:18 +02:00
|
|
|
async createPsbtTransaction() {
|
2019-06-01 22:44:39 +02:00
|
|
|
/** @type {HDSegwitBech32Wallet} */
|
|
|
|
const wallet = this.state.fromWallet;
|
|
|
|
const changeAddress = await wallet.getChangeAddressAsync();
|
2020-09-14 12:49:08 +02:00
|
|
|
const requestedSatPerByte = Number(this.state.fee);
|
2020-04-24 16:03:15 +02:00
|
|
|
console.log({ requestedSatPerByte, utxo: wallet.getUtxo() });
|
2019-06-01 22:44:39 +02:00
|
|
|
|
|
|
|
let targets = [];
|
2019-09-03 05:28:52 +02:00
|
|
|
for (const transaction of this.state.addresses) {
|
2020-04-24 16:03:15 +02:00
|
|
|
if (transaction.amount === BitcoinUnit.MAX) {
|
|
|
|
// single output with MAX
|
|
|
|
targets = [{ address: transaction.address }];
|
|
|
|
break;
|
|
|
|
}
|
2020-06-09 16:08:18 +02:00
|
|
|
const value = parseInt(transaction.amountSats);
|
2020-04-24 16:03:15 +02:00
|
|
|
if (value > 0) {
|
|
|
|
targets.push({ address: transaction.address, value });
|
2020-06-24 21:23:56 +02:00
|
|
|
} else if (transaction.amount) {
|
|
|
|
if (currency.btcToSatoshi(transaction.amount) > 0) {
|
|
|
|
targets.push({ address: transaction.address, value: currency.btcToSatoshi(transaction.amount) });
|
|
|
|
}
|
2019-09-03 05:28:52 +02:00
|
|
|
}
|
2019-08-04 21:33:15 +02:00
|
|
|
}
|
2019-06-01 22:44:39 +02:00
|
|
|
|
2020-06-01 14:54:23 +02:00
|
|
|
const { tx, fee, psbt } = wallet.createTransaction(
|
2019-12-11 05:13:40 +01:00
|
|
|
wallet.getUtxo(),
|
|
|
|
targets,
|
|
|
|
requestedSatPerByte,
|
|
|
|
changeAddress,
|
2019-12-13 02:05:38 +01:00
|
|
|
this.state.isTransactionReplaceable ? HDSegwitBech32Wallet.defaultRBFSequence : HDSegwitBech32Wallet.finalRBFSequence,
|
2019-12-11 05:13:40 +01:00
|
|
|
);
|
2019-09-27 16:49:56 +02:00
|
|
|
|
|
|
|
if (wallet.type === WatchOnlyWallet.type) {
|
|
|
|
// watch-only wallets with enabled HW wallet support have different flow. we have to show PSBT to user as QR code
|
|
|
|
// so he can scan it and sign it. then we have to scan it back from user (via camera and QR code), and ask
|
|
|
|
// user whether he wants to broadcast it
|
2019-12-12 04:17:09 +01:00
|
|
|
this.props.navigation.navigate('PsbtWithHardwareWallet', {
|
|
|
|
memo: this.state.memo,
|
|
|
|
fromWallet: wallet,
|
|
|
|
psbt,
|
|
|
|
});
|
|
|
|
this.setState({ isLoading: false });
|
2019-09-27 16:49:56 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-06-01 22:44:39 +02:00
|
|
|
|
|
|
|
BlueApp.tx_metadata = BlueApp.tx_metadata || {};
|
|
|
|
BlueApp.tx_metadata[tx.getId()] = {
|
|
|
|
txhex: tx.toHex(),
|
|
|
|
memo: this.state.memo,
|
|
|
|
};
|
|
|
|
await BlueApp.saveToDisk();
|
2019-12-12 04:17:09 +01:00
|
|
|
this.props.navigation.navigate('Confirm', {
|
|
|
|
fee: new BigNumber(fee).dividedBy(100000000).toNumber(),
|
|
|
|
memo: this.state.memo,
|
|
|
|
fromWallet: wallet,
|
|
|
|
tx: tx.toHex(),
|
|
|
|
recipients: targets,
|
|
|
|
satoshiPerByte: requestedSatPerByte,
|
|
|
|
});
|
|
|
|
this.setState({ isLoading: false });
|
2019-06-01 22:44:39 +02:00
|
|
|
}
|
|
|
|
|
2018-12-24 01:44:31 +01:00
|
|
|
onWalletSelect = wallet => {
|
2019-09-03 05:28:52 +02:00
|
|
|
const changeWallet = () => {
|
2020-04-29 16:27:07 +02:00
|
|
|
this.setState({ fromWallet: wallet }, () => {
|
2019-09-03 05:28:52 +02:00
|
|
|
this.renderNavigationHeader();
|
|
|
|
this.props.navigation.pop();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
if (this.state.addresses.length > 1 && !wallet.allowBatchSend()) {
|
|
|
|
ReactNativeHapticFeedback.trigger('notificationWarning');
|
|
|
|
Alert.alert(
|
2020-07-20 15:38:46 +02:00
|
|
|
loc.send.details_wallet_selection,
|
|
|
|
loc.send.details_no_multiple,
|
2019-09-03 05:28:52 +02:00
|
|
|
[
|
|
|
|
{
|
|
|
|
text: loc._.ok,
|
|
|
|
onPress: async () => {
|
|
|
|
const firstTransaction =
|
|
|
|
this.state.addresses.find(element => {
|
|
|
|
const feeSatoshi = new BigNumber(element.amount).multipliedBy(100000000);
|
|
|
|
return element.address.length > 0 && feeSatoshi > 0;
|
|
|
|
}) || this.state.addresses[0];
|
|
|
|
this.setState({ addresses: [firstTransaction], recipientsScrollIndex: 0 }, () => changeWallet());
|
|
|
|
},
|
|
|
|
style: 'default',
|
|
|
|
},
|
2020-07-20 15:38:46 +02:00
|
|
|
{ text: loc._.cancel, onPress: () => {}, style: 'cancel' },
|
2019-09-03 05:28:52 +02:00
|
|
|
],
|
|
|
|
{ cancelable: false },
|
|
|
|
);
|
|
|
|
} else if (this.state.addresses.some(element => element.amount === BitcoinUnit.MAX) && !wallet.allowSendMax()) {
|
|
|
|
ReactNativeHapticFeedback.trigger('notificationWarning');
|
|
|
|
Alert.alert(
|
2020-07-20 15:38:46 +02:00
|
|
|
loc.send.details_wallet_selection,
|
|
|
|
loc.send.details_no_maximum,
|
2019-09-03 05:28:52 +02:00
|
|
|
[
|
|
|
|
{
|
|
|
|
text: loc._.ok,
|
|
|
|
onPress: async () => {
|
|
|
|
const firstTransaction =
|
|
|
|
this.state.addresses.find(element => {
|
|
|
|
return element.amount === BitcoinUnit.MAX;
|
|
|
|
}) || this.state.addresses[0];
|
|
|
|
firstTransaction.amount = 0;
|
|
|
|
this.setState({ addresses: [firstTransaction], recipientsScrollIndex: 0 }, () => changeWallet());
|
|
|
|
},
|
|
|
|
style: 'default',
|
|
|
|
},
|
2020-07-20 15:38:46 +02:00
|
|
|
{ text: loc._.cancel, onPress: () => {}, style: 'cancel' },
|
2019-09-03 05:28:52 +02:00
|
|
|
],
|
|
|
|
{ cancelable: false },
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
changeWallet();
|
|
|
|
}
|
2018-12-24 01:44:31 +01:00
|
|
|
};
|
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
renderFeeSelectionModal = () => {
|
2020-09-14 12:49:08 +02:00
|
|
|
const { feePrecalc, fee, networkTransactionFees: nf } = this.state;
|
|
|
|
const options = [
|
|
|
|
{
|
|
|
|
label: loc.send.fee_fast,
|
|
|
|
time: loc.send.fee_10m,
|
|
|
|
fee: feePrecalc.fastestFee,
|
|
|
|
rate: nf.fastestFee,
|
|
|
|
active: Number(fee) === nf.fastestFee,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: loc.send.fee_medium,
|
|
|
|
time: loc.send.fee_3h,
|
|
|
|
fee: feePrecalc.mediumFee,
|
|
|
|
rate: nf.mediumFee,
|
|
|
|
active: Number(fee) === nf.mediumFee,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: loc.send.fee_slow,
|
|
|
|
time: loc.send.fee_1d,
|
|
|
|
fee: feePrecalc.slowFee,
|
|
|
|
rate: nf.slowFee,
|
|
|
|
active: Number(fee) === nf.slowFee,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
return (
|
|
|
|
<Modal
|
2020-09-08 18:06:41 +02:00
|
|
|
deviceHeight={Dimensions.get('window').height}
|
|
|
|
deviceWidth={this.state.width + this.state.width / 2}
|
2018-10-20 23:10:21 +02:00
|
|
|
isVisible={this.state.isFeeSelectionModalVisible}
|
|
|
|
style={styles.bottomModal}
|
2020-09-14 12:49:08 +02:00
|
|
|
onBackdropPress={() => this.setState({ isFeeSelectionModalVisible: false })}
|
2018-10-20 23:10:21 +02:00
|
|
|
>
|
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}>
|
2020-09-14 12:49:08 +02:00
|
|
|
{options.map(({ label, time, fee, rate, active }, index) => (
|
|
|
|
<TouchableOpacity
|
|
|
|
key={label}
|
|
|
|
onPress={() =>
|
|
|
|
this.setState(({ feePrecalc }) => {
|
|
|
|
feePrecalc.current = fee;
|
|
|
|
return { isFeeSelectionModalVisible: false, fee: rate.toString(), feePrecalc };
|
|
|
|
})
|
|
|
|
}
|
|
|
|
style={[styles.feeModalItem, active && styles.feeModalItemActive]}
|
|
|
|
>
|
|
|
|
<View style={styles.feeModalRow}>
|
|
|
|
<Text style={styles.feeModalLabel}>{label}</Text>
|
|
|
|
<View style={styles.feeModalTime}>
|
|
|
|
<Text style={styles.feeModalTimeText}>~{time}</Text>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
<View style={styles.feeModalRow}>
|
|
|
|
<Text style={styles.feeModalValue}>{fee && this.formatFee(fee)}</Text>
|
|
|
|
<Text style={styles.feeModalValue}>{rate} sat/byte</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
))}
|
|
|
|
<TouchableOpacity
|
2020-09-15 16:02:10 +02:00
|
|
|
testID="feeCustom"
|
2020-09-14 12:49:08 +02:00
|
|
|
style={styles.feeModalCustom}
|
|
|
|
onPress={async () => {
|
|
|
|
let error = loc.send.fee_satbyte;
|
|
|
|
while (true) {
|
|
|
|
let fee;
|
|
|
|
|
|
|
|
try {
|
|
|
|
fee = await prompt(loc.send.create_fee, error, true, 'numeric');
|
|
|
|
} catch (_) {
|
|
|
|
return;
|
2019-01-31 01:56:34 +01:00
|
|
|
}
|
2020-09-14 12:49:08 +02:00
|
|
|
|
|
|
|
if (!/^\d+$/.test(fee)) {
|
|
|
|
error = loc.send.details_fee_field_is_not_valid;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fee < 1) fee = '1';
|
|
|
|
fee = Number(fee).toString(); // this will remove leading zeros if any
|
2020-09-15 13:09:51 +02:00
|
|
|
this.setState({ fee, isFeeSelectionModalVisible: false }, this.reCalcTx);
|
2020-09-14 12:49:08 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Text style={styles.feeModalCustomText}>{loc.send.fee_custom}</Text>
|
2018-10-20 23:10:21 +02:00
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
|
|
|
</KeyboardAvoidingView>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-09-16 18:52:10 +02:00
|
|
|
/**
|
|
|
|
* watch-only wallets with enabled HW wallet support have different flow. we have to show PSBT to user as QR code
|
|
|
|
* so he can scan it and sign it. then we have to scan it back from user (via camera and QR code), and ask
|
|
|
|
* user whether he wants to broadcast it.
|
|
|
|
* alternatively, user can export psbt file, sign it externally and then import it
|
|
|
|
*
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
2020-01-01 04:31:04 +01:00
|
|
|
importTransaction = async () => {
|
2020-09-16 18:52:10 +02:00
|
|
|
if (this.state.fromWallet.type !== WatchOnlyWallet.type) {
|
|
|
|
alert('Error: importing transaction in non-watchonly wallet (this should never happen)');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-01 04:31:04 +01:00
|
|
|
try {
|
2020-02-24 22:45:14 +01:00
|
|
|
const res = await DocumentPicker.pick({
|
|
|
|
type: Platform.OS === 'ios' ? ['io.bluewallet.psbt', 'io.bluewallet.psbt.txn'] : [DocumentPicker.types.allFiles],
|
|
|
|
});
|
2020-09-16 18:52:10 +02:00
|
|
|
|
|
|
|
if (DeeplinkSchemaMatch.isPossiblySignedPSBTFile(res.uri)) {
|
|
|
|
// we assume that transaction is already signed, so all we have to do is get txhex and pass it to next screen
|
|
|
|
// so user can broadcast:
|
2020-01-04 04:12:29 +01:00
|
|
|
const file = await RNFS.readFile(res.uri, 'ascii');
|
2020-09-16 18:52:10 +02:00
|
|
|
const psbt = bitcoin.Psbt.fromBase64(file);
|
|
|
|
const txhex = psbt.extractTransaction().toHex();
|
|
|
|
|
|
|
|
this.props.navigation.navigate('PsbtWithHardwareWallet', {
|
|
|
|
memo: this.state.memo,
|
|
|
|
fromWallet: this.state.fromWallet,
|
|
|
|
txhex,
|
|
|
|
});
|
|
|
|
this.setState({ isLoading: false, isAdvancedTransactionOptionsVisible: false });
|
|
|
|
} else if (DeeplinkSchemaMatch.isPossiblyPSBTFile(res.uri)) {
|
|
|
|
// looks like transaction is UNsigned, so we construct PSBT object and pass to next screen
|
|
|
|
// so user can do smth with it:
|
|
|
|
const file = await RNFS.readFile(res.uri, 'ascii');
|
|
|
|
const psbt = bitcoin.Psbt.fromBase64(file);
|
|
|
|
this.props.navigation.navigate('PsbtWithHardwareWallet', {
|
|
|
|
memo: this.state.memo,
|
|
|
|
fromWallet: this.state.fromWallet,
|
|
|
|
psbt,
|
|
|
|
});
|
|
|
|
this.setState({ isLoading: false, isAdvancedTransactionOptionsVisible: false });
|
2020-01-04 04:12:29 +01:00
|
|
|
} else if (DeeplinkSchemaMatch.isTXNFile(res.uri)) {
|
2020-09-16 18:52:10 +02:00
|
|
|
// plain text file with txhex ready to broadcast
|
2020-01-04 04:12:29 +01:00
|
|
|
const file = await RNFS.readFile(res.uri, 'ascii');
|
|
|
|
this.props.navigation.navigate('PsbtWithHardwareWallet', {
|
|
|
|
memo: this.state.memo,
|
|
|
|
fromWallet: this.state.fromWallet,
|
|
|
|
txhex: file,
|
|
|
|
});
|
|
|
|
this.setState({ isLoading: false, isAdvancedTransactionOptionsVisible: false });
|
2020-09-16 18:52:10 +02:00
|
|
|
} else {
|
|
|
|
alert('Unrecognized file format');
|
2020-01-01 04:31:04 +01:00
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
if (!DocumentPicker.isCancel(err)) {
|
2020-07-20 15:38:46 +02:00
|
|
|
alert(loc.send.details_no_signed_tx);
|
2020-01-01 04:31:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-03 05:28:52 +02:00
|
|
|
renderAdvancedTransactionOptionsModal = () => {
|
2019-11-10 21:25:28 +01:00
|
|
|
const isSendMaxUsed = this.state.addresses.some(element => element.amount === BitcoinUnit.MAX);
|
2019-09-03 05:28:52 +02:00
|
|
|
return (
|
|
|
|
<Modal
|
2020-08-08 04:22:51 +02:00
|
|
|
deviceHeight={Dimensions.get('window').height}
|
2020-09-08 18:06:41 +02:00
|
|
|
deviceWidth={this.state.width + this.state.width / 2}
|
|
|
|
isVisible={this.state.isAdvancedTransactionOptionsVisible}
|
2019-09-03 05:28:52 +02:00
|
|
|
style={styles.bottomModal}
|
|
|
|
onBackdropPress={() => {
|
|
|
|
Keyboard.dismiss();
|
|
|
|
this.setState({ isAdvancedTransactionOptionsVisible: false });
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'position' : null}>
|
|
|
|
<View style={styles.advancedTransactionOptionsModalContent}>
|
2019-11-10 21:25:28 +01:00
|
|
|
{this.state.fromWallet.allowSendMax() && (
|
2019-09-03 05:28:52 +02:00
|
|
|
<BlueListItem
|
2020-09-15 18:11:18 +02:00
|
|
|
testID="sendMaxButton"
|
2019-11-10 21:25:28 +01:00
|
|
|
disabled={!(this.state.fromWallet.getBalance() > 0) || isSendMaxUsed}
|
2020-07-20 15:38:46 +02:00
|
|
|
title={loc.send.details_adv_full}
|
2019-09-03 05:28:52 +02:00
|
|
|
hideChevron
|
2019-11-10 21:25:28 +01:00
|
|
|
component={TouchableOpacity}
|
|
|
|
onPress={this.onUseAllPressed}
|
2019-09-03 05:28:52 +02:00
|
|
|
/>
|
2019-11-10 21:25:28 +01:00
|
|
|
)}
|
2019-12-11 05:13:40 +01:00
|
|
|
{this.state.fromWallet.type === HDSegwitBech32Wallet.type && (
|
|
|
|
<BlueListItem
|
2020-07-20 15:38:46 +02:00
|
|
|
title={loc.send.details_adv_fee_bump}
|
2020-05-03 20:17:49 +02:00
|
|
|
Component={TouchableWithoutFeedback}
|
|
|
|
switch={{ value: this.state.isTransactionReplaceable, onValueChange: this.onReplaceableFeeSwitchValueChanged }}
|
2019-12-11 05:13:40 +01:00
|
|
|
/>
|
|
|
|
)}
|
2020-02-25 15:42:11 +01:00
|
|
|
{this.state.fromWallet.type === WatchOnlyWallet.type &&
|
2020-02-26 15:39:19 +01:00
|
|
|
this.state.fromWallet.isHd() &&
|
|
|
|
this.state.fromWallet.getSecret().startsWith('zpub') && (
|
2020-07-20 15:38:46 +02:00
|
|
|
<BlueListItem
|
|
|
|
title={loc.send.details_adv_import}
|
|
|
|
hideChevron
|
|
|
|
component={TouchableOpacity}
|
|
|
|
onPress={this.importTransaction}
|
|
|
|
/>
|
2020-02-25 15:42:11 +01:00
|
|
|
)}
|
2019-11-10 21:25:28 +01:00
|
|
|
{this.state.fromWallet.allowBatchSend() && (
|
|
|
|
<>
|
|
|
|
<BlueListItem
|
|
|
|
disabled={isSendMaxUsed}
|
2020-07-20 15:38:46 +02:00
|
|
|
title={loc.send.details_add_rec_add}
|
2019-11-10 21:25:28 +01:00
|
|
|
hideChevron
|
|
|
|
component={TouchableOpacity}
|
|
|
|
onPress={() => {
|
|
|
|
const addresses = this.state.addresses;
|
|
|
|
addresses.push(new BitcoinTransaction());
|
|
|
|
this.setState(
|
|
|
|
{
|
|
|
|
addresses,
|
|
|
|
isAdvancedTransactionOptionsVisible: false,
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
this.scrollView.scrollToEnd();
|
|
|
|
if (this.state.addresses.length > 1) this.scrollView.flashScrollIndicators();
|
2020-06-09 16:08:18 +02:00
|
|
|
// after adding recipient it automatically scrolls to the last one
|
|
|
|
this.setState({ recipientsScrollIndex: this.state.addresses.length - 1 });
|
2019-11-10 21:25:28 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<BlueListItem
|
2020-07-20 15:38:46 +02:00
|
|
|
title={loc.send.details_add_rec_rem}
|
2019-11-10 21:25:28 +01:00
|
|
|
hideChevron
|
|
|
|
disabled={this.state.addresses.length < 2}
|
|
|
|
component={TouchableOpacity}
|
|
|
|
onPress={() => {
|
|
|
|
const addresses = this.state.addresses;
|
|
|
|
addresses.splice(this.state.recipientsScrollIndex, 1);
|
|
|
|
this.setState(
|
|
|
|
{
|
|
|
|
addresses,
|
|
|
|
isAdvancedTransactionOptionsVisible: false,
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
if (this.state.addresses.length > 1) this.scrollView.flashScrollIndicators();
|
2020-06-09 16:08:18 +02:00
|
|
|
// after deletion it automatically scrolls to the last one
|
|
|
|
this.setState({ recipientsScrollIndex: this.state.addresses.length - 1 });
|
2019-11-10 21:25:28 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
2019-09-03 05:28:52 +02:00
|
|
|
</View>
|
|
|
|
</KeyboardAvoidingView>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-12-11 05:13:40 +01:00
|
|
|
onReplaceableFeeSwitchValueChanged = value => {
|
|
|
|
this.setState({ isTransactionReplaceable: value });
|
|
|
|
};
|
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
renderCreateButton = () => {
|
|
|
|
return (
|
2020-05-24 11:17:26 +02:00
|
|
|
<View style={styles.createButton}>
|
2020-04-27 10:23:56 +02:00
|
|
|
{this.state.isLoading ? (
|
|
|
|
<ActivityIndicator />
|
|
|
|
) : (
|
2020-07-20 15:38:46 +02:00
|
|
|
<BlueButton onPress={() => this.createTransaction()} title={loc.send.details_next} testID="CreateTransactionButton" />
|
2020-04-27 10:23:56 +02:00
|
|
|
)}
|
2018-10-20 23:10:21 +02:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
2018-01-30 23:42:38 +01:00
|
|
|
|
2018-12-24 01:44:31 +01:00
|
|
|
renderWalletSelectionButton = () => {
|
2019-01-30 05:00:12 +01:00
|
|
|
if (this.state.renderWalletSelectionButtonHidden) return;
|
2018-12-24 01:44:31 +01:00
|
|
|
return (
|
2020-05-24 11:17:26 +02:00
|
|
|
<View style={styles.select}>
|
2018-12-24 01:44:31 +01:00
|
|
|
{!this.state.isLoading && (
|
|
|
|
<TouchableOpacity
|
2020-05-24 11:17:26 +02:00
|
|
|
style={styles.selectTouch}
|
2019-02-26 02:33:29 +01:00
|
|
|
onPress={() =>
|
|
|
|
this.props.navigation.navigate('SelectWallet', { onWalletSelect: this.onWalletSelect, chainType: Chain.ONCHAIN })
|
|
|
|
}
|
2018-12-24 01:44:31 +01:00
|
|
|
>
|
2020-05-24 11:17:26 +02:00
|
|
|
<Text style={styles.selectText}>{loc.wallets.select_wallet.toLowerCase()}</Text>
|
2019-08-06 19:31:23 +02:00
|
|
|
<Icon name="angle-right" size={18} type="font-awesome" color="#9aa0aa" />
|
2018-12-24 01:44:31 +01:00
|
|
|
</TouchableOpacity>
|
|
|
|
)}
|
2020-05-24 11:17:26 +02:00
|
|
|
<View style={styles.selectWrap}>
|
2019-08-10 08:57:55 +02:00
|
|
|
<TouchableOpacity
|
2020-05-24 11:17:26 +02:00
|
|
|
style={styles.selectTouch}
|
2019-08-06 19:31:23 +02:00
|
|
|
onPress={() =>
|
|
|
|
this.props.navigation.navigate('SelectWallet', { onWalletSelect: this.onWalletSelect, chainType: Chain.ONCHAIN })
|
|
|
|
}
|
|
|
|
>
|
2020-05-24 11:17:26 +02:00
|
|
|
<Text style={styles.selectLabel}>{this.state.fromWallet.getLabel()}</Text>
|
2019-08-10 08:57:55 +02:00
|
|
|
</TouchableOpacity>
|
2018-12-24 01:44:31 +01:00
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-09-03 05:28:52 +02:00
|
|
|
handlePageChange = e => {
|
|
|
|
Keyboard.dismiss();
|
2020-09-14 12:49:08 +02:00
|
|
|
const offset = e.nativeEvent.contentOffset;
|
2019-09-03 05:28:52 +02:00
|
|
|
if (offset) {
|
2020-09-08 18:06:41 +02:00
|
|
|
const page = Math.round(offset.x / this.state.width);
|
2019-09-03 05:28:52 +02:00
|
|
|
if (this.state.recipientsScrollIndex !== page) {
|
|
|
|
this.setState({ recipientsScrollIndex: page });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
scrollViewCurrentIndex = () => {
|
|
|
|
Keyboard.dismiss();
|
2020-09-14 12:49:08 +02:00
|
|
|
const offset = this.scrollView.contentOffset;
|
2019-09-03 05:28:52 +02:00
|
|
|
if (offset) {
|
2020-09-08 18:06:41 +02:00
|
|
|
const page = Math.round(offset.x / this.state.width);
|
2019-09-03 05:28:52 +02:00
|
|
|
return page;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
renderBitcoinTransactionInfoFields = () => {
|
2020-06-01 14:54:23 +02:00
|
|
|
const rows = [];
|
2020-09-08 18:06:41 +02:00
|
|
|
|
2020-06-01 14:54:23 +02:00
|
|
|
for (const [index, item] of this.state.addresses.entries()) {
|
2019-09-03 05:28:52 +02:00
|
|
|
rows.push(
|
2020-09-08 18:06:41 +02:00
|
|
|
<View key={index} style={{ width: this.state.width }}>
|
2019-09-03 05:28:52 +02:00
|
|
|
<BlueBitcoinAmount
|
|
|
|
isLoading={this.state.isLoading}
|
|
|
|
amount={item.amount ? item.amount.toString() : null}
|
2020-06-09 16:08:18 +02:00
|
|
|
onAmountUnitChange={unit => {
|
|
|
|
const units = this.state.units;
|
|
|
|
units[index] = unit;
|
|
|
|
|
|
|
|
const addresses = this.state.addresses;
|
|
|
|
const item = addresses[index];
|
|
|
|
|
|
|
|
switch (unit) {
|
|
|
|
case BitcoinUnit.SATS:
|
|
|
|
item.amountSats = parseInt(item.amount);
|
|
|
|
break;
|
|
|
|
case BitcoinUnit.BTC:
|
|
|
|
item.amountSats = currency.btcToSatoshi(item.amount);
|
|
|
|
break;
|
|
|
|
case BitcoinUnit.LOCAL_CURRENCY:
|
|
|
|
// also accounting for cached fiat->sat conversion to avoid rounding error
|
|
|
|
item.amountSats =
|
|
|
|
BlueBitcoinAmount.getCachedSatoshis(item.amount) || currency.btcToSatoshi(currency.fiatToBTC(item.amount));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
addresses[index] = item;
|
|
|
|
this.setState({ units, addresses });
|
|
|
|
}}
|
2019-09-03 05:28:52 +02:00
|
|
|
onChangeText={text => {
|
|
|
|
item.amount = text;
|
2020-06-09 16:08:18 +02:00
|
|
|
switch (this.state.units[index] || this.state.amountUnit) {
|
|
|
|
case BitcoinUnit.BTC:
|
|
|
|
item.amountSats = currency.btcToSatoshi(item.amount);
|
|
|
|
break;
|
|
|
|
case BitcoinUnit.LOCAL_CURRENCY:
|
|
|
|
item.amountSats = currency.btcToSatoshi(currency.fiatToBTC(item.amount));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case BitcoinUnit.SATS:
|
|
|
|
item.amountSats = parseInt(text);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const addresses = this.state.addresses;
|
|
|
|
addresses[index] = item;
|
2020-09-14 12:49:08 +02:00
|
|
|
this.setState({ addresses }, this.reCalcTx);
|
2019-09-03 05:28:52 +02:00
|
|
|
}}
|
2020-06-09 16:08:18 +02:00
|
|
|
unit={this.state.units[index] || this.state.amountUnit}
|
2019-09-03 05:28:52 +02:00
|
|
|
inputAccessoryViewID={this.state.fromWallet.allowSendMax() ? BlueUseAllFundsButton.InputAccessoryViewID : null}
|
|
|
|
/>
|
|
|
|
<BlueAddressInput
|
|
|
|
onChangeText={async text => {
|
|
|
|
text = text.trim();
|
2020-06-01 14:54:23 +02:00
|
|
|
const transactions = this.state.addresses;
|
2020-06-15 03:15:58 +02:00
|
|
|
const { address, amount, memo } = this.decodeBitcoinUri(text);
|
|
|
|
item.address = address || text;
|
|
|
|
item.amount = amount || item.amount;
|
|
|
|
transactions[index] = item;
|
|
|
|
this.setState({
|
|
|
|
addresses: transactions,
|
|
|
|
memo: memo || this.state.memo,
|
|
|
|
isLoading: false,
|
|
|
|
});
|
2020-09-14 12:49:08 +02:00
|
|
|
this.reCalcTx();
|
2019-09-03 05:28:52 +02:00
|
|
|
}}
|
|
|
|
onBarScanned={this.processAddressData}
|
|
|
|
address={item.address}
|
|
|
|
isLoading={this.state.isLoading}
|
|
|
|
inputAccessoryViewID={BlueDismissKeyboardInputAccessory.InputAccessoryViewID}
|
2020-05-27 13:12:17 +02:00
|
|
|
launchedBy={this.props.route.name}
|
2019-09-03 05:28:52 +02:00
|
|
|
/>
|
|
|
|
{this.state.addresses.length > 1 && (
|
2020-07-20 15:38:46 +02:00
|
|
|
<BlueText style={styles.of}>{loc.formatString(loc._.of, { number: index + 1, total: this.state.addresses.length })}</BlueText>
|
2019-09-03 05:28:52 +02:00
|
|
|
)}
|
|
|
|
</View>,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return rows;
|
|
|
|
};
|
|
|
|
|
2019-11-10 21:25:28 +01:00
|
|
|
onUseAllPressed = () => {
|
|
|
|
ReactNativeHapticFeedback.trigger('notificationWarning');
|
|
|
|
Alert.alert(
|
2020-07-20 15:38:46 +02:00
|
|
|
loc.send.details_adv_full,
|
2020-07-28 17:24:12 +02:00
|
|
|
loc.send.details_adv_full_sure + ' ' + (this.state.addresses.length > 1 ? loc.send.details_adv_full_remove : ''),
|
2019-11-10 21:25:28 +01:00
|
|
|
[
|
|
|
|
{
|
|
|
|
text: loc._.ok,
|
|
|
|
onPress: async () => {
|
|
|
|
Keyboard.dismiss();
|
|
|
|
const recipient = this.state.addresses[this.state.recipientsScrollIndex];
|
|
|
|
recipient.amount = BitcoinUnit.MAX;
|
2020-07-15 04:04:42 +02:00
|
|
|
recipient.amountSats = BitcoinUnit.MAX;
|
2020-06-09 16:08:18 +02:00
|
|
|
this.setState({
|
|
|
|
addresses: [recipient],
|
|
|
|
units: [BitcoinUnit.BTC],
|
2020-09-15 12:30:53 +02:00
|
|
|
recipientsScrollIndex: 0,
|
2020-06-09 16:08:18 +02:00
|
|
|
isAdvancedTransactionOptionsVisible: false,
|
|
|
|
});
|
2019-11-10 21:25:28 +01:00
|
|
|
},
|
|
|
|
style: 'default',
|
|
|
|
},
|
2020-07-20 15:38:46 +02:00
|
|
|
{ text: loc._.cancel, onPress: () => {}, style: 'cancel' },
|
2019-11-10 21:25:28 +01:00
|
|
|
],
|
|
|
|
{ cancelable: false },
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-09-14 12:49:08 +02:00
|
|
|
formatFee = fee => {
|
|
|
|
switch (this.state.feeUnit) {
|
|
|
|
case BitcoinUnit.SATS:
|
|
|
|
return fee + ' ' + BitcoinUnit.SATS;
|
|
|
|
case BitcoinUnit.BTC:
|
|
|
|
return currency.satoshiToBTC(fee) + ' ' + BitcoinUnit.BTC;
|
|
|
|
case BitcoinUnit.LOCAL_CURRENCY:
|
|
|
|
return currency.satoshiToLocalCurrency(fee);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-08 18:06:41 +02:00
|
|
|
onLayout = e => {
|
|
|
|
this.setState({ width: e.nativeEvent.layout.width });
|
|
|
|
};
|
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
render() {
|
2020-06-09 16:08:18 +02:00
|
|
|
if (this.state.isLoading || typeof this.state.fromWallet === 'undefined') {
|
|
|
|
return (
|
|
|
|
<View style={styles.loading}>
|
|
|
|
<BlueLoading />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2020-09-14 12:49:08 +02:00
|
|
|
|
2018-01-30 23:42:38 +01:00
|
|
|
return (
|
2018-10-20 23:10:21 +02:00
|
|
|
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
|
2020-09-08 18:06:41 +02:00
|
|
|
<View style={styles.root} onLayout={this.onLayout}>
|
2020-06-11 05:54:47 +02:00
|
|
|
<StatusBar barStyle="light-content" />
|
2019-09-03 05:28:52 +02:00
|
|
|
<View>
|
2020-06-09 16:08:18 +02:00
|
|
|
<KeyboardAvoidingView behavior="position">
|
|
|
|
<ScrollView
|
|
|
|
pagingEnabled
|
|
|
|
horizontal
|
|
|
|
contentContainerStyle={styles.scrollViewContent}
|
|
|
|
ref={ref => (this.scrollView = ref)}
|
|
|
|
keyboardShouldPersistTaps="always"
|
|
|
|
onContentSizeChange={() => this.scrollView.scrollToEnd()}
|
|
|
|
onLayout={() => this.scrollView.scrollToEnd()}
|
|
|
|
onMomentumScrollEnd={this.handlePageChange}
|
|
|
|
scrollEnabled={this.state.addresses.length > 1}
|
|
|
|
scrollIndicatorInsets={{ top: 0, left: 8, bottom: 0, right: 8 }}
|
|
|
|
>
|
|
|
|
{this.renderBitcoinTransactionInfoFields()}
|
|
|
|
</ScrollView>
|
|
|
|
<View hide={!this.state.showMemoRow} style={styles.memo}>
|
|
|
|
<TextInput
|
|
|
|
onChangeText={text => this.setState({ memo: text })}
|
2020-07-20 15:38:46 +02:00
|
|
|
placeholder={loc.send.details_note_placeholder}
|
2020-06-09 16:08:18 +02:00
|
|
|
placeholderTextColor="#81868e"
|
|
|
|
value={this.state.memo}
|
|
|
|
numberOfLines={1}
|
|
|
|
style={styles.memoText}
|
|
|
|
editable={!this.state.isLoading}
|
|
|
|
onSubmitEditing={Keyboard.dismiss}
|
|
|
|
inputAccessoryViewID={BlueDismissKeyboardInputAccessory.InputAccessoryViewID}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
<TouchableOpacity
|
2020-09-15 16:02:10 +02:00
|
|
|
testID="chooseFee"
|
2020-09-14 12:49:08 +02:00
|
|
|
onPress={() => this.setState({ isFeeSelectionModalVisible: true }, () => this.reCalcTx(true))}
|
2020-06-09 16:08:18 +02:00
|
|
|
disabled={this.state.isLoading}
|
|
|
|
style={styles.fee}
|
|
|
|
>
|
2020-07-20 15:38:46 +02:00
|
|
|
<Text style={styles.feeLabel}>{loc.send.create_fee}</Text>
|
2020-06-09 16:08:18 +02:00
|
|
|
<View style={styles.feeRow}>
|
2020-09-14 12:49:08 +02:00
|
|
|
<Text style={styles.feeValue}>
|
|
|
|
{this.state.feePrecalc.current ? this.formatFee(this.state.feePrecalc.current) : this.state.fee + ' sat/byte'}
|
|
|
|
</Text>
|
2018-12-24 01:44:31 +01:00
|
|
|
</View>
|
2020-06-09 16:08:18 +02:00
|
|
|
</TouchableOpacity>
|
|
|
|
{this.renderCreateButton()}
|
|
|
|
{this.renderFeeSelectionModal()}
|
|
|
|
{this.renderAdvancedTransactionOptionsModal()}
|
|
|
|
</KeyboardAvoidingView>
|
2018-12-24 01:44:31 +01:00
|
|
|
</View>
|
2019-02-17 10:23:12 +01:00
|
|
|
<BlueDismissKeyboardInputAccessory />
|
2019-08-06 00:25:36 +02:00
|
|
|
{Platform.select({
|
2020-06-09 16:08:18 +02:00
|
|
|
ios: (
|
|
|
|
<BlueUseAllFundsButton unit={this.state.amountUnit} onUseAllPressed={this.onUseAllPressed} wallet={this.state.fromWallet} />
|
|
|
|
),
|
2019-08-06 00:25:36 +02:00
|
|
|
android: this.state.isAmountToolbarVisibleForAndroid && (
|
2020-06-09 16:08:18 +02:00
|
|
|
<BlueUseAllFundsButton unit={this.state.amountUnit} onUseAllPressed={this.onUseAllPressed} wallet={this.state.fromWallet} />
|
2019-08-06 00:25:36 +02:00
|
|
|
),
|
|
|
|
})}
|
|
|
|
|
2018-12-24 01:44:31 +01:00
|
|
|
{this.renderWalletSelectionButton()}
|
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
|
|
|
|
|
|
|
SendDetails.propTypes = {
|
|
|
|
navigation: PropTypes.shape({
|
2019-02-01 16:28:43 +01:00
|
|
|
pop: PropTypes.func,
|
2019-02-18 08:25:27 +01:00
|
|
|
goBack: PropTypes.func,
|
2018-03-18 03:48:23 +01:00
|
|
|
navigate: PropTypes.func,
|
2019-09-03 05:28:52 +02:00
|
|
|
setParams: PropTypes.func,
|
2020-05-27 13:12:17 +02:00
|
|
|
}),
|
|
|
|
route: PropTypes.shape({
|
|
|
|
name: PropTypes.string,
|
|
|
|
params: PropTypes.shape({
|
|
|
|
amount: PropTypes.number,
|
|
|
|
address: PropTypes.string,
|
|
|
|
satoshiPerByte: PropTypes.string,
|
|
|
|
fromWallet: PropTypes.fromWallet,
|
|
|
|
memo: PropTypes.string,
|
|
|
|
uri: PropTypes.string,
|
2018-03-18 03:48:23 +01:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
};
|
2020-07-15 19:32:59 +02:00
|
|
|
|
|
|
|
SendDetails.navigationOptions = ({ navigation, route }) => ({
|
|
|
|
...BlueCreateTxNavigationStyle(navigation, route.params.withAdvancedOptionsMenuButton, route.params.advancedOptionsMenuButtonAction),
|
|
|
|
title: loc.send.header,
|
|
|
|
});
|