-
Notifications
You must be signed in to change notification settings - Fork 241
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
API changes #28
Comments
Overall I really like this! This really makes the API leaner and overall simpler to use, especially due to the
What's the difference between Another thing is that when I read reset, I imagined a function that both disconnected and connected me back to the wallet with just pressing a button. Maybe we can choose another name for this, or, further clarify what this does compared to Just my two gwei! Let me know what you think :) I really like the new API proposal. |
@Evalir Excellent point! I thought of it this way:
Now, I think you are absolutely right: the role of these two is not obvious, and they could be combined into a single function since disconnecting implies clearing the error and vice versa. Let’s do this! We could go for the name So I think we could go for |
Hmmm, In retrospect, It might be good to have both |
haha interesting 😄 I still think we could try to have them as a single function rather than two, because they both will probably start by calling the other anyway. What made you change your mind? About In the case of We could also think of alternatives to express that the entire state is going to be set to its default (I’m trying to avoid using the word “reset” here 😆). |
Haha! It's not that I changed my mind much, it's just that maybe we can make those two functions coexist, but we may need a better name for reset (naming is hard!). Regarding |
Really nice changes, and agree this will make the API much smoother to use! With
I agree with this; I presume this would also clear any localstorage cache about the last connected wallet / etc (which is also what we would want to do on disconnect anyway).
A bit of bikeshedding on the error naming (assuming we get to choose these names):
|
Issues with the current API
activate()
and store the error in the state so that users can be presented a connection error message. This is verbose and takes us farther from the goal of keeping the boilerplate code as minimal as possibleuseWallet()
.activating
,activated
andconnected
, requires consumers of the library to test several variables to know the current state and the connector identifier.Proposed changes
The goal of these changes is generally to:
useWallet()
.connect()
anddisconnect()
connect(id)
anddisconnect()
would replaceactivate(id)
anddeactivate()
. This is to remove any reference to the term “activation” and increase consistency.status
status
would be a new exported value that would contain the current status of the wallet connection. It would have take one of these values at any given time:"disconnected"
: no wallet connected (default state)."connecting"
: trying to connect to the wallet."connected"
: connected to the wallet (i.e. the account is available)."error"
: a connection error happened.These are strings and not symbols so that users don’t have to import many symbols.
These values would get deprecated:
activated
,activating
andconnected
.Having a status
connected
guarantees thataccount
is notnull
.error
andreset()
error
is a new value that contains the error object that comes with an"error"
status.There are different types of errors exported by module:
UnsupportedChainError
UnsupportedConnectorError
RejectedActivationError
ConnectorConfigError
error
would benull
when the status is noterror
, otherwise it would get populated by the corresponding error instance.Users would have the possibility to import the error constructors and use
instanceof
, or to use thename
property.The
message
property can also be used to display the current error.Calling
reset()
will makestatus
go back todisconnected
, anderror
back tonull
. Callingconnect()
would also clear the error state before initiating the new connection.@Evalir @sohkai Let me know what you guys think!
The text was updated successfully, but these errors were encountered: