import { transactionUrl, transactionIlinkUrl, getHyperviseurHistoriqueUrl, getSuperviseurHistoriqueUrl, getHistoryOrdersReceiptSuperUrl, testBaseUrl } from "./IlinkConstants"; import {store} from "../redux/store"; import axios from "axios"; import I18n from 'react-native-i18n' import { fetchWalletHistoryPending, fetchWalletHistorySuccess, fetchWalletHistoryError, fetchWalletHistoryReset, fetchWalletHistoryHyperSuperPending, fetchWalletHistoryHyperSuperSuccess, fetchWalletHistoryHyperSuperError, fetchWalletHistoryHyperSuperReset } from "../redux/actions/WalletActions"; export const getWalletTransactionHistory = (walletID, isiLinkWorldWallet) => { const auth = store.getState().authKeyReducer; const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : ''; return dispatch => { dispatch(fetchWalletHistoryPending()); axios({ url: isiLinkWorldWallet ? `${transactionIlinkUrl}/agent/${walletID}` : `${transactionUrl}/${walletID}`, method: 'GET', headers: { 'Authorization': authKey, 'X-Localization': I18n.currentLocale() } }) .then(response => { console.log(response); dispatch(fetchWalletHistorySuccess(response)); }) .catch(error => { if (error.response) dispatch(fetchWalletHistoryError(error.response)); else if (error.request) dispatch(fetchWalletHistoryError(error.request)) else dispatch(fetchWalletHistoryError(error.message)) }); } } export const getWalletTransactionHistoryUser = (walletID) => { const auth = store.getState().authKeyReducer; const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : ''; return dispatch => { dispatch(fetchWalletHistoryPending()); axios({ url: `${transactionIlinkUrl}/user/${walletID}`, method: 'GET', headers: { 'Authorization': authKey, 'X-Localization': I18n.currentLocale() } }) .then(response => { console.log(response); dispatch(fetchWalletHistorySuccess(response)); }) .catch(error => { if (error.response) dispatch(fetchWalletHistoryError(error.response)); else if (error.request) dispatch(fetchWalletHistoryError(error.request)) else dispatch(fetchWalletHistoryError(error.message)) }); } } export const getWalletTransactionHistoryReset = () => { return dispatch => { dispatch(fetchWalletHistoryReset()); } } export const getHyperSuperTransactionHistoryAction = (walletID, isHyper, transactionType) => { const auth = store.getState().authKeyReducer; const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : ''; let url = "/walletService/history"; switch (isHyper) { case true: url += "/hyper"; break; case false: url += "/super"; break; case null: url += "/agent"; break; } switch (transactionType) { case 0: url += ""; break; case 1: url += "/tax_notices"; break; case 2: if (isHyper) url += "/revenue_orders"; else url += "/orders_receipts"; break; case 3: url += "/receipts"; break; } return dispatch => { dispatch(fetchWalletHistoryHyperSuperPending()); axios({ url: `${testBaseUrl + url}/${walletID}`, method: 'GET', headers: { 'Authorization': authKey, 'X-Localization': I18n.currentLocale() } }) .then(response => { console.log(response); dispatch(fetchWalletHistoryHyperSuperSuccess(response)); }) .catch(error => { if (error.response) dispatch(fetchWalletHistoryHyperSuperError(error.response)); else if (error.request) dispatch(fetchWalletHistoryHyperSuperError(error.request)) else dispatch(fetchWalletHistoryHyperSuperError(error.message)) }); } } export const getHyperSuperTransactionHistoryReset = () => { return dispatch => { dispatch(fetchWalletHistoryHyperSuperReset()); } }