ilink-world/webservice/WalletTransactionHistoryApi.js

75 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-04-28 09:22:36 +00:00
2020-07-09 19:15:11 +00:00
import { transactionUrl, transactionIlinkUrl } from "./IlinkConstants";
2020-04-28 09:22:36 +00:00
import { store } from "../redux/store";
import axios from "axios";
2020-05-06 13:07:53 +00:00
import I18n from 'react-native-i18n'
2020-05-03 09:16:24 +00:00
import { fetchWalletHistoryPending, fetchWalletHistorySuccess, fetchWalletHistoryError, fetchWalletHistoryReset } from "../redux/actions/WalletActions";
2020-04-28 09:22:36 +00:00
2020-07-09 19:15:11 +00:00
export const getWalletTransactionHistory = (walletID, isiLinkWorldWallet) => {
2020-04-28 09:22:36 +00:00
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
2020-07-15 16:25:32 +00:00
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}` : '';
2020-04-28 09:22:36 +00:00
return dispatch => {
dispatch(fetchWalletHistoryPending());
axios({
2020-07-15 16:25:32 +00:00
url: `${transactionIlinkUrl}/user/${walletID}`,
2020-04-28 09:22:36 +00:00
method: 'GET',
headers: {
2020-05-06 13:07:53 +00:00
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
2020-04-28 09:22:36 +00:00
}
})
.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))
});
}
}
2020-05-03 09:16:24 +00:00
export const getWalletTransactionHistoryReset = () => {
return dispatch => {
dispatch(fetchWalletHistoryReset());
}
}