diff --git a/index.js b/index.js index 357824c7..6ef90d67 100644 --- a/index.js +++ b/index.js @@ -12,26 +12,4 @@ import axios from "axios"; YellowBox.ignoredYellowBox = ['Warning: Each', 'Warning: Failed']; console.disableYellowBox = true; -getAuthToken = () => { - return new Promise(async (resolve, reject) => { - - try { - const data = await AsyncStorage.getItem('persist:root'); - resolve(JSON.parse(data)) - } catch (error) { - reject(error) - - } - - }) -}; - -(async () => { - const authToken = await getAuthToken(); - const auth = JSON.parse(authToken.authKeyReducer); - console.log("AUTHTOKEN", auth); - axios.defaults.headers.common['Authorization'] = `${auth.authKey.token_type} ${auth.authKey.access_token}`; - -})(); - AppRegistry.registerComponent(appName, () => App); diff --git a/redux/reducers/AuthKeyReducer.js b/redux/reducers/AuthKeyReducer.js index 386fc701..8eb683bb 100644 --- a/redux/reducers/AuthKeyReducer.js +++ b/redux/reducers/AuthKeyReducer.js @@ -25,6 +25,13 @@ export default (state = initialState, action) => { error: action.result } + case REHYDRATE: return { + ...state, + loading: false, + authKey: action.payload.authKeyReducer.authKey, + error: null + } + default: { return state; } diff --git a/redux/reducers/WalletReducer.js b/redux/reducers/WalletReducer.js index 534a20d4..cd64bf01 100644 --- a/redux/reducers/WalletReducer.js +++ b/redux/reducers/WalletReducer.js @@ -22,7 +22,7 @@ export default (state = initialState, action) => { ...state, loading: false, result: null, - error: action.result, + error: action.result } default: { diff --git a/redux/reducers/index.js b/redux/reducers/index.js index ef764e91..cde0ee5a 100644 --- a/redux/reducers/index.js +++ b/redux/reducers/index.js @@ -12,8 +12,8 @@ const persistConfig = { }; const rootReducer = persistCombineReducers(persistConfig, { - wallet: walletReducer, - authKey: authKeyReducer + walletReducer: walletReducer, + authKeyReducer: authKeyReducer }); export default rootReducer; \ No newline at end of file diff --git a/screens/home/Home.js b/screens/home/Home.js index e6f9a7bc..ded0c626 100644 --- a/screens/home/Home.js +++ b/screens/home/Home.js @@ -116,7 +116,6 @@ class Home extends BaseScreen { let data = await this.loadingMarkers(this.state.myPosition, this.state.filternetwork, this.state.value) this.treatNewData(pos, data, false) } catch (e) { - console.debug(e.message) this.setState({ isNeedLoadMore: false, isLoadingMap: false }) } } @@ -158,15 +157,15 @@ class Home extends BaseScreen { }; componentDidMount() { - AsyncStorage.getAllKeys((err, keys) => { - AsyncStorage.multiGet(keys, (err, stores) => { - stores.map((result, i, store) => { - let key = store[i][0]; - let value = store[i][1]; - console.log('STORAGE VALUE ', `key: ${key} | value: ${value}`); - }); - }); - }); + /* AsyncStorage.getAllKeys((err, keys) => { + AsyncStorage.multiGet(keys, (err, stores) => { + stores.map((result, i, store) => { + let key = store[i][0]; + let value = store[i][1]; + console.log('STORAGE VALUE ', `key: ${key} | value: ${value}`); + }); + }); + }); */ this.mounted = true; this.configuration = new Configuration() @@ -214,7 +213,6 @@ class Home extends BaseScreen { ) if (granted === PermissionsAndroid.RESULTS.GRANTED) { readUser().then((user) => { - console.log("MAP READY"); if (user) { if (user.category !== undefined && user.category !== null) { const myPosition = { @@ -251,10 +249,8 @@ class Home extends BaseScreen { } } }) - console.log("Camera permission granted") } else { - console.log("Camera permission denied") } } catch (err) { console.log(err) @@ -320,14 +316,12 @@ class Home extends BaseScreen { return item.name.includes(this.state.network); }) if (this.state.user.category === undefined || this.state.user.category === null) { - console.log(this.state.user) if (c.length > 0 && pays) { this.setState({ filternetwork: c[0], myNetwork: c[0], filternetworkTemp: c[0] }) this.retrieveAllPoint(pays) } else { - console.log("on getnetworks", result) if (this.state.user) { if (!this.state.user.category) Alert.alert( @@ -352,7 +346,6 @@ class Home extends BaseScreen { } } }, (err) => { - console.log("error getnetwork" + e.message) // Crashlytics.log("get networks"+e.message) Alert.alert( I18n.t("UNABLE_TO_CONNECT_TITLE"), @@ -1468,7 +1461,6 @@ class Home extends BaseScreen { ) } render() { - console.log("PROPS", this.props); if (false) { return this.renderBottomHome() } else @@ -2172,9 +2164,9 @@ class Home extends BaseScreen { } const mapStateToProps = state => ({ - loading: state.loading, - authKey: state.authKey, - error: state.error + loading: state.authKeyReducer.loading, + authKey: state.authKeyReducer.authKey, + error: state.authKeyReducer.error }); const mapDispatchToProps = dispatch => bindActionCreators({ diff --git a/screens/wallet/WalletSelect.js b/screens/wallet/WalletSelect.js index df0757f5..43f361b9 100644 --- a/screens/wallet/WalletSelect.js +++ b/screens/wallet/WalletSelect.js @@ -1,5 +1,5 @@ import React, { Component } from 'react'; -import { StyleSheet, View, Image, StatusBar, ScrollView, TouchableOpacity, ActivityIndicator, Platform } from 'react-native'; +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'); @@ -16,109 +16,6 @@ import { connect } from 'react-redux'; import { readUser } from '../../webservice/AuthApi'; import { bindActionCreators } from 'redux'; -const card = [ - { - id: "12", - name: "Canal +", - countryId: "78" - }, - { - id: "14", - name: "Airtel Money", - countryId: "78" - }, - { - id: "17", - name: "SEEG", - countryId: "78" - }, - { - id: "19", - name: "Juba", - countryId: "78" - }, - { - id: "77", - name: "Mobicash", - countryId: "78" - }, - { - id: "82", - name: "Western Union", - countryId: "78" - }, - { - id: "95", - name: "MoneyGram", - countryId: "78" - }, - { - id: "100", - name: "Express Union", - countryId: "78" - }, - { - id: "109", - name: "Money Express", - countryId: "78" - }, - { - id: "118", - name: "UBA", - countryId: "78" - }, - { - id: "135", - name: "Small World", - countryId: "78" - }, - { - id: "158", - name: "Wari", - countryId: "78" - }, - { - id: "171", - name: "Ria", - countryId: "78" - }, - { - id: "184", - name: "Sigue", - countryId: "78" - }, - { - id: "197", - name: "Ecobank", - countryId: "78" - }, - { - id: "209", - name: "DHL", - countryId: "78" - }, - { - id: "220", - name: "OraBank", - countryId: "78" - }, - { - id: "223", - name: "Satcon", - countryId: "78" - }, - { - id: "235", - name: "FINAM ", - countryId: "78" - }, - { - id: "237", - name: "UBA fs ilink", - countryId: "78" - } -]; - class WalletSelect extends Component { constructor(props) { @@ -216,9 +113,9 @@ class WalletSelect extends Component { { result != null && ( - result.map((item, index) => { - this.renderWalletItem(item); - }) + result.response.map((item, index) => ( + this.renderWalletItem(item) + )) ) } @@ -226,7 +123,7 @@ class WalletSelect extends Component { } render() { - console.log("Wallet Props", this.props); + console.log("WALLET PROPS", this.props); return ( @@ -262,9 +159,9 @@ class WalletSelect extends Component { const mapStateToProps = state => ({ - loading: state.loading, - result: state.result, - error: state.error + loading: state.walletReducer.loading, + result: state.walletReducer.result, + error: state.walletReducer.error }); const mapDispatchToProps = dispatch => bindActionCreators({ diff --git a/webservice/FetchQuery.js b/webservice/FetchQuery.js new file mode 100644 index 00000000..964a3ade --- /dev/null +++ b/webservice/FetchQuery.js @@ -0,0 +1,15 @@ +import { store } from "../redux/store"; +import axios from "axios"; + +const auth = store.getState().authKeyReducer; + +console.log("STORE", auth); + +const fetchQuery = axios.create({ + timeout: 10000, + /* headers: { + 'Authorization': auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '' + } */ +}); + +export default fetchQuery; diff --git a/webservice/WalletApi.js b/webservice/WalletApi.js index 8436ca9a..b5f52ef1 100644 --- a/webservice/WalletApi.js +++ b/webservice/WalletApi.js @@ -1,25 +1,33 @@ -import axios from "axios"; + import { walletActionUrl } from "./IlinkConstants"; import { fetchWalletListPending, fetchWalletListSuccess, fetchWalletListError } from "../redux/actions/WalletActions"; +import fetchQuery from "./FetchQuery"; +import { store } from "../redux/store"; +import axios from "axios"; const getWalletActivated = (userID) => { + const auth = store.getState().authKeyReducer; + const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : ''; + + console.log('AUTHKEY', authKey); + return dispatch => { dispatch(fetchWalletListPending()); - axios.post(`${walletActionUrl}/${userID}/activated`) + axios({ + url: `${walletActionUrl}/${userID}/activated`, + method: 'GET', + headers: { + 'Authorization': authKey + } + }) .then(response => { console.log(response); dispatch(fetchWalletListSuccess(response)); }) .catch(error => { dispatch(fetchWalletListError(error.message)); - if (error.response) - dispatch(fetchWalletListError(error.response)); - else if (error.request) - dispatch(fetchWalletListError(error.request)) - else - dispatch(fetchWalletListError(error.message)) }); } }