ilink-world/webservice/WalletTransactionHistoryApi.js

75 lines
2.7 KiB
JavaScript

import { transactionUrl, transactionIlinkUrl } from "./IlinkConstants";
import { store } from "../redux/store";
import axios from "axios";
import I18n from 'react-native-i18n'
import { fetchWalletHistoryPending, fetchWalletHistorySuccess, fetchWalletHistoryError, fetchWalletHistoryReset } 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());
}
}