BlueWallet/screen/send/list.js

112 lines
2.6 KiB
JavaScript
Raw Normal View History

2018-01-30 22:42:38 +00:00
import React, { Component } from 'react';
2018-03-18 02:48:23 +00:00
import { ActivityIndicator, View } from 'react-native';
2018-01-30 22:42:38 +00:00
import Ionicons from 'react-native-vector-icons/Ionicons';
2018-03-18 02:48:23 +00:00
import { Icon } from 'react-native-elements';
2018-03-17 22:39:21 +02:00
import {
SafeBlueArea,
BlueCard,
BlueListItem,
BlueHeader,
} from '../../BlueComponents';
2018-03-18 02:48:23 +00:00
import PropTypes from 'prop-types';
2018-03-17 22:39:21 +02:00
let EV = require('../../events');
2018-03-18 02:48:23 +00:00
/** @type {AppStorage} */
let BlueApp = require('../../BlueApp');
2018-01-30 22:42:38 +00:00
export default class SendList extends Component {
static navigationOptions = {
tabBarLabel: 'Send',
tabBarIcon: ({ tintColor, focused }) => (
<Ionicons
name={focused ? 'md-paper-plane' : 'md-paper-plane'}
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
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-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) {
return (
2018-03-17 22:39:21 +02:00
<View style={{ flex: 1, paddingTop: 20 }}>
2018-01-30 22:42:38 +00:00
<ActivityIndicator />
</View>
);
}
return (
2018-03-17 22:39:21 +02:00
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1 }}>
2018-01-30 22:42:38 +00:00
<BlueHeader
2018-03-17 22:39:21 +02:00
leftComponent={
<Icon
name="menu"
color="#fff"
onPress={() => this.props.navigation.navigate('DrawerToggle')}
/>
}
centerComponent={{
text: 'Choose a wallet to send from',
style: { color: '#fff', fontSize: 25 },
}}
2018-01-30 22:42:38 +00:00
/>
2018-03-17 22:39:21 +02:00
<BlueCard containerStyle={{ padding: 0 }}>
{this.state.list.map((item, i) => (
<BlueListItem
onPress={() => {
navigate('SendDetails', { fromAddress: item.title });
}}
key={i}
title={item.title}
subtitle={item.subtitle}
leftIcon={{
name: 'bitcoin',
type: 'font-awesome',
color: 'white',
}}
/>
))}
2018-01-30 22:42:38 +00:00
</BlueCard>
</SafeBlueArea>
);
}
}
2018-03-18 02:48:23 +00:00
SendList.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
}),
};