import React, { Component } from 'react';
import { View, Dimensions } from 'react-native';
import {
BlueButton,
SafeBlueArea,
BlueCard,
BlueText,
BlueHeaderDefaultSub,
BlueLoading,
BlueSpacing20,
BlueSpacing,
BlueSpacing40,
} from '../../BlueComponents';
import PropTypes from 'prop-types';
/** @type {AppStorage} */
let BlueApp = require('../../BlueApp');
let loc = require('../../loc');
const { height, width } = Dimensions.get('window');
const aspectRatio = height / width;
let isIpad;
if (aspectRatio > 1.6) {
isIpad = false;
} else {
isIpad = true;
}
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;
}
export default class TransactionsDetails extends Component {
static navigationOptions = {
tabBarVisible: false,
};
constructor(props) {
super(props);
let hash = props.navigation.state.params.hash;
let foundTx = {};
let from = [];
let to = [];
for (let tx of BlueApp.getTransactions()) {
if (tx.hash === hash) {
console.log(tx);
foundTx = tx;
for (let input of foundTx.inputs) {
from = from.concat(input.addresses);
}
for (let output of foundTx.outputs) {
to = to.concat(output.addresses);
}
}
}
this.state = {
isLoading: true,
tx: foundTx,
from,
to,
};
}
async componentDidMount() {
console.log('transactions/details - componentDidMount');
this.setState({
isLoading: false,
});
}
render() {
if (this.state.isLoading) {
return ;
}
return (
{(() => {
if (isIpad) {
return ;
} else {
return ;
}
})()}
this.props.navigation.goBack()} />
{(() => {
if (BlueApp.tx_metadata[this.state.tx.hash]) {
if (BlueApp.tx_metadata[this.state.tx.hash]['memo']) {
return (
{BlueApp.tx_metadata[this.state.tx.hash]['memo']}
);
}
}
})()}
{loc.transactions.details.from}
{this.state.from.filter(onlyUnique).join(', ')}
{loc.transactions.details.to}
{arrDiff(this.state.from, this.state.to.filter(onlyUnique)).join(', ')}
Txid
{this.state.tx.hash}
received
{formatTime(this.state.tx.received)}
confirmed
{formatTime(this.state.tx.confirmed)}
confirmations
{this.state.tx.confirmations}
inputs
{this.state.tx.inputs.length}
outputs
{this.state.tx.outputs.length}
{(() => {
if (this.state.tx.confirmations === 0) {
return (
this.props.navigation.navigate('RBF', {
txid: this.state.tx.hash,
})
}
title="Replace-By-Fee (RBF)"
/>
);
}
})()}
);
}
}
TransactionsDetails.propTypes = {
navigation: PropTypes.shape({
goBack: PropTypes.function,
navigate: PropTypes.func,
state: PropTypes.shape({
params: PropTypes.shape({
hash: PropTypes.string,
}),
}),
}),
};