Open RyanTimesTen opened 11 months ago
thanks @RyanTimesTen.
Perhaps we could get by with the existing set of events (account/network changed) and just emit, on the wallet side, an undefined
account-address once the user locks the wallet?
How about adding a flag to enable
that states the dapp doesn't want to show a popup/UI in case the wallet is locked and/or not preauthorized?
This way, you could call it naively once the user chooses a wallet. If it works (e.g. you got an address back), perfect; if not, you'll get undefined
for the address and realize that either you aren't preauthorized or the wallet is locked.
@avimak
disconnect
event is be clearer and more explicit IMO. this event could also be emitted when the user removes the dapp connection from their walleti updated the proposal with your suggestions, thank you
@RyanTimesTen wrt silent-mode, pls see https://github.com/starknet-io/get-starknet/pull/194 (RequestAccountsParameters
); will be implemented as part of that PR
thanks @avimak. both Braavos wallet and ArgentX will need to release updates to support this, right?
yes, cc @janek26
Background
At Dynamic, we have partnered with StarkWare to build a bridge component as seen on https://starkgate.starknet.io/. We aim to create a smooth login experience for end users. We use
get-starknet-core
to connect users' starknet wallet, whether it's Braavos or ArgentX.Problem
There are two scenarios that could have improved UX, and they both begin at a state where the user has already connected a starknet wallet:
Additionally, when dealing with wallets in a locked state, we want to avoid uninitiated wallet popups – meaning, there should not be any wallet popups without the user explicitly clicking on a connect button.
The starknet window object (accessed via
get-starknet-core
) has a lot of useful properties and methods likeisConnected
andisPreauthorized
, however these cannot be used for accurately detecting wallet locked state while avoiding popups. The main reason for this is thatisConnected
is always false untilenable
is called. However, whenenable
is called, it will prompt the user to unlock the wallet if it's locked, so we have a chicken-and-egg problem.Proposed solution
There are two parts, each addressing the problems above, respectively:
accountsChanged
event withundefined
account address when the wallet is lockedenable
that states the dapp doesn't want to show a popup/UI in case the wallet is locked and/or not preauthorizedAlternate solution
disconnect
event when the wallet is lockedisLocked
(orisUnlocked
, whichever is preferred) value that represents the current locked status of the wallet, whether or notenable
has been called.Disconnect event When the user explicitly locks their wallet, the wallet should emit a
disconnect
event that can be handled via theon
method, similar toaccountsChanged
andnetworkChanged
. This will solve the first UX scenario because in ourdisconnect
event handler, we can disconnect the wallet from our app state.isLocked There should be a boolean value isLocked accessible via
get-starknet-core
similar toisConnected
that is:true
when the wallet is lockedfalse
when the wallet is lockedAdditionally, this boolean should have a value before calling enable – it should not be necessary to call enable for this property to have the correct value. This will solve the second UX scenario because our SDK can read this value and determine if it needs to remove the wallet from its connected state. For a reproduction of the UX problem we aim to solve, see: https://codesandbox.io/s/purple-glade-l3llkm?file=/src/App.js. The problem is with the automatic popup – since we have to call
enable
first to check ifisConnected
is true, there is a wallet connection popup on page load. If we were able to checkisLocked
, then we would know to simply "disconnect" the user (reset their connection state in our app), and then show them the connect button again.