2018-01-30 22:42:38 +00:00
|
|
|
/** @type {AppStorage} */
|
2018-03-17 22:39:21 +02:00
|
|
|
let BlueApp = require('../../BlueApp');
|
2018-01-30 22:42:38 +00:00
|
|
|
import React, { Component } from 'react';
|
2018-03-17 22:39:21 +02:00
|
|
|
import {
|
|
|
|
ActivityIndicator,
|
|
|
|
StyleSheet,
|
|
|
|
ListView,
|
|
|
|
Text,
|
|
|
|
View,
|
|
|
|
} from 'react-native';
|
2018-01-30 22:42:38 +00:00
|
|
|
import Ionicons from 'react-native-vector-icons/Ionicons';
|
|
|
|
import { SafeAreaView, TabNavigator } from 'react-navigation';
|
2018-03-17 22:39:21 +02:00
|
|
|
import { Card, Header, Icon, List, ListItem } from 'react-native-elements';
|
|
|
|
import {
|
|
|
|
BlueLoading,
|
|
|
|
BlueList,
|
|
|
|
BlueListView,
|
|
|
|
BlueSpacing,
|
|
|
|
BlueButton,
|
|
|
|
SafeBlueArea,
|
|
|
|
BlueCard,
|
|
|
|
BlueText,
|
|
|
|
BlueListItem,
|
|
|
|
BlueHeader,
|
|
|
|
} from '../../BlueComponents';
|
|
|
|
let EV = require('../../events');
|
|
|
|
|
|
|
|
let ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });
|
|
|
|
|
|
|
|
export default class TransactionsList extends Component {
|
2018-01-30 22:42:38 +00:00
|
|
|
static navigationOptions = {
|
|
|
|
tabBarLabel: 'Transactions',
|
|
|
|
tabBarIcon: ({ tintColor, focused }) => (
|
|
|
|
<Ionicons
|
|
|
|
name={focused ? 'ios-list-box' : 'ios-list-box-outline'}
|
|
|
|
size={26}
|
|
|
|
style={{ color: tintColor }}
|
|
|
|
/>
|
|
|
|
),
|
2018-03-17 22:39:21 +02:00
|
|
|
};
|
2018-01-30 22:42:38 +00:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
isLoading: true,
|
2018-03-17 22:39:21 +02:00
|
|
|
};
|
2018-01-30 22:42:38 +00:00
|
|
|
|
2018-03-17 22:39:21 +02:00
|
|
|
EV(EV.enum.TRANSACTIONS_COUNT_CHANGED, this.refreshFunction.bind(this));
|
2018-01-30 22:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount() {
|
2018-03-17 22:39:21 +02:00
|
|
|
console.log('transaction/list- componentDidMount');
|
|
|
|
this.refreshFunction();
|
2018-01-30 22:42:38 +00:00
|
|
|
} // end
|
|
|
|
|
2018-03-17 22:39:21 +02:00
|
|
|
refreshFunction() {
|
|
|
|
this.setState(
|
|
|
|
{
|
|
|
|
isLoading: true,
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.setState({
|
|
|
|
isLoading: false,
|
|
|
|
final_balance: BlueApp.getBalance(),
|
|
|
|
dataSource: ds.cloneWithRows(BlueApp.getTransactions()),
|
|
|
|
});
|
|
|
|
}, 1);
|
|
|
|
},
|
|
|
|
);
|
2018-01-30 22:42:38 +00:00
|
|
|
}
|
|
|
|
|
2018-03-17 22:39:21 +02:00
|
|
|
txMemo(hash) {
|
|
|
|
if (BlueApp.tx_metadata[hash] && BlueApp.tx_metadata[hash]['memo']) {
|
2018-02-24 15:15:03 +00:00
|
|
|
return ' | ' + BlueApp.tx_metadata[hash]['memo'];
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2018-01-30 22:42:38 +00:00
|
|
|
refresh() {
|
2018-03-17 22:39:21 +02:00
|
|
|
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);
|
|
|
|
},
|
|
|
|
);
|
2018-01-30 22:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-03-17 22:39:21 +02:00
|
|
|
const { navigate } = this.props.navigation;
|
2018-01-30 22:42:38 +00:00
|
|
|
|
|
|
|
if (this.state.isLoading) {
|
2018-03-17 22:39:21 +02:00
|
|
|
return <BlueLoading />;
|
2018-01-30 22:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2018-03-17 22:39:21 +02:00
|
|
|
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1 }}>
|
2018-01-30 22:42:38 +00:00
|
|
|
<Header
|
|
|
|
backgroundColor={BlueApp.settings.brandingColor}
|
2018-03-17 22:39:21 +02:00
|
|
|
leftComponent={
|
|
|
|
<Icon
|
|
|
|
name="menu"
|
|
|
|
color="#fff"
|
|
|
|
onPress={() => this.props.navigation.navigate('DrawerToggle')}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
centerComponent={{
|
|
|
|
text: this.state.final_balance + ' BTC',
|
|
|
|
style: { color: '#fff', fontSize: 25 },
|
|
|
|
}}
|
|
|
|
rightComponent={
|
|
|
|
<Icon name="refresh" color="#fff" onPress={() => this.refresh()} />
|
|
|
|
}
|
2018-01-30 22:42:38 +00:00
|
|
|
/>
|
2018-03-17 22:39:21 +02:00
|
|
|
<BlueCard title="My Transactions">
|
|
|
|
<BlueText style={{ marginBottom: 10 }}>
|
2018-01-30 22:42:38 +00:00
|
|
|
A list of ingoing or outgoing transactions of your wallets
|
|
|
|
</BlueText>
|
|
|
|
|
2018-03-17 22:39:21 +02:00
|
|
|
<BlueList>
|
|
|
|
<ListView
|
|
|
|
style={{ height: 360 }}
|
|
|
|
enableEmptySections
|
|
|
|
dataSource={this.state.dataSource}
|
|
|
|
renderRow={rowData => {
|
|
|
|
return (
|
|
|
|
<BlueListItem
|
|
|
|
avatar={
|
|
|
|
<Icon
|
|
|
|
color={(() => {
|
|
|
|
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] +
|
|
|
|
' | conf: ' +
|
|
|
|
rowData.confirmations +
|
|
|
|
'\nYOLO'
|
|
|
|
}
|
|
|
|
onPress={() => {
|
|
|
|
navigate('TransactionDetails', { hash: rowData.hash });
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</BlueList>
|
2018-01-30 22:42:38 +00:00
|
|
|
</BlueCard>
|
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|