yearn / iearn-finance

Web repository
https://v1.yearn.finance
MIT License
255 stars 296 forks source link

Fix mobile error: "this.send(e), 'this.send' is undefined" #140

Closed ghost closed 3 years ago

ghost commented 3 years ago

I suspect we are seeing this error due to the way we initialize web3.

Currently we dispatch a CONNECTION_CONNECTED event in src/App.js if window.ethereum is available.

    if(window.ethereum) {
      window.ethereum.on('accountsChanged', function (accounts) {
        store.setStore({ account: { address: accounts[0] } })

        const web3context = store.getStore('web3context')
        if(web3context) {
          emitter.emit(CONNECTION_CONNECTED)
        }
      })
    }

We cannot rely on window.ethereum being available upon app initialization. window.ethereum is not immediately available for mobile devices.

We need to follow Metamask's "best practices" guide and add an event listener to listen for ethereum initialization. If we do this this may resolve some of our mobile issues.

https://docs.metamask.io/guide/mobile-best-practices.html#the-provider-window-ethereum

milkyklim commented 3 years ago

Argent has this problem 100% of the time.

ghost commented 3 years ago

See the error message below. This bug is a blocker for Argent integration. It is reproducible 100% of the time by Argent devs.

2020-10-22 16 03 47

Sowul commented 3 years ago

Error fixed on yearn.finance but not on y.finance.

ghost commented 3 years ago

@Sowul y.finance now redirects to yearn.finance