Conversation
bb46ee1 to
9d142bd
Compare
9d142bd to
845eb8d
Compare
danfinlay
left a comment
There was a problem hiding this comment.
Looks good, safe, and useful!
I'm happy to merge it before I continue my branch kinda refactoring how the provider communicates with the background, so I can just handle the conflicts with this PR fresh in my head.
Some small comments but nothing that can't be cleaned up or refined later imo, no blockers.
| module.exports = function createBlockTracker (args, platform) { | ||
| const blockTracker = new BlockTracker(args) | ||
| blockTracker.on('latest', () => { | ||
| platform && platform.sendMessage && platform.sendMessage({ action: 'ethereum-ping-success' }) |
There was a problem hiding this comment.
Oh cool, so this means dapps can now receive push events on new blocks?
| }) | ||
| } catch (error) { | ||
| // Per EIP-1193, send should never throw, only reject its Promise. Here | ||
| // we swallow thrown errors, which is safe since we handle them above. |
There was a problem hiding this comment.
This still makes me nervous. resolve() is safe to call twice, so as a casual reader, I would gain confidence seeing a reject() here too in case it ever isn't handled correctly.
There was a problem hiding this comment.
I too feel like this should reject the promise, esp. if it's part of the contract that sendAsync doesn't throw sync errors.
| 'November 2nd, 2018. Dapps should now call provider.enable() in order to view and use ' + | ||
| 'accounts. Please see https://bit.ly/2QQHXvF for complete information and up-to-date ' + | ||
| 'example code.') | ||
|
|
There was a problem hiding this comment.
This will make certain twitter users happy ;)
whymarrh
left a comment
There was a problem hiding this comment.
I'm excited for this! I've left a few small comments.
| platform && platform.sendMessage && platform.sendMessage({ action: 'ethereum-ping-success' }) | ||
| }) | ||
| blockTracker.on('error', () => { | ||
| platform && platform.sendMessage && platform.sendMessage({ action: 'ethereum-ping-error' }) |
There was a problem hiding this comment.
Can we use an if block here? We might be getting away with too many of these single-line expressions. 😄
There was a problem hiding this comment.
Similarly for on('latest', ...) above
There was a problem hiding this comment.
But such terse syntax! Fixed :)
| } | ||
|
|
||
| _onClose () { | ||
| (this._isConnected === undefined || this._isConnected) && this._provider.emit('close', { |
There was a problem hiding this comment.
Can we use an if block here as well?
| }) | ||
| } catch (error) { | ||
| // Per EIP-1193, send should never throw, only reject its Promise. Here | ||
| // we swallow thrown errors, which is safe since we handle them above. |
There was a problem hiding this comment.
I too feel like this should reject the promise, esp. if it's part of the contract that sendAsync doesn't throw sync errors.
| export default function createStandardProvider (provider) { | ||
| const standardProvider = new StandardProvider(provider) | ||
| const sendLegacy = provider.send | ||
| provider.send = (a, b) => { |
There was a problem hiding this comment.
Can we be a bit more specific with the argument names here?
There was a problem hiding this comment.
Since these can be completely different types of variables depending on what API you're targeting (standard or legacy), good names were tough. I improved them as best I could though, I think we can do better than a and b, you're right :)
| const standardProvider = new StandardProvider(provider) | ||
| const sendLegacy = provider.send | ||
| provider.send = (a, b) => { | ||
| if (typeof payload === 'string' && !b || Array.isArray(b)) { |
There was a problem hiding this comment.
Where does payload come from?
There was a problem hiding this comment.
Great save, should be a, or what is now methodOrPayload.
danfinlay
left a comment
There was a problem hiding this comment.
This looks good. Thank you!
|
|
||
| return new Promise((resolve, reject) => { | ||
| try { | ||
| this._provider.sendAsync({ method, params, beta: true }, (error, response) => { |
There was a problem hiding this comment.
If may, why use beta: true and not the classic jsonrpc: '2.0' ?
I think this the cause of this issue : MM 6.2.1 sends invalid JSONRPC requests to private network
|
Historical note: this reintroduced always-on block tracker |


This pull request adds a new inpage adapter that exposes a provider API that conforms to EIP-1193. The exposure of this API is done so in a way that coexists with the legacy API without additional global namespace pollution.
The key difference between the legacy provider API and the standard provider API is the
sendmethod; formerly, this method was a synchronous method that was rarely used in production dapps. In the new API,sendbecomes asynchronous and replacessendAsync, which goes away entirely. So to summarize, a single asynchronoussendmethod and five emitted events are all that make up the standard provider API. So, per @danfinlay's suggestion, we can gracefully let these two APIs initially coexist:sendto determine legacy vs. standard.This means the following provider APIs all work with this PR: