eth-provider
Advanced tools
Comparing version 0.10.0 to 0.11.0
@@ -32,4 +32,3 @@ const EventEmitter = require('events') | ||
if (!this.connected) return this.connectionError(index, err) | ||
if (this.listenerCount('error')) return this.emit('error', err) | ||
console.warn('eth-provider - Uncaught connection error: ' + err.message) | ||
this.onError(err) | ||
}) | ||
@@ -58,2 +57,7 @@ | ||
onError (err) { | ||
if (this.listenerCount('error')) return this.emit('error', err) | ||
console.warn('[eth-provider] Uncaught connection error: ' + err.message) | ||
} | ||
refresh (interval = this.interval) { | ||
@@ -60,0 +64,0 @@ if (dev) console.log(`Reconnect queued for ${(interval / 1000).toFixed(2)}s in the future`) |
@@ -22,4 +22,8 @@ const EventEmitter = require('events') | ||
onError (err) { | ||
if (!this.closed && this.listenerCount('error')) this.emit('error', err) | ||
} | ||
create () { | ||
if (!XHR) return this._emit('error', new Error('No HTTP transport available')) | ||
if (!XHR) return this.onError(new Error('No HTTP transport available')) | ||
this.on('error', () => { if (this.connected) this.close() }) | ||
@@ -31,3 +35,3 @@ this.init() | ||
this.send({ jsonrpc: '2.0', method: 'net_version', params: [], id: 1 }, (err, response) => { | ||
if (err) return this._emit('error', err) | ||
if (err) return this.onError(err) | ||
this.connected = true | ||
@@ -48,3 +52,3 @@ this._emit('connect') | ||
this.subscriptionTimeout = setTimeout(() => this.pollSubscriptions(), 10000) | ||
return this._emit('error', err) | ||
return this.onError(err) | ||
} else { | ||
@@ -51,0 +55,0 @@ if (!this.closed) this.subscriptionTimeout = this.pollSubscriptions() |
@@ -7,9 +7,13 @@ const EventEmitter = require('events') | ||
if (_injected) { | ||
setTimeout(() => this.emit('error', new Error('Injected web3 provider is not currently supported')), 0) | ||
setTimeout(() => this.onError(new Error('Injected web3 provider is not currently supported')), 0) | ||
} else { | ||
setTimeout(() => this.emit('error', new Error('No injected provider found')), 0) | ||
setTimeout(() => this.onError(new Error('No injected provider found')), 0) | ||
} | ||
} | ||
onError (err) { | ||
if (this.listenerCount('error')) this.emit('error', err) | ||
} | ||
} | ||
module.exports = injected => options => new InjectedConnection(injected, options) |
@@ -16,3 +16,3 @@ const EventEmitter = require('events') | ||
create (path, options) { | ||
if (!net) return this.emit('error', new Error('No IPC transport')) | ||
if (!net) return this.onError(new Error('No IPC transport')) | ||
this.socket = net.connect({ path }) | ||
@@ -31,5 +31,9 @@ this.socket.on('connect', () => { | ||
}) | ||
this.socket.on('error', err => this.emit('error', err)) | ||
this.socket.on('error', err => this.onError(err)) | ||
} | ||
onError (err) { | ||
if (this.listenerCount('error')) this.emit('error', err) | ||
} | ||
onClose () { | ||
@@ -36,0 +40,0 @@ this.socket = null |
@@ -6,6 +6,10 @@ const EventEmitter = require('events') | ||
super() | ||
setTimeout(() => this.emit('error', new Error(message)), 0) | ||
setTimeout(() => this.onError(new Error(message)), 0) | ||
} | ||
onError (err) { | ||
if (this.listenerCount('error')) this.emit('error', err) | ||
} | ||
} | ||
module.exports = message => () => new UnavailableConnection(message) |
@@ -21,4 +21,8 @@ const EventEmitter = require('events') | ||
create (url, options) { | ||
if (!WebSocket) this.emit('error', new Error('No WebSocket transport available')) | ||
try { this.socket = new WebSocket(url, [], { origin: options.origin }) } catch (e) { return this.emit('error', e) } | ||
if (!WebSocket) return this.onError(new Error('No WebSocket transport available')) | ||
try { | ||
this.socket = new WebSocket(url, [], { origin: options.origin }) | ||
} catch (e) { | ||
return this.onError(e) | ||
} | ||
@@ -51,7 +55,8 @@ this.socket.addEventListener('error', this.onError) | ||
onError (err) { | ||
this.emit('error', err) | ||
if (this.listenerCount('error')) this.emit('error', err) | ||
} | ||
onClose (e) { | ||
clearTimeout(this.closeTimeout) | ||
// onClose should only be called as a result of the socket's close event | ||
// OR when close() is called manually and the socket either doesn't exist or is already in a closed state | ||
@@ -64,6 +69,3 @@ const err = { | ||
if (this.socket) { | ||
this.socket.removeEventListener('open', this.onOpen) | ||
this.socket.removeEventListener('close', this.onClose) | ||
this.socket.removeEventListener('message', this.onMessage) | ||
this.socket.removeEventListener('error', this.onError) | ||
this.socket.removeAllListeners() | ||
this.socket = null | ||
@@ -81,10 +83,11 @@ } | ||
close () { | ||
if (this.socket) { | ||
this.socket.close() | ||
// give the socket close event some time to fire, otherwise we can clean up | ||
// and close everything manually | ||
this.closeTimeout = setTimeout(() => { | ||
this.onClose() | ||
}, 1000) | ||
if (this.socket && WebSocket && this.socket.readyState !== WebSocket.CLOSED) { | ||
this.socket.removeAllListeners() | ||
this.socket.addEventListener('error', () => {}) | ||
this.socket.addEventListener('close', this.onClose) | ||
if (this.socket.terminate) { | ||
this.socket.terminate() | ||
} else { | ||
this.socket.close() | ||
} | ||
} else { | ||
@@ -91,0 +94,0 @@ this.onClose() |
{ | ||
"name": "eth-provider", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"description": "A Universal Ethereum Provider", | ||
@@ -32,9 +32,9 @@ "browser": "browser.js", | ||
"uuid": "8.3.2", | ||
"ws": "8.4.0", | ||
"ws": "8.5.0", | ||
"xhr2-cookies": "1.1.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "9.1.3", | ||
"standard": "16.0.4" | ||
"mocha": "9.2.2", | ||
"standard": "17.0.0" | ||
} | ||
} |
@@ -61,7 +61,6 @@ /* globals describe it */ | ||
it('should have no accounts on accountChange', done => { | ||
console.log('Close your Frame account') | ||
it('should get accountsChanged event', done => { | ||
console.log('Change your Frame account') | ||
const accountsChanged = accounts => { | ||
assert(Array.isArray(accounts)) | ||
assert(accounts.length === 0) | ||
ethereum.off('accountsChanged', accountsChanged) | ||
@@ -73,11 +72,2 @@ done() | ||
it('should have an account on accountChange', done => { | ||
console.log('Open a Frame account') | ||
ethereum.once('accountsChanged', accounts => { | ||
assert(Array.isArray(accounts)) | ||
assert(accounts.length > 0) | ||
done() | ||
}) | ||
}).timeout(45 * 1000) | ||
it('should subscribe to newBlockHeaders using EIP-1193 spec', done => { | ||
@@ -84,0 +74,0 @@ const waitForNewHead = async () => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
570004
1355