|
|
|
export default class ApiHelper {
|
|
|
|
constructor(options) {
|
|
|
|
this.apiURL = options.state.appSettings.apiURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
getNetworkStats = () => {
|
|
|
|
return this.fetch(`${this.apiURL}/network/stats`, { method: 'GET' })
|
|
|
|
.then(res => Promise.resolve(res));
|
|
|
|
}
|
|
|
|
|
|
|
|
getPoolConfig = () => {
|
|
|
|
return this.fetch(`${this.apiURL}/config`, { method: 'GET' })
|
|
|
|
.then(res => Promise.resolve(res));
|
|
|
|
}
|
|
|
|
|
|
|
|
getPoolStats = () => {
|
|
|
|
return this.fetch(`${this.apiURL}/pool/stats`, { method: 'GET' })
|
|
|
|
.then(res => Promise.resolve(res));
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch = (url, options) => {
|
|
|
|
const headers = options.headers || {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
};
|
|
|
|
|
|
|
|
return fetch(url, { headers, ...options })
|
|
|
|
.then(this._checkStatus)
|
|
|
|
.then(response => response.json());
|
|
|
|
};
|
|
|
|
|
|
|
|
_checkStatus = response => {
|
|
|
|
if (response.status >= 200 && response.status < 300) {
|
|
|
|
return response;
|
|
|
|
} else {
|
|
|
|
const error = new Error(response.statusText);
|
|
|
|
error.response = response;
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|