192 lines
6.5 KiB
JavaScript
192 lines
6.5 KiB
JavaScript
import React, { Component } from 'react';
|
|
import { StyleSheet, View, Image, StatusBar, ScrollView, TouchableOpacity, ActivityIndicator, Platform, ProgressBarAndroid, Text } from 'react-native';
|
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
|
const route = require('./../../route.json');
|
|
let slugify = require('slugify');
|
|
import I18n from 'react-native-i18n'
|
|
import * as Utils from '../../utils/DeviceUtils';
|
|
import { Images } from '../../config/Images';
|
|
import CustomText from '../../components/CustomText';
|
|
import { Color } from '../../config/Color';
|
|
import { baseUrl } from '../../webservice/IlinkConstants';
|
|
import { IlinkEmitter } from "../../utils/events";
|
|
import { Provider, Appbar } from 'react-native-paper';
|
|
import getWalletActivated from '../../webservice/WalletApi';
|
|
import { connect } from 'react-redux';
|
|
import { readUser } from '../../webservice/AuthApi';
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
class WalletSelect extends Component {
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
slugify.extend({ '+': 'plus' });
|
|
IlinkEmitter.on("langueChange", this.updateLangue.bind(this));
|
|
}
|
|
|
|
static navigationOptions = ({ navigation }) => ({
|
|
header: null,
|
|
headerMode: 'none',
|
|
headerTitle: null,
|
|
activeColor: '#f0edf6',
|
|
inactiveColor: '#3e2465',
|
|
barStyle: { backgroundColor: '#694fad' },
|
|
|
|
drawerLabel: I18n.t('CREDIT_MANAGE'),
|
|
drawerIcon: ({ tintColor }) => (
|
|
<Icon
|
|
name={'credit-card'}
|
|
size={24}
|
|
/>)
|
|
});
|
|
|
|
componentDidMount() {
|
|
|
|
readUser().then((user) => {
|
|
if (user) {
|
|
this.props.getWalletActivated(user.agentId);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
updateLangue() {
|
|
this.props.navigation.setParams({ name: I18n.t('WALLET') })
|
|
this.forceUpdate()
|
|
}
|
|
|
|
renderLoader = () => {
|
|
return (
|
|
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
|
|
{Platform.OS === 'android'
|
|
?
|
|
(
|
|
<>
|
|
<ProgressBarAndroid />
|
|
<Text>{I18n.t('LOADING_DOTS')}</Text>
|
|
|
|
</>
|
|
) :
|
|
<>
|
|
<ActivityIndicator size="large" color={'#ccc'} />
|
|
<Text>{I18n.t('LOADING_DOTS')}</Text>
|
|
</>
|
|
}
|
|
</View>
|
|
)
|
|
}
|
|
|
|
renderWalletItem = (item) => {
|
|
let icon = `${baseUrl}/datas/img/network/${slugify(item.network, { lower: true })}-logo.png`;
|
|
return (
|
|
<TouchableOpacity
|
|
key={item.id}
|
|
style={[styles.paymentItem, { borderBottomColor: Color.borderColor }]}
|
|
onPress={() => this.props.navigation.push('walletDetail')}>
|
|
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
|
<View style={styles.iconContent}>
|
|
<Image style={{ width: 48, height: 48 }} source={{ uri: icon }} />
|
|
</View>
|
|
<View>
|
|
<CustomText body1>{item.network}</CustomText>
|
|
<CustomText footnote grayColor style={{ marginTop: 5 }}>
|
|
{I18n.t('COUNTRY')}: {item.country}
|
|
</CustomText>
|
|
</View>
|
|
</View>
|
|
</TouchableOpacity>
|
|
)
|
|
}
|
|
|
|
renderWalletList = () => {
|
|
|
|
const { result, error } = this.props;
|
|
if (error !== null) {
|
|
return (
|
|
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
|
|
<CustomText body1>{error}</CustomText>
|
|
</View>
|
|
)
|
|
}
|
|
if (result !== null)
|
|
return (
|
|
<ScrollView style={{ flex: 1, padding: 20 }}>
|
|
{
|
|
result != null && (
|
|
result.response.map((item, index) => (
|
|
this.renderWalletItem(item)
|
|
))
|
|
)
|
|
}
|
|
</ScrollView>
|
|
)
|
|
}
|
|
|
|
render() {
|
|
console.log("WALLET PROPS", this.props);
|
|
return (
|
|
<Provider>
|
|
<View style={{ flex: 1 }}>
|
|
|
|
<StatusBar
|
|
backgroundColor={Color.primaryDarkColor}
|
|
barStyle="light-content"
|
|
translucent={false}
|
|
/>
|
|
|
|
<Appbar.Header dark={true} style={{ backgroundColor: Color.primaryColor }}>
|
|
<Appbar.BackAction
|
|
onPress={() => { this.props.navigation.pop() }}
|
|
/>
|
|
<Appbar.Content
|
|
title={I18n.t('WALLET')}
|
|
subtitle={I18n.t('SELECT_YOUR_WALLET')}
|
|
/>
|
|
</Appbar.Header>
|
|
|
|
{
|
|
this.props.loading ?
|
|
this.renderLoader() :
|
|
this.renderWalletList()
|
|
}
|
|
|
|
|
|
</View>
|
|
</Provider>
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
loading: state.walletReducer.loading,
|
|
result: state.walletReducer.result,
|
|
error: state.walletReducer.error
|
|
});
|
|
|
|
const mapDispatchToProps = dispatch => bindActionCreators({
|
|
getWalletActivated
|
|
}, dispatch);
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(WalletSelect);
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
backgroundColor: Color.containerBackgroundColor,
|
|
},
|
|
paymentItem: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
justifyContent: "space-between",
|
|
borderBottomWidth: 1,
|
|
paddingVertical: 5,
|
|
width: "100%",
|
|
marginBottom: 15
|
|
},
|
|
iconContent: {
|
|
width: 60,
|
|
marginRight: 10,
|
|
alignItems: "center"
|
|
}
|
|
}); |