Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP-1193 updates #2856

Merged
merged 5 commits into from
Jun 2, 2019
Merged

EIP-1193 updates #2856

merged 5 commits into from
Jun 2, 2019

Conversation

JunichiSugiura
Copy link

Description

Currently, if we instantiate Web3 with EIP1193 compatible provider, the provider resolver resolves CustomProvider for Eth and Shh module. This causes that the provider's send method receives payload as the first argument and callback function as the second argument when a dapp calls web3.eth.getAccounts() for example.

Code to reproduce

const Web3 = require('web3')
const EventEmitter = require('events')

class Provider extends EventEmitter {
  constructor() {
    super()
    this.isEIP1193 = true
  }
}

const provider = new Provider()
const web3 = new Web3(provider)

console.log(web3.currentProvider.constructor.name)
// -> Web3EthereumProvider

console.log(web3.eth._currentProvider.constructor.name)
// -> CustomProvider

I added another condition for the resolver to check if the provider is Web3EthereumProvider then return the provider itself.

I hope this helps.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Enhancement

Checklist:

  • I have selected the correct base branch.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no warnings.
  • I have updated or added types for all modules I've changed
  • Any dependent changes have been merged and published in downstream modules.
  • I ran npm run test in the root folder with success and extended the tests if necessary.
  • I ran npm run build in the root folder and tested it in the browser and with node.
  • I ran npm run dtslint in the root folder and tested that all my types are correct
  • I have tested my code on an ethereum test network.

@coveralls
Copy link

coveralls commented May 29, 2019

Coverage Status

Coverage increased (+0.003%) to 95.865% when pulling 406bf68 on LukeSugiura:hotfix/provider-resolver into 9f95015 on ethereum:1.0.

@JunichiSugiura
Copy link
Author

Another solution is to add `isEIP1193' property to Web3EthereumProvider class. @nivida What do you think?

@nivida nivida added the On Ice Important but no longer pursued for the near future label May 29, 2019
@nivida nivida changed the title Resolve Web3EthereumProvider intead of CustomProvider for Eth and Shh module EIP-1193 updates May 29, 2019
@nivida nivida added Bug Addressing a bug In Progress Currently being worked on and removed On Ice Important but no longer pursued for the near future labels May 30, 2019
@JunichiSugiura
Copy link
Author

@nivida I applied your change request and added a test for the resolver logic. Could you review this again?

@nivida nivida removed the In Progress Currently being worked on label Jun 2, 2019
@nivida nivida merged commit caa9410 into web3:1.0 Jun 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants