diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index 241c71813..1cb2bad07 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -68,11 +68,7 @@ // stream.end(); // }); } - // Test - sendRpcRequest('system_name', []); main(); - // Test 2 - sendRpcRequest('chain_getBlock', []); \ No newline at end of file diff --git a/src/main/webapp/js/http.js b/src/main/webapp/js/http.js index e68f3829f..fec1de453 100644 --- a/src/main/webapp/js/http.js +++ b/src/main/webapp/js/http.js @@ -40,9 +40,23 @@ function httpRequestSync(method, url, body) { var isRpcExported = false; function sendRpcRequest(method, params) { - if (isRpcExported === false) { - window.setTimeout(() => sendRpcRequest(method, params), 10); - } else { - console.log(rpc.sendRequest(method, params)); - } + return new Promise((resolve, reject) => { + if (isRpcExported === false) { + window.setTimeout(async () => { + try { + const result = await sendRpcRequest(method, params); + resolve(result); + } catch (error) { + reject(error); + } + }, 10); + } else { + try { + const result = rpc.sendRequest(method, params); + resolve(result); + } catch (error) { + reject(error); + } + } + }); }