Updated WebSocketProvider to use web-style event listener API.

This commit is contained in:
Richard Moore 2020-07-13 08:41:54 -04:00
parent 49e83b0c4d
commit 57fd6f0604
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651

@ -278,15 +278,15 @@ export class WebSocketProvider extends JsonRpcProvider {
async destroy(): Promise<void> {
// Wait until we have connected before trying to disconnect
if (this._websocket.readyState === WebSocket.CONNECTING) {
await new Promise((resolve) => {
this._websocket.on("open", () => {
await (new Promise((resolve) => {
this._websocket.onopen = function() {
resolve(true);
});
};
this._websocket.on("error", () => {
this._websocket.onerror = function() {
resolve(false);
});
});
};
}));
}
// Hangup (navigating away from the page that opened the connection)