BlueWallet/screen/transactions/details.js

180 lines
6.0 KiB
JavaScript
Raw Normal View History

2018-01-30 23:42:38 +01:00
import React, { Component } from 'react';
2018-09-29 06:58:09 +02:00
import { View, ScrollView, TouchableOpacity, Linking } from 'react-native';
import {
BlueButton,
SafeBlueArea,
BlueCard,
BlueText,
BlueHeaderDefaultSub,
BlueLoading,
BlueSpacing20,
BlueCopyToClipboardButton,
} from '../../BlueComponents';
2018-03-18 03:48:23 +01:00
import PropTypes from 'prop-types';
/** @type {AppStorage} */
let BlueApp = require('../../BlueApp');
2018-05-28 21:18:11 +02:00
let loc = require('../../loc');
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;
}
function formatTime(time) {
if (typeof time === 'string') {
time = time.replace('T', ' ').replace('Z', '');
time = time.split('.')[0];
}
return time;
}
2018-01-30 23:42:38 +01:00
export default class TransactionsDetails extends Component {
static navigationOptions = {
header: ({ navigation }) => {
return <BlueHeaderDefaultSub leftText={loc.transactions.details.title} onClose={() => navigation.goBack(null)} />;
},
2018-03-17 21:39:21 +01:00
};
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) {
console.log(tx);
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) {
2018-03-17 21:39:21 +01:00
to = to.concat(output.addresses);
2018-01-30 23:42:38 +01:00
}
}
}
this.state = {
isLoading: true,
tx: foundTx,
from,
to,
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
});
2018-01-30 23:42:38 +01:00
}
render() {
if (this.state.isLoading) {
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 }}>
<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>
);
}
2018-01-30 23:42:38 +01:00
}
})()}
2018-01-30 23:42:38 +01:00
2018-09-29 06:58:09 +02:00
<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>
2018-09-11 20:17:24 +02:00
2018-09-29 06:58:09 +02:00
<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>
2018-09-11 20:17:24 +02:00
2018-09-29 06:58:09 +02:00
<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>
2018-09-11 20:17:24 +02:00
<BlueText style={{ fontSize: 16, fontWeight: '500', marginBottom: 4 }}>Received</BlueText>
<BlueText style={{ marginBottom: 26, color: 'grey' }}>{formatTime(this.state.tx.received)}</BlueText>
2018-09-11 20:17:24 +02:00
2018-09-29 06:58:09 +02:00
<BlueText style={{ fontSize: 16, fontWeight: '500', marginBottom: 4 }}>Block Height</BlueText>
<BlueText style={{ marginBottom: 26, color: 'grey' }}>{formatTime(this.state.tx.block_height)}</BlueText>
2018-09-11 20:17:24 +02:00
<BlueText style={{ fontSize: 16, fontWeight: '500', marginBottom: 4 }}>Confirmations</BlueText>
<BlueText style={{ marginBottom: 26, color: 'grey' }}>{this.state.tx.confirmations}</BlueText>
2018-01-30 23:42:38 +01:00
<BlueText style={{ fontSize: 16, fontWeight: '500', marginBottom: 4 }}>Inputs</BlueText>
<BlueText style={{ marginBottom: 26, color: 'grey' }}>{this.state.tx.inputs.length}</BlueText>
2018-01-30 23:42:38 +01:00
<BlueText style={{ fontSize: 16, fontWeight: '500', marginBottom: 4 }}>Outputs</BlueText>
<BlueText style={{ marginBottom: 26, color: 'grey' }}>{this.state.tx.outputs.length}</BlueText>
</BlueCard>
2018-01-30 23:42:38 +01:00
{(() => {
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>
2018-01-30 23:42:38 +01:00
</SafeBlueArea>
);
}
}
2018-03-18 03:48:23 +01:00
TransactionsDetails.propTypes = {
navigation: PropTypes.shape({
goBack: PropTypes.function,
navigate: PropTypes.func,
state: PropTypes.shape({
params: PropTypes.shape({
hash: PropTypes.string,
}),
}),
}),
};