-
Notifications
You must be signed in to change notification settings - Fork 577
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
NIP-07: switching accounts #701
base: master
Are you sure you want to change the base?
Conversation
add events system in window.nostr
I like this. One use case that this doesn't cover cleanly (from a UX perspective) is when a user wants to trigger an account selector from within the app. So for example, I recently added account switching to Coracle — to add a new account, the user clicks + Account, then selects their log in method. If they user is already logged in using an extension, clicking "log in with extension" will only log them in using their current account (or show an error). It would be nice to be able to communicate with the extension to ask the user to select an account. Maybe this is too much for right now, just a thought. |
+1 for multiple accounts. |
This is fine, but instead of these magic strings can we go with hardcoded functions, like |
cool! But most of the events systems I see either use References: is there any specific use case to use hardcoded functions? also, I think it will be hard to implement. current solution uses a single method to handle every new event. |
Yes, but they're all very bad and confusing. Web extensions use the format I'm suggesting. It's much saner. |
I think this issue should be renamed "NIP-07: switch account". At first I thought you were suggesting NIP-07 perform the basic work of clients, which makes no sense. |
Can you elaborate why all are very bad? I think pretty much any app/library I know work like that and I favor the most adopted/known APIs to behave like developers already know and maybe expect it. But I guess this is a personal preference, what are other opinions? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this will break compatibility with old clients that can't recognize this, we should add a enableAccountSwitching
call that signals the app supports account switching.
what would it break? wouldn't clients that do not listen to this event simply behave like it is currently? |
they would not since it is the extension triggering an account switch. |
this is the bahavior right now. The user can change the accounts and clients currently have no way of knowing that the selected key changed. there are also clients that cache the key locally and do not get it from the extension which can also lead to the problem of different keys. |
therefore keys should not be changed without a full page reload unless the client is explicitly aware of this feature |
I like this idea, and will implement in the AKA Profiles signing extension once finalized and merged. |
Implemented in V1.05 of AKA Profiles Extension as |
Adding an enableAccountSwitching call might not be necessary. enforcing a full page reload for account switching might not be practical, as it's up to the provider to handle this behavior, and users might be on different tabs or even different websites at the time of account switching. Therefore, it's best to leave it to the providers. Alby did that even before supporting nostr. let's avoid unnecessary complications. additionally, now Alby + aka-extensions supports this spec can we get this merged? |
Users with more than 1 account often forget to switch to the right Nostr account in an extension. The consequence is a super frustrating experience for users. We regularly read complaints such as "this app is broken" or "Nostr does not work" etc. in our support channels. We would like to prevent such an experience. This enhancement will improve the UX for users by giving clients the chance to react to account switches and show users in which account they're actually logged in. |
Introduction:
The proposed enhancement to the
window.nostr
NIP-07 spec aims to improve user experience by introducing event subscription functionality. By allowing users to subscribe to specific events such asaccountChanged
, we can notify client websites about important changes happening in the connected NIP-07 supported wallet. This will ensure that the client website always displays accurate and up-to-date information, even when users switch between multiple accounts in their NIP-07-supported wallets.Proposal:
One of the essential events we can introduce is
accountChanged
. When the user switches between different accounts in their NIP-07 supported wallet, this event will be triggered, notifying the client website about the account change, and then the client website can update information on the website according to the accountaccountChanged
accountChanged
where
accountChangedHandler
is a listener function that will be invoked on firing the event. You can re-request the user's public key to update website content with data related to the new accountoutput:
2023-08-08.13-54-26.mp4
Additional Information for developers (if required):
EventEmitter
API can be used to implement such events within thewindow.nostr
to facilitate event handling. TheEventEmitter
will allow users to subscribe to specific events and receive notifications when those events occur.documentation for events: https://nodejs.org/dist/v11.13.0/docs/api/events.html#events_class_eventemitter
packages such as events pkg implements the Node.js events module for environments that do not have it, like browsers.
Note: wallets can call the registered event internally using the same provider class as follows
Benefits:
Conclusion:
The introduction of event subscription functionality in
window.nostr
will significantly enhance the user experience for client websites integrated with NIP-07-supported wallets. By leveraging events likeaccountChanged
, client websites can stay in sync with the connected NIP-07-supported wallet, ensuring accurate and up-to-date information for users. This enhancement aligns with our commitment to providing a seamless and user-friendly blockchain wallet experience for our users.