2018-01-30 22:42:38 +00:00
|
|
|
import React, { Component } from 'react';
|
2020-05-24 12:17:26 +03:00
|
|
|
import { View, ScrollView, TouchableOpacity, Linking, StyleSheet } from 'react-native';
|
2018-09-29 11:35:04 -04:00
|
|
|
import {
|
|
|
|
SafeBlueArea,
|
|
|
|
BlueCard,
|
|
|
|
BlueText,
|
|
|
|
BlueHeaderDefaultSub,
|
|
|
|
BlueLoading,
|
|
|
|
BlueSpacing20,
|
|
|
|
BlueCopyToClipboardButton,
|
2018-10-29 18:11:48 -04:00
|
|
|
BlueNavigationStyle,
|
2018-09-29 11:35:04 -04:00
|
|
|
} from '../../BlueComponents';
|
2020-03-30 09:50:19 -04:00
|
|
|
import HandoffSettings from '../../class/handoff';
|
|
|
|
import Handoff from 'react-native-handoff';
|
2018-03-18 02:48:23 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
/** @type {AppStorage} */
|
2020-06-01 15:54:23 +03:00
|
|
|
const BlueApp = require('../../BlueApp');
|
|
|
|
const loc = require('../../loc');
|
2018-12-11 22:52:46 +00:00
|
|
|
const dayjs = require('dayjs');
|
2018-12-27 01:12:19 -05:00
|
|
|
|
2020-05-24 12:17:26 +03:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
root: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
scroll: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
rowHeader: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
marginBottom: 4,
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
},
|
|
|
|
rowCaption: {
|
|
|
|
fontSize: 16,
|
|
|
|
fontWeight: '500',
|
|
|
|
marginBottom: 4,
|
|
|
|
},
|
|
|
|
rowValue: {
|
|
|
|
marginBottom: 26,
|
|
|
|
color: 'grey',
|
|
|
|
},
|
|
|
|
txId: {
|
|
|
|
fontSize: 16,
|
|
|
|
fontWeight: '500',
|
|
|
|
},
|
|
|
|
txHash: {
|
|
|
|
marginBottom: 8,
|
|
|
|
color: 'grey',
|
|
|
|
},
|
|
|
|
txLink: {
|
|
|
|
marginBottom: 26,
|
|
|
|
color: '#2f5fb3',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-09-11 19:17:24 +01:00
|
|
|
function onlyUnique(value, index, self) {
|
|
|
|
return self.indexOf(value) === index;
|
|
|
|
}
|
|
|
|
|
|
|
|
function arrDiff(a1, a2) {
|
2020-06-01 15:54:23 +03:00
|
|
|
const ret = [];
|
|
|
|
for (const v of a2) {
|
2018-09-11 19:17:24 +01:00
|
|
|
if (a1.indexOf(v) === -1) {
|
|
|
|
ret.push(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-01-30 22:42:38 +00:00
|
|
|
export default class TransactionsDetails extends Component {
|
2018-10-29 18:11:48 -04:00
|
|
|
static navigationOptions = () => ({
|
|
|
|
...BlueNavigationStyle(),
|
|
|
|
});
|
2018-01-30 22:42:38 +00:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2020-06-01 15:54:23 +03:00
|
|
|
const hash = props.route.params.hash;
|
2018-03-17 22:39:21 +02:00
|
|
|
let foundTx = {};
|
|
|
|
let from = [];
|
|
|
|
let to = [];
|
2020-06-01 15:54:23 +03:00
|
|
|
for (const tx of BlueApp.getTransactions()) {
|
2018-01-30 22:42:38 +00:00
|
|
|
if (tx.hash === hash) {
|
|
|
|
foundTx = tx;
|
2020-06-01 15:54:23 +03:00
|
|
|
for (const input of foundTx.inputs) {
|
2018-03-17 22:39:21 +02:00
|
|
|
from = from.concat(input.addresses);
|
2018-01-30 22:42:38 +00:00
|
|
|
}
|
2020-06-01 15:54:23 +03:00
|
|
|
for (const output of foundTx.outputs) {
|
2019-06-09 23:25:57 +01:00
|
|
|
if (output.addresses) to = to.concat(output.addresses);
|
2019-06-11 00:18:40 +01:00
|
|
|
if (output.scriptPubKey && output.scriptPubKey.addresses) to = to.concat(output.scriptPubKey.addresses);
|
2018-01-30 22:42:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-31 20:14:28 +00:00
|
|
|
let wallet = false;
|
2020-06-01 15:54:23 +03:00
|
|
|
for (const w of BlueApp.getWallets()) {
|
|
|
|
for (const t of w.getTransactions()) {
|
2018-10-31 20:14:28 +00:00
|
|
|
if (t.hash === hash) {
|
|
|
|
console.log('tx', hash, 'belongs to', w.getLabel());
|
|
|
|
wallet = w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-30 22:42:38 +00:00
|
|
|
this.state = {
|
|
|
|
isLoading: true,
|
|
|
|
tx: foundTx,
|
|
|
|
from,
|
|
|
|
to,
|
2018-10-31 20:14:28 +00:00
|
|
|
wallet,
|
2020-03-30 09:50:19 -04:00
|
|
|
isHandOffUseEnabled: false,
|
2018-03-17 22:39:21 +02:00
|
|
|
};
|
2018-01-30 22:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount() {
|
2018-03-17 22:39:21 +02:00
|
|
|
console.log('transactions/details - componentDidMount');
|
2020-03-30 09:50:19 -04:00
|
|
|
const isHandOffUseEnabled = await HandoffSettings.isHandoffUseEnabled();
|
2018-01-30 22:42:38 +00:00
|
|
|
this.setState({
|
|
|
|
isLoading: false,
|
2020-03-30 09:50:19 -04:00
|
|
|
isHandOffUseEnabled,
|
2018-03-17 22:39:21 +02:00
|
|
|
});
|
2019-07-14 12:40:31 +01:00
|
|
|
}
|
|
|
|
|
2018-01-30 22:42:38 +00:00
|
|
|
render() {
|
2020-06-01 15:54:23 +03:00
|
|
|
if (this.state.isLoading || !('tx' in this.state)) {
|
2018-03-17 22:39:21 +02:00
|
|
|
return <BlueLoading />;
|
2018-01-30 22:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-05-24 12:17:26 +03:00
|
|
|
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={styles.root}>
|
2020-03-30 09:50:19 -04:00
|
|
|
{this.state.isHandOffUseEnabled && (
|
|
|
|
<Handoff
|
|
|
|
title={`Bitcoin Transaction ${this.state.tx.hash}`}
|
|
|
|
type="io.bluewallet.bluewallet"
|
|
|
|
url={`https://blockstream.info/tx/${this.state.tx.hash}`}
|
|
|
|
/>
|
|
|
|
)}
|
2018-10-29 18:11:48 -04:00
|
|
|
<BlueHeaderDefaultSub leftText={loc.transactions.details.title} rightComponent={null} />
|
2020-05-24 12:17:26 +03:00
|
|
|
<ScrollView style={styles.scroll}>
|
2018-09-28 18:17:26 -04:00
|
|
|
<BlueCard>
|
|
|
|
{(() => {
|
|
|
|
if (BlueApp.tx_metadata[this.state.tx.hash]) {
|
2020-06-01 15:54:23 +03:00
|
|
|
if (BlueApp.tx_metadata[this.state.tx.hash].memo) {
|
2018-09-28 18:17:26 -04:00
|
|
|
return (
|
|
|
|
<View>
|
2020-06-01 15:54:23 +03:00
|
|
|
<BlueText h4>{BlueApp.tx_metadata[this.state.tx.hash].memo}</BlueText>
|
2018-09-28 18:17:26 -04:00
|
|
|
<BlueSpacing20 />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2018-01-30 22:42:38 +00:00
|
|
|
}
|
2018-09-28 18:17:26 -04:00
|
|
|
})()}
|
2018-01-30 22:42:38 +00:00
|
|
|
|
2020-06-01 15:54:23 +03:00
|
|
|
{'from' in this.state && (
|
|
|
|
<>
|
2020-05-24 12:17:26 +03:00
|
|
|
<View style={styles.rowHeader}>
|
|
|
|
<BlueText style={styles.rowCaption}>{loc.transactions.details.from}</BlueText>
|
2018-10-27 11:13:09 -04:00
|
|
|
<BlueCopyToClipboardButton stringToCopy={this.state.from.filter(onlyUnique).join(', ')} />
|
|
|
|
</View>
|
2020-05-24 12:17:26 +03:00
|
|
|
<BlueText style={styles.rowValue}>{this.state.from.filter(onlyUnique).join(', ')}</BlueText>
|
2020-06-01 15:54:23 +03:00
|
|
|
</>
|
2018-10-27 11:13:09 -04:00
|
|
|
)}
|
|
|
|
|
2020-06-01 15:54:23 +03:00
|
|
|
{'to' in this.state && (
|
|
|
|
<>
|
2020-05-24 12:17:26 +03:00
|
|
|
<View style={styles.rowHeader}>
|
|
|
|
<BlueText style={styles.rowCaption}>{loc.transactions.details.to}</BlueText>
|
2018-10-27 11:13:09 -04:00
|
|
|
<BlueCopyToClipboardButton stringToCopy={this.state.to.filter(onlyUnique).join(', ')} />
|
|
|
|
</View>
|
2020-05-24 12:17:26 +03:00
|
|
|
<BlueText style={styles.rowValue}>{arrDiff(this.state.from, this.state.to.filter(onlyUnique)).join(', ')}</BlueText>
|
2020-06-01 15:54:23 +03:00
|
|
|
</>
|
2018-10-27 11:13:09 -04:00
|
|
|
)}
|
|
|
|
|
2020-06-01 15:54:23 +03:00
|
|
|
{'fee' in this.state.tx && (
|
|
|
|
<>
|
2020-05-24 12:17:26 +03:00
|
|
|
<BlueText style={styles.rowCaption}>{loc.send.create.fee}</BlueText>
|
|
|
|
<BlueText style={styles.rowValue}>{this.state.tx.fee + ' sats'}</BlueText>
|
2020-06-01 15:54:23 +03:00
|
|
|
</>
|
2018-12-18 20:46:06 -05:00
|
|
|
)}
|
|
|
|
|
2020-06-01 15:54:23 +03:00
|
|
|
{'hash' in this.state.tx && (
|
|
|
|
<>
|
2020-05-24 12:17:26 +03:00
|
|
|
<View style={styles.rowHeader}>
|
|
|
|
<BlueText style={styles.txId}>Txid</BlueText>
|
2018-10-27 11:13:09 -04:00
|
|
|
<BlueCopyToClipboardButton stringToCopy={this.state.tx.hash} />
|
|
|
|
</View>
|
2020-05-24 12:17:26 +03:00
|
|
|
<BlueText style={styles.txHash}>{this.state.tx.hash}</BlueText>
|
2018-10-27 11:13:09 -04:00
|
|
|
<TouchableOpacity
|
|
|
|
onPress={() => {
|
2019-06-07 15:45:35 -04:00
|
|
|
const url = `https://blockstream.info/tx/${this.state.tx.hash}`;
|
2018-10-27 11:13:09 -04:00
|
|
|
Linking.canOpenURL(url).then(supported => {
|
|
|
|
if (supported) {
|
|
|
|
Linking.openURL(url);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
2020-05-24 12:17:26 +03:00
|
|
|
<BlueText style={styles.txLink}>{loc.transactions.details.show_in_block_explorer}</BlueText>
|
2018-10-27 11:13:09 -04:00
|
|
|
</TouchableOpacity>
|
2020-06-01 15:54:23 +03:00
|
|
|
</>
|
2018-10-27 11:13:09 -04:00
|
|
|
)}
|
2018-12-18 20:46:06 -05:00
|
|
|
|
2020-06-01 15:54:23 +03:00
|
|
|
{'received' in this.state.tx && (
|
|
|
|
<>
|
2020-05-24 12:17:26 +03:00
|
|
|
<BlueText style={styles.rowCaption}>Received</BlueText>
|
|
|
|
<BlueText style={styles.rowValue}>{dayjs(this.state.tx.received).format('MM/DD/YYYY h:mm A')}</BlueText>
|
2020-06-01 15:54:23 +03:00
|
|
|
</>
|
2018-10-27 11:13:09 -04:00
|
|
|
)}
|
|
|
|
|
2020-06-01 15:54:23 +03:00
|
|
|
{'block_height' in this.state.tx && this.state.tx.block_height > 0 && (
|
|
|
|
<>
|
2020-05-24 12:17:26 +03:00
|
|
|
<BlueText style={styles.rowCaption}>Block Height</BlueText>
|
|
|
|
<BlueText style={styles.rowValue}>{this.state.tx.block_height}</BlueText>
|
2020-06-01 15:54:23 +03:00
|
|
|
</>
|
2018-10-27 11:13:09 -04:00
|
|
|
)}
|
|
|
|
|
2020-06-01 15:54:23 +03:00
|
|
|
{'inputs' in this.state.tx && (
|
|
|
|
<>
|
2020-05-24 12:17:26 +03:00
|
|
|
<BlueText style={styles.rowCaption}>Inputs</BlueText>
|
|
|
|
<BlueText style={styles.rowValue}>{this.state.tx.inputs.length}</BlueText>
|
2020-06-01 15:54:23 +03:00
|
|
|
</>
|
2018-10-27 11:13:09 -04:00
|
|
|
)}
|
|
|
|
|
2020-06-01 15:54:23 +03:00
|
|
|
{'outputs' in this.state.tx && this.state.tx.outputs.length > 0 && (
|
|
|
|
<>
|
2020-05-24 12:17:26 +03:00
|
|
|
<BlueText style={styles.rowCaption}>Outputs</BlueText>
|
|
|
|
<BlueText style={styles.rowValue}>{this.state.tx.outputs.length}</BlueText>
|
2020-06-01 15:54:23 +03:00
|
|
|
</>
|
2018-10-27 11:13:09 -04:00
|
|
|
)}
|
2018-09-28 18:17:26 -04:00
|
|
|
</BlueCard>
|
|
|
|
</ScrollView>
|
2018-01-30 22:42:38 +00:00
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-03-18 02:48:23 +00:00
|
|
|
|
|
|
|
TransactionsDetails.propTypes = {
|
2020-05-27 14:12:17 +03:00
|
|
|
route: PropTypes.shape({
|
|
|
|
name: PropTypes.string,
|
|
|
|
params: PropTypes.shape({
|
|
|
|
hash: PropTypes.string,
|
2018-03-18 02:48:23 +00:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
};
|