import React, { Component } from 'react'; import { ListView, Dimensions } from 'react-native'; import Ionicons from 'react-native-vector-icons/Ionicons'; import { Header, Icon } from 'react-native-elements'; import { BlueLoading, BlueList, SafeBlueArea, BlueCard, BlueText, BlueListItem } from '../../BlueComponents'; import PropTypes from 'prop-types'; let loc = require('../../loc'); let EV = require('../../events'); /** @type {AppStorage} */ let BlueApp = require('../../BlueApp'); const { height } = Dimensions.get('window'); let ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 }); export default class TransactionsList extends Component { static navigationOptions = { tabBarLabel: loc.transactions.list.tabBarLabel, tabBarIcon: ({ tintColor, focused }) => ( ), }; constructor(props) { super(props); this.state = { isLoading: true, }; EV(EV.enum.TRANSACTIONS_COUNT_CHANGED, this.refreshFunction.bind(this)); } async componentDidMount() { console.log('transaction/list- componentDidMount'); this.refreshFunction(); } // end refreshFunction() { this.setState( { isLoading: true, }, () => { setTimeout(() => { this.setState({ isLoading: false, final_balance: BlueApp.getBalance(), dataSource: ds.cloneWithRows(BlueApp.getTransactions()), }); }, 1); }, ); } txMemo(hash) { if (BlueApp.tx_metadata[hash] && BlueApp.tx_metadata[hash]['memo']) { return ' | ' + BlueApp.tx_metadata[hash]['memo']; } return ''; } refresh() { this.setState( { isLoading: true, }, async function() { let that = this; setTimeout(async function() { // more responsive let noErr = true; try { await BlueApp.fetchWalletTransactions(); await BlueApp.fetchWalletBalances(); } catch (err) { noErr = false; console.warn(err); } if (noErr) await BlueApp.saveToDisk(); // caching EV(EV.enum.WALLETS_COUNT_CHANGED); // TODO: some other event type? that.setState({ isLoading: false, final_balance: BlueApp.getBalance(), dataSource: ds.cloneWithRows(BlueApp.getTransactions()), }); }, 10); }, ); } render() { const { navigate } = this.props.navigation; if (this.state.isLoading) { return ; } return (
this.refresh()} />} /> {loc.transactions.list.description} { return ( { return (rowData.confirmations && ((rowData.value < 0 && '#900') || '#080')) || '#ebebeb'; })()} name={(() => { return (rowData.value < 0 && 'call-made') || 'call-received'; })()} /> } title={rowData.value / 100000000 + ' BTC' + this.txMemo(rowData.hash)} subtitle={ rowData.received .replace(['T'], ' ') .replace(['Z'], ' ') .split('.')[0] + ' | ' + loc.transactions.list.conf + ': ' + rowData.confirmations + '\nYOLO' } onPress={() => { navigate('TransactionDetails', { hash: rowData.hash }); }} /> ); }} /> ); } } TransactionsList.propTypes = { navigation: PropTypes.shape({ navigate: PropTypes.func, }), };