You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

export default class ApiHelper {
constructor(options) {
this.apiURL = options.state.appSettings.apiURL;
}
getMinerStats = address => {
return this.fetch(`${this.apiURL}/miner/${address}/stats`, { method: 'GET' })
.then(res => Promise.resolve(res));
}
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;
}
};
}