useAccount
Create account
Orderly Key
Creates an OrderlyKey
. The validity of the OrderlyKey
(in days) can be set.
After the OrderlyKey
is successfully created, it will be stored in the KeyStore
, and will be used for API signatures later on.
KeyStore
The KeyStore
instance is responsible for storing the Orderly private key, which is used for trading.
By default the key will be stored in local Storage, but a custom KeyStore
implementation can be given to OrderlyConfigProvider
like explained here.
Account status
The Account
object has the following statuses:
The above statuses are represented as follows:
NotConnected
/Connected
- Wallet connection status, not related to Orderly.NotConnected
means no wallet connected,Connected
means the wallet app is connected and we know the user’s wallet address.NotSignedIn
/SignedIn
- The result from callingGet Account Information
orRegister Account
.NotSignedIn
means there’s no registered account associated with the wallet address andbrokerId
pair.SignedIn
means that an account has been previously registered with the wallet address andbrokerId
pair.DisabledTrading
/EnableTrading
- The result from callingGet Orderly Key
orAdd Orderly Key
.DisabledTrading
means no active Orderly Key is found in theKeyStore
.EnableTrading
means an active Orderly Key is found in theKeyStore
and can be used to authenticate for any private API requests.
Get account status
There are two ways to get the account status. You can get it either directly from useAccount
’s value, or through subscribing to the account status change event:
- Retrieve from the
state
value inuseAccount
:
state
also contains the following account info, as shown below:
- Subscribe to the
change:status
event in theAccount
instance. (account
is a singleton of theAccount
instance)。
Update account status
@orderly.network/hooks
currently does not provide the functionality for connecting wallets, builders have to handle wallet connection logic themselves, refer here.
Once the user has successfully connected a wallet, use the setAddress
method to pass the address
to the Account
instance. 3 additional parameters need to be passed when calling setAddress
:
provider
- provider according to theEIP1193Provider
standardchain
- information regarding the connected chain, including theid
wallet
- wallet information, including the name of the wallet app
The setAddress
method in Account
will check the accound_id
and the existence of any valid OrderlyKey
from the provided address
and update the state
. If the state
is AccountStatusEnum.EnableTrading
, then the full login process in complete and the user can then access all functionalities provided by Orderly.