2020-01-04 06:02:30 +01:00
|
|
|
/* global alert */
|
2018-01-30 23:42:38 +01:00
|
|
|
import React, { Component } from 'react';
|
2019-09-03 05:28:52 +02:00
|
|
|
import {
|
|
|
|
TextInput,
|
|
|
|
FlatList,
|
|
|
|
ScrollView,
|
|
|
|
Linking,
|
|
|
|
TouchableOpacity,
|
|
|
|
Clipboard,
|
|
|
|
StyleSheet,
|
|
|
|
TouchableWithoutFeedback,
|
|
|
|
Keyboard,
|
|
|
|
Text,
|
|
|
|
View,
|
2020-01-04 06:02:30 +01:00
|
|
|
Platform,
|
2019-09-03 05:28:52 +02:00
|
|
|
} from 'react-native';
|
2018-10-29 23:11:48 +01:00
|
|
|
import { BlueNavigationStyle, SafeBlueArea, BlueCard, BlueText } from '../../BlueComponents';
|
2018-03-18 03:48:23 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2019-02-28 02:29:13 +01:00
|
|
|
import Privacy from '../../Privacy';
|
2019-09-03 05:28:52 +02:00
|
|
|
import { BitcoinUnit } from '../../models/bitcoinUnits';
|
2020-01-04 06:02:30 +01:00
|
|
|
import { Icon } from 'react-native-elements';
|
|
|
|
import Share from 'react-native-share';
|
|
|
|
import RNFS from 'react-native-fs';
|
|
|
|
import DirectoryPickerManager from 'react-native-directory-picker';
|
2019-09-03 05:28:52 +02:00
|
|
|
/** @type {AppStorage} */
|
|
|
|
const BlueApp = require('../../BlueApp');
|
|
|
|
const loc = require('../../loc');
|
|
|
|
const currency = require('../../currency');
|
2018-01-30 23:42:38 +01:00
|
|
|
|
|
|
|
export default class SendCreate extends Component {
|
2020-01-04 06:02:30 +01:00
|
|
|
static navigationOptions = ({ navigation }) => ({
|
2018-10-29 23:11:48 +01:00
|
|
|
...BlueNavigationStyle,
|
|
|
|
title: loc.send.create.details,
|
2020-01-04 06:02:30 +01:00
|
|
|
headerRight: navigation.state.params.exportTXN ? (
|
|
|
|
<TouchableOpacity style={{ marginRight: 16 }} onPress={navigation.state.params.exportTXN}>
|
|
|
|
<Icon size={22} name="share-alternative" type="entypo" color={BlueApp.settings.foregroundColor} />
|
|
|
|
</TouchableOpacity>
|
|
|
|
) : null,
|
2018-10-29 23:11:48 +01:00
|
|
|
});
|
|
|
|
|
2018-01-30 23:42:38 +01:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-03-17 21:39:21 +01:00
|
|
|
console.log('send/create constructor');
|
2020-01-04 06:02:30 +01:00
|
|
|
props.navigation.setParams({ exportTXN: this.exportTXN });
|
2018-01-30 23:42:38 +01:00
|
|
|
this.state = {
|
2018-10-20 23:10:21 +02:00
|
|
|
isLoading: false,
|
2018-10-27 17:13:09 +02:00
|
|
|
fee: props.navigation.getParam('fee'),
|
2019-09-03 05:28:52 +02:00
|
|
|
recipients: props.navigation.getParam('recipients'),
|
|
|
|
memo: props.navigation.getParam('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'),
|
2019-09-03 05:28:52 +02:00
|
|
|
wallet: props.navigation.getParam('wallet'),
|
|
|
|
feeSatoshi: props.navigation.getParam('feeSatoshi'),
|
2018-03-17 21:39:21 +01:00
|
|
|
};
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
|
2020-01-04 06:02:30 +01:00
|
|
|
componentDidMount() {
|
2019-02-28 02:29:13 +01:00
|
|
|
Privacy.enableBlur();
|
2018-03-17 21:39:21 +01:00
|
|
|
console.log('send/create - componentDidMount');
|
2018-10-20 23:10:21 +02:00
|
|
|
}
|
2018-03-17 21:39:21 +01:00
|
|
|
|
2020-01-04 06:02:30 +01:00
|
|
|
exportTXN = async () => {
|
|
|
|
const fileName = `${Date.now()}.txn`;
|
|
|
|
if (Platform.OS === 'ios') {
|
|
|
|
const filePath = RNFS.TemporaryDirectoryPath + `/${fileName}`;
|
|
|
|
await RNFS.writeFile(filePath, this.state.tx);
|
|
|
|
Share.open({
|
|
|
|
url: 'file://' + filePath,
|
|
|
|
})
|
|
|
|
.catch(error => console.log(error))
|
|
|
|
.finally(() => {
|
|
|
|
RNFS.unlink(filePath);
|
|
|
|
});
|
|
|
|
} else if (Platform.OS === 'android') {
|
|
|
|
DirectoryPickerManager.showDirectoryPicker(null, async response => {
|
|
|
|
if (response.didCancel) {
|
|
|
|
console.log('User cancelled directory picker');
|
|
|
|
} else if (response.error) {
|
|
|
|
console.log('DirectoryPickerManager Error: ', response.error);
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
await RNFS.writeFile(response.path + `/${fileName}`, this.state.tx, 'ascii');
|
|
|
|
alert('Successfully exported.');
|
|
|
|
RNFS.unlink(response.path + `/${fileName}`);
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
alert(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-28 02:29:13 +01:00
|
|
|
componentWillUnmount() {
|
|
|
|
Privacy.disableBlur();
|
|
|
|
}
|
|
|
|
|
2019-09-03 05:28:52 +02:00
|
|
|
_renderItem = ({ index, item }) => {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<View>
|
|
|
|
<Text style={styles.transactionDetailsTitle}>{loc.send.create.to}</Text>
|
|
|
|
<Text style={styles.transactionDetailsSubtitle}>{item.address}</Text>
|
|
|
|
<Text style={styles.transactionDetailsTitle}>{loc.send.create.amount}</Text>
|
|
|
|
<Text style={styles.transactionDetailsSubtitle}>
|
|
|
|
{item.amount === BitcoinUnit.MAX
|
|
|
|
? currency.satoshiToBTC(this.state.wallet.getBalance()) - this.state.fee
|
2019-09-27 13:36:08 +02:00
|
|
|
: item.amount || currency.satoshiToBTC(item.value)}{' '}
|
2019-09-03 05:28:52 +02:00
|
|
|
{BitcoinUnit.BTC}
|
|
|
|
</Text>
|
|
|
|
{this.state.recipients.length > 1 && (
|
|
|
|
<BlueText style={{ alignSelf: 'flex-end' }}>
|
|
|
|
{index + 1} of {this.state.recipients.length}
|
|
|
|
</BlueText>
|
|
|
|
)}
|
|
|
|
</View>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
renderSeparator = () => {
|
|
|
|
return <View style={{ backgroundColor: BlueApp.settings.inputBorderColor, height: 0.5, marginVertical: 16 }} />;
|
|
|
|
};
|
|
|
|
|
2018-01-30 23:42:38 +01:00
|
|
|
render() {
|
2018-10-20 23:10:21 +02:00
|
|
|
return (
|
|
|
|
<SafeBlueArea style={{ flex: 1, paddingTop: 19 }}>
|
2018-12-11 23:52:46 +01:00
|
|
|
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
|
|
|
|
<ScrollView>
|
|
|
|
<BlueCard style={{ alignItems: 'center', flex: 1 }}>
|
|
|
|
<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
|
|
|
|
value={this.state.tx}
|
|
|
|
/>
|
2018-10-20 23:10:21 +02:00
|
|
|
|
2018-12-11 23:52:46 +01:00
|
|
|
<TouchableOpacity style={{ marginVertical: 24 }} onPress={() => Clipboard.setString(this.state.tx)}>
|
|
|
|
<Text style={{ color: '#9aa0aa', fontSize: 15, fontWeight: '500', alignSelf: 'center' }}>Copy and broadcast later</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
<TouchableOpacity style={{ marginVertical: 24 }} onPress={() => Linking.openURL('https://coinb.in/?verify=' + this.state.tx)}>
|
|
|
|
<Text style={{ color: '#9aa0aa', fontSize: 15, fontWeight: '500', alignSelf: 'center' }}>Verify on coinb.in</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
</BlueCard>
|
|
|
|
<BlueCard>
|
2019-09-03 05:28:52 +02:00
|
|
|
<FlatList
|
|
|
|
scrollEnabled={this.state.recipients.length > 1}
|
|
|
|
extraData={this.state.recipients}
|
|
|
|
data={this.state.recipients}
|
|
|
|
renderItem={this._renderItem}
|
|
|
|
keyExtractor={(_item, index) => `${index}`}
|
|
|
|
ItemSeparatorComponent={this.renderSeparator}
|
|
|
|
/>
|
2018-12-11 23:52:46 +01:00
|
|
|
<Text style={styles.transactionDetailsTitle}>{loc.send.create.fee}</Text>
|
2019-09-03 05:28:52 +02:00
|
|
|
<Text style={styles.transactionDetailsSubtitle}>
|
|
|
|
{this.state.fee} {BitcoinUnit.BTC}
|
|
|
|
</Text>
|
2018-01-30 23:42:38 +01:00
|
|
|
|
2018-12-11 23:52:46 +01:00
|
|
|
<Text style={styles.transactionDetailsTitle}>{loc.send.create.tx_size}</Text>
|
|
|
|
<Text style={styles.transactionDetailsSubtitle}>{this.state.size} bytes</Text>
|
2018-08-19 00:10:12 +02:00
|
|
|
|
2018-12-11 23:52:46 +01:00
|
|
|
<Text style={styles.transactionDetailsTitle}>{loc.send.create.satoshi_per_byte}</Text>
|
|
|
|
<Text style={styles.transactionDetailsSubtitle}>{this.state.satoshiPerByte} Sat/B</Text>
|
2019-09-03 05:28:52 +02:00
|
|
|
{this.state.memo.length > 0 && (
|
|
|
|
<>
|
|
|
|
<Text style={styles.transactionDetailsTitle}>{loc.send.create.memo}</Text>
|
|
|
|
<Text style={styles.transactionDetailsSubtitle}>{this.state.memo}</Text>
|
|
|
|
</>
|
|
|
|
)}
|
2018-12-11 23:52:46 +01:00
|
|
|
</BlueCard>
|
|
|
|
</ScrollView>
|
|
|
|
</TouchableWithoutFeedback>
|
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({
|
2019-02-01 16:28:43 +01:00
|
|
|
goBack: PropTypes.func,
|
2020-01-04 06:02:30 +01:00
|
|
|
setParams: PropTypes.func,
|
2019-02-01 16:28:43 +01:00
|
|
|
getParam: PropTypes.func,
|
|
|
|
navigate: PropTypes.func,
|
|
|
|
dismiss: PropTypes.func,
|
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,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
};
|