ilink-world/webservice/WalletApi.js

128 lines
4.5 KiB
JavaScript

import { walletActionUrl, commissionAmount, walletDetailUrl, walletUserSimpleActionUrl } from "./IlinkConstants";
import { fetchWalletListPending, fetchWalletListSuccess, fetchWalletListError, fetchWalletListReset, fetchWalletListDetailPending, fetchWalletListDetailSuccess, fetchWalletListDetailError, fetchWalletListDetailReset, fetchWalletGetCommissionPending, fetchWalletGetCommissionSuccess, fetchWalleGetCommissionError, walletGetCommissionReset } from "../redux/actions/WalletActions";
import { store } from "../redux/store";
import axios from "axios";
import I18n from 'react-native-i18n'
export const getWalletActivated = (userID) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchWalletListPending());
axios({
url: `${walletActionUrl}/${userID}/activated`,
method: 'GET',
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchWalletListSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchWalletListError(error.response));
else if (error.request)
dispatch(fetchWalletListError(error.request))
else
dispatch(fetchWalletListError(error.message))
});
}
}
export const resetWalletListReducer = () => {
return dispatch => {
dispatch(fetchWalletListReset());
}
}
export const getWalletDetailActivated = (id, isAgentCall) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
console.log("isAgentCall", isAgentCall);
let url = null;
if (isAgentCall === null)
url = `${walletUserSimpleActionUrl}/${id}`;
else if (isAgentCall === false)
url = `${walletDetailUrl}/${id}`;
else
url = `${walletActionUrl}/${id}/activated`;
return dispatch => {
dispatch(fetchWalletListDetailPending());
axios({
url,
method: 'GET',
headers: {
'Authorization': authKey
}
})
.then(response => {
console.log("RESPONSE", response);
dispatch(fetchWalletListDetailSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchWalletListDetailError(error.response));
else if (error.request)
dispatch(fetchWalletListDetailError(error.request))
else
dispatch(fetchWalletListDetailError(error.message))
});
}
}
export const resetWalletListDetailReducer = () => {
return dispatch => {
dispatch(fetchWalletListDetailReset());
}
}
export const getWalletCommissionAmount = (data) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchWalletGetCommissionPending());
axios({
url: `${commissionAmount}`,
method: 'POST',
headers: {
'Authorization': authKey
},
data
})
.then(response => {
console.log(response);
dispatch(fetchWalletGetCommissionSuccess(response));
})
.catch(error => {
console.log(error);
dispatch(fetchWalleGetCommissionError(error.message));
if (error.response)
dispatch(fetchWalleGetCommissionError(error.response));
else if (error.request)
dispatch(fetchWalleGetCommissionError(error.request))
else
dispatch(fetchWalleGetCommissionError(error.message))
});
}
}
export const walletCommissionAmountReset = () => {
return dispatch => {
dispatch(walletGetCommissionReset());
}
}