-
Notifications
You must be signed in to change notification settings - Fork 32
Description
This is going to require some work with the full set of wallets y'all interface with, but it solves a BIG problem.
Today, SWK is extremely hard to use (at least, with standard app building patterns) because getAddress is overloaded. It currently does three, maybe four, things:
- Checks if the user has opened the wallet and given it permission to access the current app. Freighter has two methods for this same behavior, and both are useful:
- It OPENS THE WALLET EXTENSION'S "CONNECT" MODAL!! I'm going to shout about this some more because it is SO unexpected and leads to horrible twisty app logic. In general, a getter method should NEVER HAVE SIDE EFFECTS. If something has a name that indicates that it's doing a simple data look-up, it should not also do something as obnoxious or user-effecting as opening a modal.
- In Freighter, this is done with requestAccess, an action-verb name that gives the developer a hint at its repercussions.
- It actually gets the currently-selected address from the connected wallet
Since SWK currently provides no way to do this, apps today need to implement some impoverished version of 1 above using localStorage. In Scaffold Stellar today, we use localStorage. There's all sorts of side effects we need to code around, or simply can't or shouldn't code around:
- Our
onWalletSelectedlogic only setslocalStorageafter a successful subsequent call togetAddress, because without that our polling logic starts requestinggetAddressand opening duplicate "connect" modals. - If the user connects on Day 1, the localStorage will still be set on Day 2, which will cause
getAddressto be called at page load, opening the "connect" modal. Perhaps the only way around this is to reverse-engineer specific wallet extensions' session expiration logic, and implement more app-side logic to expire thislocalStorage. This is error-prone and bloated. - Rather than straightforwardly asking the wallet extension itself if the user
isConnectedand if the extensionisAllowedto access the page, we need to check if our localStorage item is set. As noted, this is not the same thing, and leads to hard-to-maintain code and janky user experiences.
I suggest following Freighter's lead here, adding isConnected, isAllowed, and requestAccess.
I realize that I am suggesting interface methods beyond what is specified by SEP-43. To me, the challenge of using bare-minimum, current-day SEP-43 indicates to me that it is too limited, and we need to update it. SWK ought to be the most powerful voice in this process.