import React, {Component} from 'react';
import {
ActivityIndicator,
Alert,
Animated,
Platform,
ProgressBarAndroid,
ScrollView,
StatusBar,
StyleSheet,
Text,
TouchableOpacity,
View
} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import I18n from 'react-native-i18n'
import * as Utils from '../../utils/DeviceUtils';
import Icons from 'react-native-vector-icons/Ionicons'
import {Color} from '../../config/Color';
import omit from 'lodash/omit';
import Tag from '../../components/Tag';
import {IlinkEmitter} from "../../utils/events";
import {Typography} from '../../config/typography';
import {responsiveWidth,} from 'react-native-responsive-dimensions';
import {
getWalletDetailActivated,
passwordValidationAction,
passwordValidationReset,
resetWalletListDetailReducer
} from '../../webservice/WalletApi';
import {depositActionReset} from '../../webservice/DepositApi';
import {
getWalletTransactionHistoryReset,
getWalletTransactionHistoryUser
} from '../../webservice/WalletTransactionHistoryApi';
import {getUserIdentificationAction, getUserIdentificationResetAction} from '../../webservice/IdentificationApi';
import {resetCommissionReducer, transferCommissionAction} from '../../webservice/WalletTransferCommission';
import Dialog from "react-native-dialog";
import isEqual from 'lodash/isEqual';
import {baseUrl} from '../../webservice/IlinkConstants';
import 'moment/locale/fr'
import 'moment/locale/es-us'
import 'moment/locale/en-au'
import 'moment/locale/en-ca'
import 'moment/locale/en-ie'
import 'moment/locale/en-il'
import 'moment/locale/en-nz'
import 'moment/locale/en-gb'
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {
cutString,
cutStringWithoutDot,
displayToast,
isEmptyObject,
optionDepotUserScreen,
optionIdentificationUserScreen,
optionLinkAccountUserScreen,
optionNanoCreditScreen,
optionNanoSanteUserScreen,
optionPaiementFacture,
optionRetraitUserScreen,
transactionHistoryIlinkLabel
} from '../../utils/UtilsFunction';
import {readUser} from '../../webservice/AuthApi';
import LottieView from "lottie-react-native";
import * as Animatable from "react-native-animatable";
import {Fumi} from "react-native-textinput-effects";
import FontAwesomeIcon from "react-native-vector-icons/FontAwesome";
import Button from "../../components/Button";
let moment = require('moment-timezone');
const thousands = require('thousands');
let route = require('./../../route.json');
let slugify = require('slugify');
require('../../utils/Translations');
class WalletDetailUser extends Component {
constructor(props) {
super(props);
this.state = {
index: 0,
heightHeader: Utils.heightHeader(),
isModalConfirmVisible: false,
wallet: null,
triggerTransferCommission: false,
loading: false,
isTriggerRefresh: false,
scrollHeaderY: 0,
user: null,
displayModalHistory: false,
historyItemDetail: null,
isIdentified: false,
isIdentifiedValidated: false,
password: '',
isLogged: false
};
slugify.extend({'+': 'plus'});
this.scrollY = new Animated.Value(0);
this.scrollHeaderY = new Animated.Value(0);
this.deltaY = new Animated.Value(0);
this.bgBannerY = new Animated.Value(0);
this.heightImageBanner = Utils.scaleWithPixel(250, 1);
this.marginTopBanner = this.heightImageBanner - this.state.heightHeader - 40;
this.currentLocale = I18n.locale.includes("fr") ? "fr" : "en-gb";
moment.locale(this.currentLocale);
IlinkEmitter.on("langueChange", this.updateLangue.bind(this));
IlinkEmitter.on("refreshWallet", this.refresh);
this.props.getWalletTransactionHistoryReset();
this.props.depositActionReset();
this.props.resetWalletListDetailReducer();
this.props.passwordValidationReset();
this.props.getUserIdentificationResetAction();
console.warn("Wallet User Props", this.props);
this.getWalletDetail();
this.willFocus = this.props.navigation.addListener(
'willFocus',
payload => {
this.getWalletDetail();
});
}
static navigatorStyle = {
navBarBackgroundColor: Color.primaryColor,
statusBarColor: Color.primaryDarkColor,
navBarTextColor: '#FFFFFF',
navBarButtonColor: '#FFFFFF'
};
static navigationOptions = () => {
return {
//title: I18n.t('WALLET'),
//title: this.isHomeRootView ? I18n.t('WALLET') : ((typeof this.props.navigation.state.params !== 'undefined') && this.props.navigation.state.params.wallet.network),
drawerLabel: () => null,
headerTitle: I18n.t('WALLET'),
headerTintColor: 'white',
headerStyle: {
backgroundColor: Color.primaryColor,
marginTop: 23,
color: 'white'
},
headerTitleStyle: {
color: "white"
},
title: I18n.t('WALLET')
}
};
getWalletDetail = () => {
this.props.getWalletDetailActivated(this.props.navigation.state.params.userId, null);
readUser().then((user) => {
if (user) {
if (user !== undefined) {
this.setState({user});
this.props.getUserIdentificationAction(user.phone);
this.props.getWalletTransactionHistoryUser(user.id);
}
}
});
};
componentDidMount() {
const {result, resultUserIdentification, errorUserIdentification} = this.props;
if (result !== null) {
if (typeof result.response !== 'undefined') {
const wallet = result.response[0];
console.log("WALLET RECUPERER", wallet);
this.setState({
wallet: wallet,
isTriggerRefresh: false
});
}
}
if (resultUserIdentification !== null) {
console.log("RESULT NUMBER DETAIL", resultUserIdentification);
if (typeof resultUserIdentification.response !== 'undefined') {
this.setState({
isIdentified: resultUserIdentification.response.isIdentified,
isIdentifiedValidated: resultUserIdentification.response.isIdentifiedValidated,
})
}
}
}
componentWillReceiveProps(nextProps) {
if (nextProps.resultPasswordValidation !== null) {
if (nextProps.resultPasswordValidation.status === 200) {
this.setState({
isLogged: true
});
this.props.passwordValidationReset();
}
}
if (nextProps.errorPasswordValidation !== null) {
console.log(nextProps.errorPasswordValidation);
Alert.alert(
I18n.t("ERROR_LABEL"),
'' + nextProps.errorPasswordValidation,
[
{
text: I18n.t("OK"), onPress: () => {
this.props.passwordValidationReset();
}
}
],
{cancelable: false}
);
this.setState({
isLogged: false
});
}
/* if (nextProps.loading || nextProps.loadingTransferCommission)
this.setState({
loading: true
})
else
this.setState({
loading: false
})*/
}
shouldComponentUpdate(nextProps, nextState) {
if (this.state.triggerTransferCommission !== nextState.triggerTransferCommission) {
return false;
} else {
return true;
}
}
getWalletIcon = (wallet) => {
return `${baseUrl}/datas/img/network/${slugify(wallet.network, {lower: true})}-logo.png`;
}
getCreationDateToHumanFormat = (date) => {
let re = moment.tz(date, moment.tz.guess()).format();
return moment(re).fromNow();
}
updateLangue() {
this.props.navigation.setParams({name: I18n.t('WALLET')})
this.forceUpdate()
}
handleIndexChange = index => this.setState({index});
imageScale = () => {
return this.scrollY.interpolate({
inputRange: [0, 100],
outputRange: [1, 0.5],
extrapolate: 'clamp',
});
}
imageTranslateY = () => {
return this.scrollY.interpolate({
inputRange: [0, 100],
outputRange: [-5, 50],
extrapolate: 'clamp',
});
}
bgHeaderTranslateY = () => {
return this.scrollY.interpolate({
inputRange: [0, 150],
outputRange: [-5, 0],
extrapolate: 'clamp',
});
}
refresh = () => {
let userId = this.props.navigation.state.params.userId;
this.props.getWalletDetailActivated(userId, null);
}
renderHeader = (wallet) => (
{I18n.t('COUNTRY')}
{wallet.country}
{wallet.network}
}
style={{
paddingRight: 10,
width: 120,
borderTopRightRadius: 0,
borderBottomRightRadius: 0,
borderRightWidth: 1,
borderRightColor: Color.whiteColor
}}
primary
onPress={() => {
this.props.navigation.push(route.walletOptionSelect, {
optionSelect: optionLinkAccountUserScreen,
lottie: {
source: require("./../../datas/json/link_card.json"),
loop: true
},
isIdentified: this.props.resultUserIdentification.response.isIdentified
});
}}>
{I18n.t('LINK_CARD_REATTACH')}
} primary
style={{width: 110, borderTopLeftRadius: 0, borderBottomLeftRadius: 0,}}
onPress={() => {
this._scrollView.scrollToEnd();
}}>
{I18n.t('HISTORY')}
{I18n.t('CREATION_DATE')}
{moment(wallet.created_date).format('DD/MM/YYYY')}
);
renderLoader = () => {
return (
{Platform.OS === 'android'
?
(
<>
{I18n.t('LOADING_DOTS')}
>
) :
<>
{I18n.t('LOADING_DOTS')}
>
}
)
}
renderAccountDetail = (wallet) => (
{I18n.t('PRINCIPAL_ACCOUNT_TITLE')}
{`${thousands(wallet.balance, ' ')} ${wallet.currency_code}`}
{I18n.t('NUMERO_COMPTE')}
{wallet.user_code}
);
renderDetailWallet = (wallet) => {
return (
!isEmptyObject(wallet) ?
(<>
{this.state.triggerTransferCommission && this.renderDialogTransferCommissionResponse()}
this._scrollView = component}
style={{
paddingHorizontal: 20, position: 'absolute',
width: '100%',
height: '100%',
zIndex: 2
}}
scrollEventThrottle={8}
onScroll={Animated.event([
{
nativeEvent: {
contentOffset: {y: this.scrollY},
},
},
],
{
listener: (event) => {
this.setState({scrollHeaderY: event.nativeEvent.contentOffset.y});
}
})}>
{this.renderHeader(wallet)}
{this.renderAccountDetail(wallet)}
<>
{I18n.t('TRANSACTIONS')}
{
this.props.navigation.push(route.walletOptionSelect, {
optionSelect: optionDepotUserScreen,
onGoBack: () => this.refresh(),
lottie: {
source: require("./../../datas/json/wallet_with_cash.json"),
loop: false
}
})
}}
activeOpacity={0.9}>
{I18n.t('ENVOIE_ARGENT')}
{/*
{I18n.t('DEPOSIT_DESCRIPTION')}
*/}
{
this.props.navigation.push(route.walletOptionSelect, {
optionSelect: optionRetraitUserScreen,
onGoBack: () => this.refresh(),
lottie: {
source: require("./../../datas/json/wallet_with_cash.json"),
loop: true
}
})
}}
activeOpacity={0.9}>
{I18n.t('RETRAIT_ARGENT')}
{/*
{I18n.t('WITHDRAWAL_DESCRIPTION')}
*/}
{
if (this.props.result.response.has_nano_credit === 1) {
this.props.navigation.push(route.walletOptionSelect, {
optionSelect: optionNanoCreditScreen,
wallet,
lottie: {
source: require("./../../datas/json/cedit-cards.json"),
loop: true
},
isNanoCredit: true
});
} else {
displayToast(I18n.t('NANO_CREDIT_DISABLE'));
}
}
}
activeOpacity={0.9}>
{I18n.t('NANO_CREDIT')}
{
this.props.navigation.push(route.walletOptionSelect, {
optionSelect: optionNanoSanteUserScreen,
wallet,
lottie: {
source: require("./../../datas/json/cedit-cards.json"),
loop: true
},
isNanoSante: true
});
}}
activeOpacity={0.9}>
{I18n.t('NANO_SANTE')}
{
this.props.navigation.push(route.walletOptionSelect, {
optionSelect: optionPaiementFacture,
onGoBack: () => this.refresh(),
lottie: {
source: require("./../../datas/json/paiement_facture.json"),
loop: true
}
});
}} activeOpacity={0.9}>
{I18n.t('PAIEMENT_FACTURE')}
{
/*if (!this.state.isIdentified)
this.props.navigation.push(route.createIdentificationUser)
else
displayToast(I18n.t('ALREADY_IDENTIFIED')); */
this.props.navigation.push(route.walletOptionSelect, {
optionSelect: optionIdentificationUserScreen,
lottie: {
source: require("./../../datas/json/identification.json"),
loop: true
},
isIdentified: this.props.resultUserIdentification.response.isIdentified
})
}}
activeOpacity={0.9}>
{I18n.t('CREATION_IDENTIFICATION_CLIENT')}
>
{this.renderHistoryTransaction(wallet)}
>)
:
(
{I18n.t('NO_WALLET_ACTIVED')}
)
)
}
renderModalHistoryDetail = () => {
const {historyItemDetail} = this.state;
return (
{I18n.t('HISTORY_DETAIL')}
{I18n.t('OPERATION')}
{this.state.historyItemDetail.operation}
{I18n.t('TRANSACTION_ID')}
{this.state.historyItemDetail.id_transaction}
Date
{this.state.historyItemDetail.date}
{I18n.t('INIT_COUNTRY')}
{this.state.historyItemDetail.init_country}
{I18n.t('AMOUNT')}
{this.state.historyItemDetail.montant}
{I18n.t('FEES_AND_TAXES')}
{this.state.historyItemDetail.frais}
{I18n.t('NET_AMOUNT')}
{this.state.historyItemDetail.montant_net_init}
{I18n.t('EMETTEUR')}
{this.state.historyItemDetail.emetteur}
{I18n.t('DESTINATAIRE')}
{this.state.historyItemDetail.destinataire}
{I18n.t('FINAL_COUNTRY')}
{this.state.historyItemDetail.final_country}
{I18n.t('NET_AMOUNT')}
{this.state.historyItemDetail.montant_net_final}
{I18n.t('ACTIVE_WALLET')}
{this.state.historyItemDetail.reseau_payeur}
{
this.setState({
displayModalHistory: !this.state.displayModalHistory,
});
}}/>
);
}
renderHistoryTransactionItem = (item, index, wallet) => {
return (
{
this.setState({displayModalHistory: true, historyItemDetail: item})
}} style={[styles.contentService, {borderBottomColor: Color.primaryColor}]}>
{
Object.keys(omit(item, ['id', 'id_transaction', 'type', 'frais', 'init_country', 'final_country', 'source', 'emetteur', 'montant_net_final', 'montant_net_init', 'reseau_payeur', 'operation'])).map((element, i) => (
{
isEqual(element, 'montant') ?
` ${item[element].length > 8 ? cutString(thousands(item[element], ' '), 6) : thousands(item[element], ' ')}`
: isEqual(element, 'destinataire') ?
item[element].length > 13 ? cutString(item[element], 13) : item[element]
: isEqual(element, 'date') ?
cutStringWithoutDot(item[element], 16)
: item[element]
}
))
}
);
/*
{item.description}
{date}
*/
}
renderHistoryTransactionList = (wallet) => {
const {resultTransaction, errorTransaction} = this.props;
if (errorTransaction !== null) {
if (typeof errorTransaction.data !== 'undefined') {
return (
{errorTransaction.data.error}
)
} else {
return (
{errorTransaction}
)
}
}
if (resultTransaction !== null) {
if (resultTransaction.response !== null) {
return (
Array.isArray(resultTransaction.response) && (resultTransaction.response.length) > 0 ?
(
<>
{
transactionHistoryIlinkLabel().map((item, index) => (
{I18n.t(item.label)}
))
}
{
resultTransaction.response.map((item, index) => (
this.renderHistoryTransactionItem(item, index, wallet)
))
}
>
) :
(
{I18n.t('NO_WALLET_HISTORY')}
)
)
}
}
}
renderHistoryTransaction = (wallet) => {
return (
<>
{
this.props.loadingTransaction ?
(
{Platform.OS === 'android'
?
(
<>
{I18n.t('LOADING_DOTS')}
>
) :
<>
{I18n.t('LOADING_DOTS')}
>
}
) :
<>
{I18n.t('TRANSACTION_HISTORY')}
{this.renderHistoryTransactionList(wallet)}
>
}
>
)
}
render() {
console.warn("Wallet Detail user Props", this.props);
return (
<>
{this.state.displayModalHistory && this.renderModalHistoryDetail()}
{
((this.props.loading || this.props.loadingUserIdentification) ?
this.renderLoader() :
(
this.props.result !== null ?
Array.isArray(this.props.result.response) && (this.props.result.response.length) === 0 ?
{I18n.t('NO_WALLET_ACTIVED')}
:
this.props.result.response.password_validation === "MIN" && !this.state.isLogged ?
{
this.codeAgentAnim = comp
}}>
{
this.setState({password});
}}
style={styles.input} />
:
this.renderDetailWallet(this.props.result.response)
: this.props.error !== null &&
this.props.error.data !== null &&
{this.props.error.data.error}
)
)
}
>
);
}
}
const mapStateToProps = state => ({
loading: state.walletDetailReducer.loading,
result: state.walletDetailReducer.result,
error: state.walletDetailReducer.error,
loadingTransaction: state.walletHistoryReducer.loadingTransaction,
resultTransaction: state.walletHistoryReducer.resultTransaction,
errorTransaction: state.walletHistoryReducer.errorTransaction,
loadingUserIdentification: state.getUserIdentificationReducer.loading,
resultUserIdentification: state.getUserIdentificationReducer.result,
errorUserIdentification: state.getUserIdentificationReducer.error,
loadingPasswordValidation: state.passwordValidationReducer.loading,
resultPasswordValidation: state.passwordValidationReducer.result,
errorPasswordValidation: state.passwordValidationReducer.error,
});
const mapDispatchToProps = dispatch => bindActionCreators({
getWalletDetailActivated,
getWalletTransactionHistoryUser,
transferCommissionAction,
resetWalletListDetailReducer,
resetCommissionReducer,
getWalletTransactionHistoryReset,
depositActionReset,
getUserIdentificationAction,
getUserIdentificationResetAction,
passwordValidationAction,
passwordValidationReset,
}, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)(WalletDetailUser);
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: Color.containerBackgroundColor
},
indicator: {
height: 2
},
tab: {
width: Utils.getWidthDevice() / 2
},
tabbar: {
height: 40
},
lottie: {
width: 248,
height: 248
},
imgBanner: {
width: '100%',
height: 250,
position: 'absolute',
},
contentService: {
paddingVertical: 10,
borderBottomWidth: 0.5,
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'space-between',
},
containField: {
padding: 10,
marginBottom: 20,
borderWidth: 0.5,
shadowOffset: {width: 1.5, height: 1.5},
shadowOpacity: 1.0,
elevation: 5,
flexDirection: "row",
height: 140,
borderRadius: 10
},
paymentItem: {
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
borderBottomWidth: 1,
paddingVertical: 5,
width: responsiveWidth(100),
marginBottom: 15
},
iconContent: {
width: 60,
marginRight: 10,
alignItems: "center"
},
contentLeftItem: {
flex: 1,
paddingTop: 40,
paddingLeft: 10,
paddingRight: 10,
alignItems: "center"
},
tagFollow: {width: 150, margin: 10},
profileItem: {
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
paddingBottom: 20,
paddingTop: 20
},
checkDefault: {
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
borderBottomWidth: 1,
paddingVertical: 10,
marginTop: 5
},
blockView: {
paddingVertical: 10,
borderBottomWidth: 0.5,
},
circlePoint: {
width: 50,
height: 50,
borderRadius: 25,
marginRight: 5,
alignItems: 'center',
justifyContent: 'center',
},
transactionContainer: {
flexDirection: 'row',
flex: 1,
paddingTop: 10,
paddingLeft: 10,
paddingRight: 10,
},
containerTouch: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
marginRight: 1,
shadowColor: Color.borderColor,
borderColor: Color.borderColor,
borderWidth: 0.5,
shadowOffset: {width: 1.5, height: 1.5},
shadowOpacity: 1.0,
elevation: 5,
borderRadius: 10,
backgroundColor: Color.cardBackgroundColor
},
contain: {
flexDirection: 'row',
justifyContent: 'space-between',
},
imageBanner: {
marginTop: 15,
marginLeft: 5,
width: Utils.scaleWithPixel(30),
height: Utils.scaleWithPixel(30)
},
content: {
height: Utils.scaleWithPixel(60),
paddingHorizontal: 10,
justifyContent: 'space-between',
alignItems: 'flex-start',
flex: 1,
},
contentTitle: {
paddingTop: 5,
}
})