ilink-world/webservice/WalletApi.js

120 lines
4.3 KiB
JavaScript

import { walletActionUrl, commissionAmount } 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";
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
}
})
.then(response => {
console.log(response);
dispatch(fetchWalletListSuccess(response));
})
.catch(error => {
console.log(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))
});
}
}
export const resetWalletListReducer = () => {
return dispatch => {
dispatch(fetchWalletListReset());
}
}
export const getWalletDetailActivated = (userID) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchWalletListDetailPending());
axios({
url: `${walletActionUrl}/${userID}/activated`,
method: 'GET',
headers: {
'Authorization': authKey
}
})
.then(response => {
console.log(response);
dispatch(fetchWalletListDetailSuccess(response));
})
.catch(error => {
console.log(error);
dispatch(fetchWalletListDetailError(error.message));
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());
}
}