scio-labs / use-inkathon

Typesafe React hooks and utility functions that simplify the process of working with Substrate-based networks and ink! smart contracts.
https://inkathon.xyz
GNU General Public License v3.0
51 stars 15 forks source link

store active extension + wallet in localstorage and initialize lazy #74

Open niklasp opened 4 months ago

niklasp commented 4 months ago

This PR closes #15 by storing the selected extension + walletAddress in localstorage when the extension is enabled / the account is selected. The selections are then restored when the dApp is initialized. For backwards compatibility the setActiveAccount function is overridden to atomatically save to local storage.

The other addition is the userWantsConnection const also discussed in #15 which enables a better UX by not popping up extension windows on page visit. For backwards compatibility when connectOnInit is set to true in the provider, the popups remain. When it is set to false and the user already connected an extension + account, it will also connect the wallet on page reload - until the user disconnects.

See also this video with a demo of a first visitor to the dapp

https://github.com/scio-labs/use-inkathon/assets/1685139/038eb1d5-48a6-406c-8d73-de50500bb5eb

and check it out live on a boilerplate including the changes here (with connectOnInit={false} behavior): https://inkathon-frontend-git-localstorage-niklasps-projects.vercel.app/

changeset-bot[bot] commented 4 months ago

⚠️ No Changeset found

Latest commit: 5385fc0c9033e959a90b184ca46021f15dd3d48d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

niklasp commented 3 months ago

@wottpal comments?

langdon0003 commented 1 month ago

@wottpal Could you please take a look and give feedback on this PR, I currently use use-inkathon on my daap and I thing this feature is a must. thank you

wottpal commented 1 month ago

I will revisit this one shortly, sorry for the radio silence :)

niklasp commented 3 weeks ago

@wottpal atm i have to use my cloned version for dapps as this is missing. any chance for merge? I can also change things.

niklasp commented 1 week ago

pong