You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

211 lines
7.2 KiB

7 years ago
import React, { Component } from 'react';
6 years ago
import { View, ScrollView, TouchableOpacity, Linking } from 'react-native';
import {
BlueButton,
SafeBlueArea,
BlueCard,
BlueText,
BlueHeaderDefaultSub,
BlueLoading,
BlueSpacing20,
BlueCopyToClipboardButton,
BlueNavigationStyle,
} from '../../BlueComponents';
7 years ago
import PropTypes from 'prop-types';
/** @type {AppStorage} */
let BlueApp = require('../../BlueApp');
let loc = require('../../loc');
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;
}
function formatTime(time) {
if (typeof time === 'string') {
time = time.replace('T', ' ').replace('Z', '');
time = time.split('.')[0];
}
return time;
}
7 years ago
export default class TransactionsDetails extends Component {
static navigationOptions = () => ({
...BlueNavigationStyle(),
});
7 years ago
constructor(props) {
super(props);
7 years ago
let hash = props.navigation.state.params.hash;
let foundTx = {};
let from = [];
let to = [];
7 years ago
for (let tx of BlueApp.getTransactions()) {
if (tx.hash === hash) {
console.log(tx);
foundTx = tx;
for (let input of foundTx.inputs) {
7 years ago
from = from.concat(input.addresses);
7 years ago
}
for (let output of foundTx.outputs) {
7 years ago
to = to.concat(output.addresses);
7 years ago
}
}
}
this.state = {
isLoading: true,
tx: foundTx,
from,
to,
7 years ago
};
7 years ago
}
async componentDidMount() {
7 years ago
console.log('transactions/details - componentDidMount');
7 years ago
this.setState({
isLoading: false,
7 years ago
});
7 years ago
}
render() {
if (this.state.isLoading || !this.state.hasOwnProperty('tx')) {
7 years ago
return <BlueLoading />;
7 years ago
}
return (
6 years ago
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1 }}>
<BlueHeaderDefaultSub leftText={loc.transactions.details.title} rightComponent={null} />
<ScrollView style={{ flex: 1 }}>
<BlueCard>
{(() => {
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>
);
}
7 years ago
}
})()}
7 years ago
{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>
)}
{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>
<TouchableOpacity
onPress={() => {
const url = `https://live.blockcypher.com/btc/tx/${this.state.tx.hash}`;
Linking.canOpenURL(url).then(supported => {
if (supported) {
Linking.openURL(url);
}
});
}}
>
<BlueText style={{ marginBottom: 26, color: 'grey' }}>{this.state.tx.hash}</BlueText>
</TouchableOpacity>
</React.Fragment>
)}
{this.state.tx.hasOwnProperty('received') && (
<React.Fragment>
<BlueText style={{ fontSize: 16, fontWeight: '500', marginBottom: 4 }}>Received</BlueText>
<BlueText style={{ marginBottom: 26, color: 'grey' }}>{formatTime(this.state.tx.received)}</BlueText>
</React.Fragment>
)}
{this.state.tx.hasOwnProperty('block_height') && (
<React.Fragment>
<BlueText style={{ fontSize: 16, fontWeight: '500', marginBottom: 4 }}>Block Height</BlueText>
<BlueText style={{ marginBottom: 26, color: 'grey' }}>{formatTime(this.state.tx.block_height)}</BlueText>
</React.Fragment>
)}
{this.state.tx.hasOwnProperty('confirmations') && (
<React.Fragment>
<BlueText style={{ fontSize: 16, fontWeight: '500', marginBottom: 4 }}>Confirmations</BlueText>
<BlueText style={{ marginBottom: 26, color: 'grey' }}>{this.state.tx.confirmations}</BlueText>
</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>
)}
{this.state.tx.hasOwnProperty('outputs') && (
<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>
)}
</BlueCard>
7 years ago
{(() => {
if (this.state.tx.confirmations === 0) {
return (
<BlueButton
onPress={() =>
this.props.navigation.navigate('RBF', {
txid: this.state.tx.hash,
})
}
title="Replace-By-Fee (RBF)"
/>
);
}
})()}
</ScrollView>
7 years ago
</SafeBlueArea>
);
}
}
7 years ago
TransactionsDetails.propTypes = {
navigation: PropTypes.shape({
goBack: PropTypes.function,
navigate: PropTypes.func,
state: PropTypes.shape({
params: PropTypes.shape({
hash: PropTypes.string,
}),
}),
}),
};