2018-01-30 23:42:38 +01:00
|
|
|
import React, { Component } from 'react';
|
2019-07-13 17:20:38 +02:00
|
|
|
import { View, ActivityIndicator, ScrollView, TouchableOpacity, Linking } from 'react-native';
|
2018-09-29 17:35:04 +02:00
|
|
|
import {
|
|
|
|
BlueButton,
|
|
|
|
SafeBlueArea,
|
|
|
|
BlueCard,
|
|
|
|
BlueText,
|
|
|
|
BlueHeaderDefaultSub,
|
|
|
|
BlueLoading,
|
|
|
|
BlueSpacing20,
|
|
|
|
BlueCopyToClipboardButton,
|
2018-10-29 23:11:48 +01:00
|
|
|
BlueNavigationStyle,
|
2018-09-29 17:35:04 +02:00
|
|
|
} from '../../BlueComponents';
|
2018-03-18 03:48:23 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2019-07-13 17:20:38 +02:00
|
|
|
import { HDSegwitBech32Transaction, HDSegwitBech32Wallet } from '../../class';
|
2018-03-18 03:48:23 +01:00
|
|
|
/** @type {AppStorage} */
|
|
|
|
let BlueApp = require('../../BlueApp');
|
2018-05-28 21:18:11 +02:00
|
|
|
let loc = require('../../loc');
|
2018-12-11 23:52:46 +01:00
|
|
|
const dayjs = require('dayjs');
|
2018-12-27 07:12:19 +01:00
|
|
|
|
2019-07-13 17:20:38 +02:00
|
|
|
const buttonStatus = Object.freeze({
|
|
|
|
possible: 1,
|
|
|
|
unknown: 2,
|
|
|
|
notPossible: 3,
|
|
|
|
});
|
|
|
|
|
2018-09-11 20:17:24 +02:00
|
|
|
function onlyUnique(value, index, self) {
|
|
|
|
return self.indexOf(value) === index;
|
|
|
|
}
|
|
|
|
|
|
|
|
function arrDiff(a1, a2) {
|
|
|
|
let ret = [];
|
|
|
|
for (let v of a2) {
|
|
|
|
if (a1.indexOf(v) === -1) {
|
|
|
|
ret.push(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-01-30 23:42:38 +01:00
|
|
|
export default class TransactionsDetails extends Component {
|
2018-10-29 23:11:48 +01:00
|
|
|
static navigationOptions = () => ({
|
|
|
|
...BlueNavigationStyle(),
|
|
|
|
});
|
2018-01-30 23:42:38 +01:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-03-17 21:39:21 +01:00
|
|
|
let hash = props.navigation.state.params.hash;
|
|
|
|
let foundTx = {};
|
|
|
|
let from = [];
|
|
|
|
let to = [];
|
2018-01-30 23:42:38 +01:00
|
|
|
for (let tx of BlueApp.getTransactions()) {
|
|
|
|
if (tx.hash === hash) {
|
|
|
|
foundTx = tx;
|
|
|
|
for (let input of foundTx.inputs) {
|
2018-03-17 21:39:21 +01:00
|
|
|
from = from.concat(input.addresses);
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
for (let output of foundTx.outputs) {
|
2019-06-10 00:25:57 +02:00
|
|
|
if (output.addresses) to = to.concat(output.addresses);
|
2019-06-11 01:18:40 +02:00
|
|
|
if (output.scriptPubKey && output.scriptPubKey.addresses) to = to.concat(output.scriptPubKey.addresses);
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-31 21:14:28 +01:00
|
|
|
let wallet = false;
|
|
|
|
for (let w of BlueApp.getWallets()) {
|
|
|
|
for (let t of w.getTransactions()) {
|
|
|
|
if (t.hash === hash) {
|
|
|
|
console.log('tx', hash, 'belongs to', w.getLabel());
|
|
|
|
wallet = w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-30 23:42:38 +01:00
|
|
|
this.state = {
|
|
|
|
isLoading: true,
|
|
|
|
tx: foundTx,
|
|
|
|
from,
|
|
|
|
to,
|
2018-10-31 21:14:28 +01:00
|
|
|
wallet,
|
2019-07-13 17:20:38 +02:00
|
|
|
isCPFPpossible: buttonStatus.unknown,
|
2019-07-14 13:40:31 +02:00
|
|
|
isRBFBumpFeePossible: buttonStatus.unknown,
|
|
|
|
isRBFCancelPossible: buttonStatus.unknown,
|
2018-03-17 21:39:21 +01:00
|
|
|
};
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount() {
|
2018-03-17 21:39:21 +01:00
|
|
|
console.log('transactions/details - componentDidMount');
|
2018-01-30 23:42:38 +01:00
|
|
|
this.setState({
|
|
|
|
isLoading: false,
|
2018-03-17 21:39:21 +01:00
|
|
|
});
|
2019-07-13 17:20:38 +02:00
|
|
|
|
2019-07-14 13:40:31 +02:00
|
|
|
try {
|
|
|
|
await this.checkPossibilityOfCPFP();
|
|
|
|
await this.checkPossibilityOfRBFBumpFee();
|
|
|
|
await this.checkPossibilityOfRBFCancel();
|
|
|
|
} catch (_) {
|
|
|
|
this.setState({
|
|
|
|
isCPFPpossible: buttonStatus.notPossible,
|
|
|
|
isRBFBumpFeePossible: buttonStatus.notPossible,
|
|
|
|
isRBFCancelPossible: buttonStatus.notPossible,
|
|
|
|
});
|
|
|
|
}
|
2019-07-13 17:20:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async checkPossibilityOfCPFP() {
|
|
|
|
if (this.state.wallet.type !== HDSegwitBech32Wallet.type) {
|
|
|
|
return this.setState({ isCPFPpossible: buttonStatus.notPossible });
|
|
|
|
}
|
|
|
|
|
|
|
|
let tx = new HDSegwitBech32Transaction(null, this.state.tx.hash, this.state.wallet);
|
2019-07-14 13:40:31 +02:00
|
|
|
if ((await tx.isToUsTransaction()) && (await tx.getRemoteConfirmationsNum()) === 0) {
|
2019-07-13 17:20:38 +02:00
|
|
|
return this.setState({ isCPFPpossible: buttonStatus.possible });
|
|
|
|
} else {
|
|
|
|
return this.setState({ isCPFPpossible: buttonStatus.notPossible });
|
|
|
|
}
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
|
2019-07-14 13:40:31 +02:00
|
|
|
async checkPossibilityOfRBFBumpFee() {
|
|
|
|
if (this.state.wallet.type !== HDSegwitBech32Wallet.type) {
|
|
|
|
return this.setState({ isRBFBumpFeePossible: buttonStatus.notPossible });
|
|
|
|
}
|
|
|
|
|
|
|
|
let tx = new HDSegwitBech32Transaction(null, this.state.tx.hash, this.state.wallet);
|
|
|
|
if ((await tx.isOurTransaction()) && /* (await tx.getRemoteConfirmationsNum()) === 0 && FIXME */ (await tx.isSequenceReplaceable())) {
|
|
|
|
return this.setState({ isRBFBumpFeePossible: buttonStatus.possible });
|
|
|
|
} else {
|
|
|
|
return this.setState({ isRBFBumpFeePossible: buttonStatus.notPossible });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async checkPossibilityOfRBFCancel() {
|
|
|
|
if (this.state.wallet.type !== HDSegwitBech32Wallet.type) {
|
|
|
|
return this.setState({ isRBFCancelPossible: buttonStatus.notPossible });
|
|
|
|
}
|
|
|
|
|
|
|
|
let tx = new HDSegwitBech32Transaction(null, this.state.tx.hash, this.state.wallet);
|
|
|
|
if (
|
|
|
|
(await tx.isOurTransaction()) &&
|
|
|
|
/* (await tx.getRemoteConfirmationsNum()) === 0 && FIXME */ (await tx.isSequenceReplaceable()) &&
|
|
|
|
(await tx.canCancelTx())
|
|
|
|
) {
|
|
|
|
return this.setState({ isRBFCancelPossible: buttonStatus.possible });
|
|
|
|
} else {
|
|
|
|
return this.setState({ isRBFCancelPossible: buttonStatus.notPossible });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-30 23:42:38 +01:00
|
|
|
render() {
|
2018-10-27 17:13:09 +02:00
|
|
|
if (this.state.isLoading || !this.state.hasOwnProperty('tx')) {
|
2018-03-17 21:39:21 +01:00
|
|
|
return <BlueLoading />;
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2018-06-28 03:43:28 +02:00
|
|
|
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1 }}>
|
2018-10-29 23:11:48 +01:00
|
|
|
<BlueHeaderDefaultSub leftText={loc.transactions.details.title} rightComponent={null} />
|
2018-09-29 00:17:26 +02:00
|
|
|
<ScrollView style={{ flex: 1 }}>
|
|
|
|
<BlueCard>
|
2019-01-30 01:50:50 +01:00
|
|
|
{(() => {
|
|
|
|
if (this.state.tx.confirmations === 0 && this.state.wallet && this.state.wallet.allowRBF()) {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<BlueButton
|
|
|
|
onPress={() =>
|
|
|
|
this.props.navigation.navigate('RBF', {
|
|
|
|
txid: this.state.tx.hash,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
title="Replace-By-Fee (RBF)"
|
|
|
|
/>
|
|
|
|
<BlueSpacing20 />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})()}
|
|
|
|
|
2019-07-13 17:20:38 +02:00
|
|
|
{(() => {
|
|
|
|
if (this.state.isCPFPpossible === buttonStatus.unknown) {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<ActivityIndicator />
|
|
|
|
<BlueSpacing20 />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
} else if (this.state.isCPFPpossible === buttonStatus.possible) {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<BlueButton
|
|
|
|
onPress={() =>
|
|
|
|
this.props.navigation.navigate('CPFP', {
|
|
|
|
txid: this.state.tx.hash,
|
|
|
|
wallet: this.state.wallet,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
title="Bump fee (CPFP)"
|
|
|
|
/>
|
|
|
|
<BlueSpacing20 />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
2019-07-14 13:40:31 +02:00
|
|
|
})()}
|
|
|
|
|
|
|
|
{(() => {
|
|
|
|
if (this.state.isRBFBumpFeePossible === buttonStatus.unknown) {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<ActivityIndicator />
|
|
|
|
<BlueSpacing20 />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
} else if (this.state.isRBFBumpFeePossible === buttonStatus.possible) {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<BlueButton
|
|
|
|
onPress={() =>
|
|
|
|
this.props.navigation.navigate('RBFBumpFee', {
|
|
|
|
txid: this.state.tx.hash,
|
|
|
|
wallet: this.state.wallet,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
title="Bump fee (RBF)"
|
|
|
|
/>
|
|
|
|
<BlueSpacing20 />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})()}
|
|
|
|
|
|
|
|
{(() => {
|
|
|
|
if (this.state.isRBFCancelPossible === buttonStatus.unknown) {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<ActivityIndicator />
|
|
|
|
<BlueSpacing20 />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
} else if (this.state.isRBFCancelPossible === buttonStatus.possible) {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<BlueButton
|
|
|
|
onPress={() =>
|
|
|
|
this.props.navigation.navigate('RBFCancel', {
|
|
|
|
txid: this.state.tx.hash,
|
|
|
|
wallet: this.state.wallet,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
title="Cancel this transaction (RBF)"
|
|
|
|
/>
|
|
|
|
<BlueSpacing20 />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
2019-07-13 17:20:38 +02:00
|
|
|
})()}
|
|
|
|
|
2018-09-29 00:17:26 +02:00
|
|
|
{(() => {
|
|
|
|
if (BlueApp.tx_metadata[this.state.tx.hash]) {
|
|
|
|
if (BlueApp.tx_metadata[this.state.tx.hash]['memo']) {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<BlueText h4>{BlueApp.tx_metadata[this.state.tx.hash]['memo']}</BlueText>
|
|
|
|
<BlueSpacing20 />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
2018-09-29 00:17:26 +02:00
|
|
|
})()}
|
2018-01-30 23:42:38 +01:00
|
|
|
|
2018-10-27 17:13:09 +02:00
|
|
|
{this.state.hasOwnProperty('from') && (
|
|
|
|
<React.Fragment>
|
|
|
|
<View style={{ flex: 1, flexDirection: 'row', marginBottom: 4, justifyContent: 'space-between' }}>
|
|
|
|
<BlueText style={{ fontSize: 16, fontWeight: '500', marginBottom: 4 }}>{loc.transactions.details.from}</BlueText>
|
|
|
|
<BlueCopyToClipboardButton stringToCopy={this.state.from.filter(onlyUnique).join(', ')} />
|
|
|
|
</View>
|
|
|
|
<BlueText style={{ marginBottom: 26, color: 'grey' }}>{this.state.from.filter(onlyUnique).join(', ')}</BlueText>
|
|
|
|
</React.Fragment>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{this.state.hasOwnProperty('to') && (
|
|
|
|
<React.Fragment>
|
|
|
|
<View style={{ flex: 1, flexDirection: 'row', marginBottom: 4, justifyContent: 'space-between' }}>
|
|
|
|
<BlueText style={{ fontSize: 16, fontWeight: '500', marginBottom: 4 }}>{loc.transactions.details.to}</BlueText>
|
|
|
|
<BlueCopyToClipboardButton stringToCopy={this.state.to.filter(onlyUnique).join(', ')} />
|
|
|
|
</View>
|
|
|
|
<BlueText style={{ marginBottom: 26, color: 'grey' }}>
|
|
|
|
{arrDiff(this.state.from, this.state.to.filter(onlyUnique)).join(', ')}
|
|
|
|
</BlueText>
|
|
|
|
</React.Fragment>
|
|
|
|
)}
|
|
|
|
|
2018-12-19 02:46:06 +01:00
|
|
|
{this.state.tx.hasOwnProperty('fee') && (
|
|
|
|
<React.Fragment>
|
|
|
|
<BlueText style={{ fontSize: 16, fontWeight: '500', marginBottom: 4 }}>{loc.send.create.fee}</BlueText>
|
2018-12-25 02:06:52 +01:00
|
|
|
<BlueText style={{ marginBottom: 26, color: 'grey' }}>{this.state.tx.fee + ' sats'}</BlueText>
|
2018-12-19 02:46:06 +01:00
|
|
|
</React.Fragment>
|
|
|
|
)}
|
|
|
|
|
2018-10-27 17:13:09 +02:00
|
|
|
{this.state.tx.hasOwnProperty('hash') && (
|
|
|
|
<React.Fragment>
|
|
|
|
<View style={{ flex: 1, flexDirection: 'row', marginBottom: 4, justifyContent: 'space-between' }}>
|
|
|
|
<BlueText style={{ fontSize: 16, fontWeight: '500' }}>Txid</BlueText>
|
|
|
|
<BlueCopyToClipboardButton stringToCopy={this.state.tx.hash} />
|
|
|
|
</View>
|
2018-12-27 15:27:47 +01:00
|
|
|
<BlueText style={{ marginBottom: 8, color: 'grey' }}>{this.state.tx.hash}</BlueText>
|
2018-10-27 17:13:09 +02:00
|
|
|
<TouchableOpacity
|
|
|
|
onPress={() => {
|
2019-06-07 21:45:35 +02:00
|
|
|
const url = `https://blockstream.info/tx/${this.state.tx.hash}`;
|
2018-10-27 17:13:09 +02:00
|
|
|
Linking.canOpenURL(url).then(supported => {
|
|
|
|
if (supported) {
|
|
|
|
Linking.openURL(url);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
2018-12-27 15:27:47 +01:00
|
|
|
<BlueText style={{ marginBottom: 26, color: '#2f5fb3' }}>{loc.transactions.details.show_in_block_explorer}</BlueText>
|
2018-10-27 17:13:09 +02:00
|
|
|
</TouchableOpacity>
|
|
|
|
</React.Fragment>
|
|
|
|
)}
|
2018-12-19 02:46:06 +01:00
|
|
|
|
2018-10-27 17:13:09 +02:00
|
|
|
{this.state.tx.hasOwnProperty('received') && (
|
|
|
|
<React.Fragment>
|
|
|
|
<BlueText style={{ fontSize: 16, fontWeight: '500', marginBottom: 4 }}>Received</BlueText>
|
2018-12-11 23:52:46 +01:00
|
|
|
<BlueText style={{ marginBottom: 26, color: 'grey' }}>{dayjs(this.state.tx.received).format('MM/DD/YYYY h:mm A')}</BlueText>
|
2018-10-27 17:13:09 +02:00
|
|
|
</React.Fragment>
|
|
|
|
)}
|
|
|
|
|
2019-01-30 01:50:50 +01:00
|
|
|
{this.state.tx.hasOwnProperty('block_height') && this.state.tx.block_height > 0 && (
|
2018-10-27 17:13:09 +02:00
|
|
|
<React.Fragment>
|
|
|
|
<BlueText style={{ fontSize: 16, fontWeight: '500', marginBottom: 4 }}>Block Height</BlueText>
|
2018-12-11 23:52:46 +01:00
|
|
|
<BlueText style={{ marginBottom: 26, color: 'grey' }}>{this.state.tx.block_height}</BlueText>
|
2018-10-27 17:13:09 +02:00
|
|
|
</React.Fragment>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{this.state.tx.hasOwnProperty('inputs') && (
|
|
|
|
<React.Fragment>
|
|
|
|
<BlueText style={{ fontSize: 16, fontWeight: '500', marginBottom: 4 }}>Inputs</BlueText>
|
|
|
|
<BlueText style={{ marginBottom: 26, color: 'grey' }}>{this.state.tx.inputs.length}</BlueText>
|
|
|
|
</React.Fragment>
|
|
|
|
)}
|
|
|
|
|
2019-02-01 21:04:00 +01:00
|
|
|
{this.state.tx.hasOwnProperty('outputs') && this.state.tx.outputs.length > 0 && (
|
2018-10-27 17:13:09 +02:00
|
|
|
<React.Fragment>
|
|
|
|
<BlueText style={{ fontSize: 16, fontWeight: '500', marginBottom: 4 }}>Outputs</BlueText>
|
|
|
|
<BlueText style={{ marginBottom: 26, color: 'grey' }}>{this.state.tx.outputs.length}</BlueText>
|
|
|
|
</React.Fragment>
|
|
|
|
)}
|
2018-09-29 00:17:26 +02:00
|
|
|
</BlueCard>
|
|
|
|
</ScrollView>
|
2018-01-30 23:42:38 +01:00
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-03-18 03:48:23 +01:00
|
|
|
|
|
|
|
TransactionsDetails.propTypes = {
|
|
|
|
navigation: PropTypes.shape({
|
2019-02-01 16:28:43 +01:00
|
|
|
goBack: PropTypes.func,
|
2018-03-18 03:48:23 +01:00
|
|
|
navigate: PropTypes.func,
|
|
|
|
state: PropTypes.shape({
|
|
|
|
params: PropTypes.shape({
|
|
|
|
hash: PropTypes.string,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
};
|