169 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			169 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
| 
 | |
| import { walletActionUrl, commissionAmount, walletDetailUrl, walletUserSimpleActionUrl, linkCardUrl } from "./IlinkConstants";
 | |
| import {
 | |
|      fetchWalletListPending, fetchWalletListSuccess, fetchWalletListError, fetchWalletListReset,
 | |
|      fetchWalletListDetailPending, fetchWalletListDetailSuccess, fetchWalletListDetailError, fetchWalletListDetailReset,
 | |
|      fetchWalletGetCommissionPending, fetchWalletGetCommissionSuccess, fetchWalleGetCommissionError, walletGetCommissionReset,
 | |
|      fetchLinkCardPending, fetchLinkCardSuccess, fetchLinkCardError, fetchLinkCardReset
 | |
| } 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());
 | |
|      }
 | |
| } |