Skip to content

Commit

Permalink
bug: fix sendRpcRequest not returning result
Browse files Browse the repository at this point in the history
  • Loading branch information
Zurcusa committed Aug 30, 2024
1 parent dd94d79 commit 2f98bd5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
4 changes: 0 additions & 4 deletions src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@
// stream.end();
// });
}
// Test
sendRpcRequest('system_name', []);
main();
// Test 2
sendRpcRequest('chain_getBlock', []);
</script>
</body>
</html>
24 changes: 19 additions & 5 deletions src/main/webapp/js/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
}

0 comments on commit 2f98bd5

Please sign in to comment.