From 07da9ea0dccac44e18f49870ef60706ede7fd552 Mon Sep 17 00:00:00 2001 From: Ryan Ghods Date: Fri, 5 Oct 2018 03:10:36 -0700 Subject: [PATCH] Automatically merged updates to draft EIP(s) 1193 Hi, I'm a bot! This change was automatically merged because: - It only modifies existing Draft or Last Call EIP(s) - The PR was approved or written by at least one author of each modified EIP - The build is passing --- EIPS/eip-1193.md | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/EIPS/eip-1193.md b/EIPS/eip-1193.md index 43525650..6dd91abe 100644 --- a/EIPS/eip-1193.md +++ b/EIPS/eip-1193.md @@ -149,7 +149,7 @@ web3.setProvider(ethereum); ethereum .send('eth_getBlockByNumber', ['latest', 'true']) .then(block => { - console.log(`Block ${block.number}:\n${block}`); + console.log(`Block ${block.number}:`, block); }) .catch(error => { console.error( @@ -167,16 +167,16 @@ ethereum // Example 3: Log available accounts ethereum - .send('eth_accounts') - .then(accounts => { - console.log(`Accounts:\n${accounts.join('\n')}`); - }) - .catch(error => { - console.error( - `Error fetching accounts: ${error.message}. + .send('eth_accounts') + .then(accounts => { + console.log(`Accounts:\n${accounts.join('\n')}`); + }) + .catch(error => { + console.error( + `Error fetching accounts: ${error.message}. Code: ${error.code}. Data: ${error.data}` - ); - }); + ); + }); } }) .catch(error => { @@ -193,14 +193,14 @@ ethereum .then(subscriptionId => { subId = subscriptionId; ethereum.on(subscriptionId, block => { - if (result instanceOf Error) { + if (block instanceof Error) { const error = result; console.error( `Error from newHeads subscription: ${error.message}. Code: ${error.code}. Data: ${error.data}` ); } else { - console.log(`New block ${block.number}:\n${block}`); + console.log(`New block ${block.number}:`, block); } }); }) @@ -208,7 +208,7 @@ ethereum console.error( `Error making newHeads subscription: ${error.message}. Code: ${error.code}. Data: ${error.data}` - ); + ); }); // to unsubscribe ethereum @@ -233,9 +233,7 @@ ethereum.removeListener('accountsChanged', logAccounts); // Example 6: Log if connection ends ethereum.on('close', (code, reason) => { - console.log( - `Ethereum provider connection closed: ${reason}. Code: ${code}` - ); + console.log(`Ethereum provider connection closed: ${reason}. Code: ${code}`); }); ``` @@ -377,10 +375,11 @@ class EthereumProvider extends EventEmitter { return promise; } - subscribe(subscriptionType, subscriptionMethod, params) { + subscribe(subscriptionType, subscriptionMethod, params = []) { return this.send(subscriptionType, [subscriptionMethod, ...params]).then( subscriptionId => { this._activeSubscriptions.push(subscriptionId); + return subscriptionId; } ); } @@ -394,6 +393,7 @@ class EthereumProvider extends EventEmitter { ); // Remove listeners on subscriptionId this.removeAllListeners(subscriptionId); + return success; } }); }