Добрый день ! Как сделать fetch запрос на данный кусок кода.
var getUserBalanse = () =>{
if (!license_active) return;
var xhr = new XMLHttpRequest();
var url = localStorage.getItem('REQUEST_URL').replace(/"/g, '') + "/api/v2/balance/owner";
xhr.open("GET", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Accept", ["application/json", "text/plain", "*/*"]);
xhr.setRequestHeader("x-token", localStorage.getItem('_wb-ext-user-token').replace(/"/g, ''));
xhr.onreadystatechange = () => {
if (xhr.readyState === 4 && xhr.status === 200) {
var json = JSON.parse(xhr.responseText);
if (json.data&& json.data.length > 0) {
var pvbal = document.getElementById('mybalans');
if(!pvbal) {
pvbal = document.createElement("div");
pvbal.id = 'mybalans';
document.body.appendChild(pvbal);
}
pvzbal.innerHTML = `<div class="hash__pv"> ${json.summ} </span>`;
console.log(json);
}
}
};
xhr.send();
}
getUserBalanse()