diff --git a/index.html b/index.html
index 679e1d4..b1d3bf3 100644
--- a/index.html
+++ b/index.html
@@ -41,8 +41,23 @@
document.getElementById('peers').innerText = peerCount;
}
+const nimiqInitPromise = new Promise((resolve, reject) => Nimiq.init(resolve, (code) => {
+ switch (code) {
+ case Nimiq.ERR_WAIT:
+ alert('Error: Already open in another tab or window.');
+ break;
+ case Nimiq.ERR_UNSUPPORTED:
+ alert('Error: Browser not supported');
+ break;
+ default:
+ alert('Error: Nimiq initialization error');
+ break;
+ }
+ reject(code);
+}));
+
function init(clientType = 'pico') {
- Nimiq.init(async function() {
+ nimiqInitPromise.then(async () => {
document.getElementById('message').innerText = 'Nimiq loaded. Connecting and establishing consensus.';
// Connect to the testnet.
@@ -83,19 +98,6 @@
// Update the peer count every 1 second
setInterval(_updatePeerCount, 1000);
-
- }, function(code) {
- switch (code) {
- case Nimiq.ERR_WAIT:
- alert('Error: Already open in another tab or window.');
- break;
- case Nimiq.ERR_UNSUPPORTED:
- alert('Error: Browser not supported');
- break;
- default:
- alert('Error: Nimiq initialization error');
- break;
- }
});
}