blocknative / web3-onboard

Client library to onboard users to web3 apps
https://onboard.blocknative.com/
MIT License
813 stars 474 forks source link

a disconnect error by default value or other reason can not set local storage #2227

Closed logsdk closed 2 weeks ago

logsdk commented 3 weeks ago

Current Behavior

1、connect wallet, tips successful 2、discount wallet, error

SyntaxError: Unexpected end of JSON input at JSON.parse () at disconnect (index-34745058.js:3597:25) at async eval (useConnectWallet.js:25:29)

in packages/core/src/disconnect.ts:47

const labels = JSON.parse(getLocalStore(STORAGE_KEYS.LAST_CONNECTED_WALLET) || '');

if can not get last connected wallet, the default value '', can not be parsed by JSON.

Expected Behavior

disconnect wallet successful

Steps To Reproduce

No response

What package is effected by this issue?

@web3-onboard/core

Is this a build or a runtime issue?

Runtime

Package Version

2.22.1

Node Version

No response

What browsers are you seeing the problem on?

No response

Relevant log output

No response

Anything else?

No response

Sanity Check

Adamj1232 commented 3 weeks ago

Hi @logsdk can you provide more context for me around what this code is trying to do?

ignromanov commented 3 weeks ago

Hi. The same issue. You need to connect to the DApp using Rabby wallet. After pressing the disconnect button (calling the disconnect function) - an error is thrown.

  const [{ wallet }, disconnect] = useConnectWallet()
  await disconnect(wallet)

The reason is that the onboard.js:last_connected_wallet key is missing from the local storage

Adamj1232 commented 3 weeks ago

@ignromanov Disconnect using the approach as shown above working without issue on our demo sites - https://github.com/blocknative/react-demo/blob/89509379f4cd09299b45b2301769aa80a7c58991/src/App.js#L543 If you can provide more code for context I can assist further

ignromanov commented 3 weeks ago

The reason was that flags autoConnectLastWallet and autoConnectAllPreviousWallet were false during onboard initialization

Adamj1232 commented 3 weeks ago

@ignromanov does that mean we can close this issue?

ignromanov commented 3 weeks ago

@Adamj1232 I think you should test with these flags set to False. You will get a disconnect error.

Adamj1232 commented 3 weeks ago

@ignromanov I am still unable to reproduce the disconnect error - I made a video of what I am seeing when trying this locally. https://www.loom.com/share/3d73a7ccfa1645cb9deb820fb8ea438c?sid=93f5efb4-5539-4075-a204-c9ea9dcea605 Might be good to confirm you are on the latest version of "@web3-onboard/injected-wallets": "^2.11.1"

ignromanov commented 3 weeks ago

@Adamj1232 I tried it on your test application. Try with these changes to reproduce it. I got an error.

image
Adamj1232 commented 3 weeks ago

@ignromanov I am still unable to reproduce an error with that change

ignromanov commented 3 weeks ago

@Adamj1232 Recorded a video reproduction of the error. Launched your repository with the change described above.

https://github.com/blocknative/web3-onboard/assets/3179314/c4428a70-e6ae-4056-909e-0adf7bf19bdb

satoshisafedevs commented 3 weeks ago

We are seeing this same issue with the latest version on all packages and brave browser.

Adamj1232 commented 2 weeks ago

@ignromanov ahh ok I think I got it figured out, required a local storage clear to reproduce. Looking into this today. Will have a fix shortly.

Adamj1232 commented 2 weeks ago

@ignromanov please give this a shot with the latest alpha version of @web3-onboard/core or framework package noted in the PR above - would love validation on your end prior to release