BlueWallet/screen/wallets/list.js

137 lines
3.4 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 { ListView } from 'react-native';
2018-01-30 22:42:38 +00:00
import Ionicons from 'react-native-vector-icons/Ionicons';
import {
2018-03-17 22:39:21 +02:00
BlueLoading,
BlueList,
BlueButton,
SafeBlueArea,
BlueCard,
BlueText,
BlueListItem,
BlueHeader,
} from '../../BlueComponents';
2018-03-18 02:48:23 +00:00
import { Icon } from 'react-native-elements';
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-03-17 22:39:21 +02:00
let ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });
2018-01-30 22:42:38 +00:00
export default class WalletsList extends Component {
static navigationOptions = {
tabBarLabel: 'Wallets',
tabBarIcon: ({ tintColor, focused }) => (
<Ionicons
name={focused ? 'ios-briefcase' : 'ios-briefcase-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
};
EV(EV.enum.WALLETS_COUNT_CHANGED, this.refreshFunction.bind(this));
2018-01-30 22:42:38 +00:00
}
async componentDidMount() {
2018-03-17 22:39:21 +02:00
this.refreshFunction();
2018-01-30 22:42:38 +00:00
} // end of componendDidMount
2018-03-17 22:39:21 +02:00
refreshFunction() {
this.setState(
{
isLoading: true,
},
() => {
setTimeout(() => {
this.setState({
isLoading: false,
dataSource: ds.cloneWithRows(BlueApp.getWallets()),
});
}, 1);
},
);
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 (
<SafeBlueArea>
<BlueHeader
2018-03-17 22:39:21 +02:00
leftComponent={
<Icon
name="menu"
color="#fff"
onPress={() => this.props.navigation.navigate('DrawerToggle')}
/>
}
centerComponent={{
text: 'Blue Wallet',
style: { color: '#fff', fontSize: 25 },
}}
2018-01-30 22:42:38 +00:00
/>
2018-03-17 22:39:21 +02:00
<BlueCard title="My Bitcoin Wallets">
<BlueText style={{ marginBottom: 10 }}>
A wallet represents a pair of a secret (private key) and an address
you can share to receive coins.
2018-01-30 22:42:38 +00:00
</BlueText>
<BlueList>
<ListView
2018-03-17 22:39:21 +02:00
enableEmptySections
2018-01-30 22:42:38 +00:00
maxHeight={290}
dataSource={this.state.dataSource}
2018-03-17 22:39:21 +02:00
renderRow={rowData => {
return (
<BlueListItem
onPress={() => {
navigate('WalletDetails', {
address: rowData.getAddress(),
});
}}
leftIcon={{
name: 'bitcoin',
type: 'font-awesome',
color: '#fff',
}}
title={
rowData.getLabel() + ' | ' + rowData.getBalance() + ' BTC'
}
subtitle={rowData.getShortAddress()}
hideChevron={false}
/>
);
}}
2018-01-30 22:42:38 +00:00
/>
2018-03-17 22:39:21 +02:00
</BlueList>
2018-01-30 22:42:38 +00:00
</BlueCard>
<BlueButton
2018-03-17 22:39:21 +02:00
icon={{ name: 'plus-small', type: 'octicon' }}
2018-01-30 22:42:38 +00:00
onPress={() => {
2018-03-17 22:39:21 +02:00
navigate('AddWallet');
2018-01-30 22:42:38 +00:00
}}
title="Add Wallet"
/>
</SafeBlueArea>
);
}
2018-03-17 22:39:21 +02:00
}
2018-03-18 02:48:23 +00:00
WalletsList.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
}),
};