simba-mobile-cad3/app/webservice/UpdateDefaultNetworkApi.js

53 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2025-01-07 09:47:45 +00:00
import {store} from "../redux/store";
import {
fetchGetNotificationError,
fetchGetNotificationPending,
fetchGetNotificationSuccess
} from "../redux/actions/NanoCreditAction";
import axios from "axios";
import {getNotificationUrl, updateDefaultNetworkUrl} from "./IlinkConstants";
import I18n from "react-native-i18n";
import {
fetchUpdateDefaultNetworkError,
fetchUpdateDefaultNetworkPending, fetchUpdateDefaultNetworkReset,
fetchUpdateDefaultNetworkSuccess
} from "../redux/actions/WalletActions";
export const updateDefaultNetworkAction = (data) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchUpdateDefaultNetworkPending());
axios({
url: updateDefaultNetworkUrl,
method: 'POST',
data,
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchUpdateDefaultNetworkSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchUpdateDefaultNetworkError(error.response));
else if (error.request)
dispatch(fetchUpdateDefaultNetworkError(error.request))
else
dispatch(fetchUpdateDefaultNetworkError(error.message))
});
}
}
export const updateDefaultNetworkReset = () => {
return dispatch => {
dispatch(fetchUpdateDefaultNetworkReset());
}
}