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 crash if no ethereum object #545

Closed
SionoiS opened this issue Sep 22, 2021 · 4 comments · Fixed by #548
Closed

EIP-1193 crash if no ethereum object #545

SionoiS opened this issue Sep 22, 2021 · 4 comments · Fixed by #548

Comments

@SionoiS
Copy link
Contributor

SionoiS commented Sep 22, 2021

Would be cool if it returned a nice error message when the user has no compatible wallet installed with their browser instead of crashing.

@tomusdrw
Copy link
Owner

Can you provide a code sample? Which line exactly crashes the app?

@SionoiS
Copy link
Contributor Author

SionoiS commented Sep 23, 2021

The ethereum object is undefined.

index-31f41f846045dd9b.js:664 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'on')
    at imports.wbg.__wbg_on_0f85c0c3add89018 (index-31f41f846045dd9b.js:664)
    at web3::transports::eip_1193::Provider::on::haa90b8451281dff2 (index-31f41f846045dd9b_bg.wasm:0x82b319)
    at web3::transports::eip_1193::ProviderAndListeners::on::h67c1a9a03ee86ffa (index-31f41f846045dd9b_bg.wasm:0x69629c)
    at web3::transports::eip_1193::Eip1193::new::h1777e4e309433e74 (index-31f41f846045dd9b_bg.wasm:0x52cd75)
    at web_app::utils::web3::Web3Service::new::he41951d6e5f8c511 (index-31f41f846045dd9b_bg.wasm:0x4db8ad)
    at web_app::main::h44cf0902015ad00d (index-31f41f846045dd9b_bg.wasm:0x605eb5)
    at core::ops::function::FnOnce::call_once::h1a851f6194f89d40 (index-31f41f846045dd9b_bg.wasm:0xa198ef)
    at std::sys_common::backtrace::__rust_begin_short_backtrace::he2f30625ce35cc33 (index-31f41f846045dd9b_bg.wasm:0xa0908c)
    at std::rt::lang_start::{{closure}}::h300b60a332ccf4f7 (index-31f41f846045dd9b_bg.wasm:0x9cbbaf)
    at std::rt::lang_start_internal::h6c264208183e517c (index-31f41f846045dd9b_bg.wasm:0x73d00a)

It should return an error when the ethereum object is not present.

That's line

fn on(_: &Provider, eventName: &str, listener: &Closure<dyn FnMut(JsValue)>);

@tomusdrw
Copy link
Owner

Sorry, but this is not specific enough for me. What do you mean by "it should return an error"? Which part of the code should error out?

The way I see it is we could change the bindgen to return Result<Option<Provider>, JsValue> here and then force the user to handle non-existence in case of using Provider::default().

Can you please share the exact code you are using and how you expect this to be handled?

@SionoiS
Copy link
Contributor Author

SionoiS commented Sep 24, 2021

Yes, returning an Option is fine, no need for an error.

 pub fn default() -> Result<Option<Self>, JsValue> { 

instead of

pub fn default() -> Result<Self, JsValue> {

and

fn get_provider_js() -> Result<Option<Provider>, JsValue>;

instead of

fn get_provider_js() -> Result<Provider, JsValue>;

I will send a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants