getAlby / lightning-browser-extension

The Bitcoin Lightning Browser Extension that brings deep Lightning & Nostr integration to the web. Wallet interface to multiple lightning nodes and key signer for Nostr, Liquid and onchain use.
https://getalby.com/#extension
MIT License
540 stars 194 forks source link

[Feature] Better handling of connector init failure / disconnect #2468

Open rolznz opened 1 year ago

rolznz commented 1 year ago

Feature description

Currently we assume the connector init() function always works.

If the init() function doesn't work, the connector is left in a broken state, and multiple error toasts are displayed each time a call is requested (at least two - getinfo and invoices)

Describe the solution

I think we either should have a state where shows the connection failed, and the user can either retry or switch account. If the init fails or the connector disconnects at some point, we shouldn't still try to access the connector to get new data (which causes a cascading list of error messages)

Describe alternatives

No response

Additional context

No response

Are you working on this?

None

rolznz commented 1 year ago

Also, the app unlock screen is stuck loading while slow connectors load. Ideally we should have a connector loading screen image

rolznz commented 1 year ago

Notes from @reneaaron

I always wondered why after a failed request with Alby (offline, 503 error, etc) I have to reload the extension before it starts to work again. Seems the the failed promise is stored in state.connector which was introduced with this commit. (this breaks every subsequent request done via the connector and prevents you e.g. from unloading, because the failed promise is cached and immediately returns)

Now I just stumbled upon Roland's PR to fix that for LNC and think this needs to be solved at the root of the problem. (and not in the connector individually)

rolznz commented 1 year ago

Another issue: It's impossible to switch accounts / cancel loading of an account when one is currently loading. You have to wait for the account to fail loading before you can switch.

fczuardi commented 1 year ago

Notes from @reneaaron

I always wondered why after a failed request with Alby (offline, 503 error, etc) I have to reload the extension before it starts to work again. Seems the the failed promise is stored in state.connector which was introduced with this commit. (this breaks every subsequent request done via the connector and prevents you e.g. from unloading, because the failed promise is cached and immediately returns)

Now I just stumbled upon Roland's PR to fix that for LNC and think this needs to be solved at the root of the problem. (and not in the connector individually)

so, the same try /catch of lnc here? https://github.com/getAlby/lightning-browser-extension/blob/master/src/extension/background-script/state.ts#L112

rolznz commented 1 year ago

@fczuardi that would be a good start (I think there is one other usage of connector.init() which would also need to have the same error handling)