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.

178 lines
5.0 KiB

7 years ago
import React, { Component } from 'react';
6 years ago
import { View, Dimensions } from 'react-native';
7 years ago
import {
7 years ago
BlueButton,
SafeBlueArea,
BlueCard,
BlueText,
6 years ago
BlueHeaderDefaultSub,
7 years ago
BlueLoading,
BlueSpacing20,
6 years ago
BlueSpacing,
BlueSpacing40,
7 years ago
} from '../../BlueComponents';
7 years ago
import PropTypes from 'prop-types';
/** @type {AppStorage} */
let BlueApp = require('../../BlueApp');
let loc = require('../../loc');
6 years ago
const { height, width } = Dimensions.get('window');
const aspectRatio = height / width;
let isIpad;
if (aspectRatio > 1.6) {
isIpad = false;
} else {
isIpad = true;
}
7 years ago
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 = {
header: ({ navigation }) => {
return <BlueHeaderDefaultSub leftText={loc.transactions.details.title} onClose={() => navigation.goBack(null)} />;
},
7 years ago
};
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) {
7 years ago
return <BlueLoading />;
7 years ago
}
return (
6 years ago
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1 }}>
{(() => {
if (isIpad) {
return <BlueSpacing40 />;
} else {
return <BlueSpacing />;
}
})()}
<BlueCard>
7 years ago
{(() => {
if (BlueApp.tx_metadata[this.state.tx.hash]) {
7 years ago
if (BlueApp.tx_metadata[this.state.tx.hash]['memo']) {
7 years ago
return (
<View>
<BlueText h4>{BlueApp.tx_metadata[this.state.tx.hash]['memo']}</BlueText>
7 years ago
<BlueSpacing20 />
7 years ago
</View>
);
}
}
})()}
<BlueText style={{ fontSize: 16, fontWeight: '500' }}>{loc.transactions.details.from}</BlueText>
<BlueText style={{ marginBottom: 6, color: 'grey' }}>{this.state.from.filter(onlyUnique).join(', ')}</BlueText>
<BlueText style={{ fontSize: 16, fontWeight: '500' }}>{loc.transactions.details.to}</BlueText>
<BlueText style={{ marginBottom: 6, color: 'grey' }}>
{arrDiff(this.state.from, this.state.to.filter(onlyUnique)).join(', ')}
</BlueText>
<BlueText style={{ fontSize: 16, fontWeight: '500' }}>Txid</BlueText>
<BlueText style={{ marginBottom: 6, color: 'grey' }}>{this.state.tx.hash}</BlueText>
<BlueText style={{ fontSize: 16, fontWeight: '500' }}>received</BlueText>
<BlueText style={{ marginBottom: 6, color: 'grey' }}>{formatTime(this.state.tx.received)}</BlueText>
<BlueText style={{ fontSize: 16, fontWeight: '500' }}>confirmed</BlueText>
<BlueText style={{ marginBottom: 6, color: 'grey' }}>{formatTime(this.state.tx.confirmed)}</BlueText>
<BlueText style={{ fontSize: 16, fontWeight: '500' }}>confirmations</BlueText>
<BlueText style={{ marginBottom: 6, color: 'grey' }}>{this.state.tx.confirmations}</BlueText>
7 years ago
<BlueText style={{ fontSize: 16, fontWeight: '500' }}>inputs</BlueText>
<BlueText style={{ marginBottom: 6, color: 'grey' }}>{this.state.tx.inputs.length}</BlueText>
7 years ago
<BlueText style={{ fontSize: 16, fontWeight: '500' }}>outputs</BlueText>
<BlueText style={{ marginBottom: 6, color: 'grey' }}>{this.state.tx.outputs.length}</BlueText>
7 years ago
7 years ago
<BlueText style={{ marginBottom: 10 }} />
7 years ago
</BlueCard>
{(() => {
7 years ago
if (this.state.tx.confirmations === 0) {
7 years ago
return (
<BlueButton
onPress={() =>
7 years ago
this.props.navigation.navigate('RBF', {
txid: this.state.tx.hash,
})
7 years ago
}
title="Replace-By-Fee (RBF)"
/>
);
}
})()}
</SafeBlueArea>
);
}
}
7 years ago
TransactionsDetails.propTypes = {
navigation: PropTypes.shape({
goBack: PropTypes.function,
navigate: PropTypes.func,
state: PropTypes.shape({
params: PropTypes.shape({
hash: PropTypes.string,
}),
}),
}),
};