228 lines
6.9 KiB
JavaScript
228 lines
6.9 KiB
JavaScript
import {
|
|
commissionAmount,
|
|
getOperatorListUrl,
|
|
linkCardUrl,
|
|
walletActionUrl,
|
|
walletDetailUrl,
|
|
walletUserSimpleActionUrl
|
|
} from "./IlinkConstants";
|
|
import {
|
|
fetchGetListOperatorError,
|
|
fetchGetListOperatorPending,
|
|
fetchGetListOperatorReset,
|
|
fetchGetListOperatorSuccess,
|
|
fetchLinkCardError,
|
|
fetchLinkCardPending,
|
|
fetchLinkCardReset,
|
|
fetchLinkCardSuccess,
|
|
fetchWalleGetCommissionError,
|
|
fetchWalletGetCommissionPending,
|
|
fetchWalletGetCommissionSuccess,
|
|
fetchWalletListDetailError,
|
|
fetchWalletListDetailPending,
|
|
fetchWalletListDetailReset,
|
|
fetchWalletListDetailSuccess,
|
|
fetchWalletListError,
|
|
fetchWalletListPending,
|
|
fetchWalletListReset,
|
|
fetchWalletListSuccess,
|
|
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());
|
|
}
|
|
}
|
|
|
|
export const linkCardAction = (data, userID) => {
|
|
|
|
const auth = store.getState().authKeyReducer;
|
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
|
|
|
return dispatch => {
|
|
dispatch(fetchLinkCardPending());
|
|
|
|
axios({
|
|
url: `${linkCardUrl}/${userID}`,
|
|
data,
|
|
method: 'POST',
|
|
headers: {
|
|
'Authorization': authKey,
|
|
'X-Localization': I18n.currentLocale()
|
|
}
|
|
})
|
|
.then(response => {
|
|
console.log(response);
|
|
dispatch(fetchLinkCardSuccess(response));
|
|
})
|
|
.catch(error => {
|
|
if (error.response)
|
|
dispatch(fetchLinkCardError(error.response));
|
|
else if (error.request)
|
|
dispatch(fetchLinkCardError(error.request))
|
|
else
|
|
dispatch(fetchLinkCardError(error.message))
|
|
});
|
|
}
|
|
}
|
|
export const linkCardReset = () => {
|
|
return dispatch => {
|
|
dispatch(fetchLinkCardReset());
|
|
}
|
|
}
|
|
|
|
|
|
export const getOperatorListAction = (typeOperator, idNetworkWallet) => {
|
|
|
|
const auth = store.getState().authKeyReducer;
|
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
|
|
|
return dispatch => {
|
|
dispatch(fetchGetListOperatorPending());
|
|
|
|
axios({
|
|
url: `${getOperatorListUrl}/${typeOperator}/${idNetworkWallet}`,
|
|
method: 'GET',
|
|
headers: {
|
|
'Authorization': authKey,
|
|
'X-Localization': I18n.currentLocale()
|
|
}
|
|
})
|
|
.then(response => {
|
|
console.log(response);
|
|
dispatch(fetchGetListOperatorSuccess(response));
|
|
})
|
|
.catch(error => {
|
|
if (error.response)
|
|
dispatch(fetchGetListOperatorError(error.response));
|
|
else if (error.request)
|
|
dispatch(fetchGetListOperatorError(error.request))
|
|
else
|
|
dispatch(fetchGetListOperatorError(error.message))
|
|
});
|
|
}
|
|
}
|
|
export const getOperatorListReset = () => {
|
|
return dispatch => {
|
|
dispatch(fetchGetListOperatorReset());
|
|
}
|
|
} |