BlueWallet/screen/receive/list.js

104 lines
2.6 KiB
JavaScript
Raw Normal View History

2018-01-30 22:42:38 +00:00
import React, { Component } from 'react';
2018-09-16 02:24:45 -04:00
import { FlatList, Text, StyleSheet } from 'react-native';
2018-01-30 22:42:38 +00:00
import Ionicons from 'react-native-vector-icons/Ionicons';
2018-07-07 14:04:32 +01:00
import { BlueLoading, SafeBlueArea, BlueCard, BlueListItem, BlueHeader } from '../../BlueComponents';
2018-03-18 02:48:23 +00:00
import PropTypes from 'prop-types';
2018-05-28 20:18:11 +01:00
/** @type {AppStorage} */
2018-03-18 02:48:23 +00:00
let BlueApp = require('../../BlueApp');
2018-03-17 22:39:21 +02:00
let EV = require('../../events');
2018-05-28 20:18:11 +01:00
let loc = require('../../loc');
2018-01-30 22:42:38 +00:00
export default class ReceiveList extends Component {
static navigationOptions = {
2018-05-28 20:18:11 +01:00
tabBarLabel: loc.receive.list.tabBarLabel,
2018-01-30 22:42:38 +00:00
tabBarIcon: ({ tintColor, focused }) => (
2018-07-07 14:04:32 +01:00
<Ionicons name={focused ? 'ios-cash' : 'ios-cash-outline'} size={26} style={{ color: tintColor }} />
2018-01-30 22:42:38 +00:00
),
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
this.walletsCount = 0;
EV(EV.enum.WALLETS_COUNT_CHANGED, () => {
2018-03-17 22:39:21 +02:00
return this.componentDidMount();
});
2018-01-30 22:42:38 +00:00
}
async componentDidMount() {
2018-03-17 22:39:21 +02:00
console.log('receive/list - componentDidMount');
let list = [];
2018-01-30 22:42:38 +00:00
this.walletsCount = 0;
for (let w of BlueApp.getWallets()) {
list.push({
title: w.getAddress(),
subtitle: w.getLabel(),
2018-03-17 22:39:21 +02:00
});
2018-01-30 22:42:38 +00:00
this.walletsCount++;
}
this.setState({
isLoading: false,
2018-03-17 22:39:21 +02:00
list: list,
2018-09-16 02:24:45 -04:00
dataSource: list,
2018-03-17 22:39:21 +02:00
});
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-09-16 02:24:45 -04:00
<SafeBlueArea forceInset={{ horizontal: 'always' }}>
2018-01-30 22:42:38 +00:00
<BlueHeader
2018-03-17 22:39:21 +02:00
centerComponent={{
2018-05-28 20:18:11 +01:00
text: loc.receive.list.header,
2018-05-22 18:10:53 +01:00
style: { color: BlueApp.settings.foregroundColor, fontSize: 23 },
2018-03-17 22:39:21 +02:00
}}
2018-01-30 22:42:38 +00:00
/>
2018-03-17 22:39:21 +02:00
<BlueCard containerStyle={{ padding: 0 }}>
2018-09-16 02:24:45 -04:00
<FlatList
data={this.state.dataSource}
style={Styles.flatList}
renderItem={item => {
2018-05-12 21:27:34 +01:00
return (
<BlueListItem
title={item.title}
subtitle={item.subtitle}
onPress={() => {
navigate('ReceiveDetails', { address: item.title });
}}
leftIcon={{
name: 'bitcoin',
type: 'font-awesome',
2018-05-22 18:10:53 +01:00
color: BlueApp.settings.foregroundColor,
2018-05-12 21:27:34 +01:00
}}
/>
);
}}
/>
2018-01-30 22:42:38 +00:00
</BlueCard>
</SafeBlueArea>
);
}
}
2018-03-18 02:48:23 +00:00
2018-09-16 02:24:45 -04:00
const Styles = StyleSheet.create({
flatList: {
flex: 1,
},
});
2018-03-18 02:48:23 +00:00
ReceiveList.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
}),
};