Skip to content

Commit

Permalink
CIP30: Events API
Browse files Browse the repository at this point in the history
The events API was removed from CIP-30 before merging with the plan to
add it in a later revision. This commit simply contains the scaffolding
that was removed prior to merging cardano-foundation#88 so we can start the discussion
again.
  • Loading branch information
rooooooooob committed Nov 19, 2021
1 parent d5842cc commit a63ba37
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions CIP-0030/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ APIErrorCode {
InvalidRequest: -1,
InternalError: -2,
Refused: -3,
AccountChange: -4,
}
APIError {
code: APIErrorCode,
Expand All @@ -84,7 +83,6 @@ APIError {
* InvalidRequest - Inputs do not conform to this spec or are otherwise invalid.
* InternalError - An error occurred during execution of this API call.
* Refused - The request was refused due to lack of access - e.g. wallet disconnects.
* AccountChange - The account has changed. The dApp should call `wallet.enable()` to reestablish connection to the new account. The wallet should not ask for confirmation as the user was the one who initiated the account change in the first place.

### DataSignError

Expand Down Expand Up @@ -247,6 +245,30 @@ Errors: `APIError`, `TxSendError`

As wallets should already have this ability, we allow dApps to request that a transaction be sent through it. If the wallet accepts the transaction and tries to send it, it shall return the transaction id for the dApp to track. The wallet is free to return the `TxSendError` with code `Refused` if they do not wish to send it, or `Failure` if there was an error in sending it (e.g. preliminary checks failed on signatures).



## Events

In addition to the API methods that are actively called, the connector also must emit the following events. All methods events are required to be implemented.

TODO: event emission method? Possible methods:

1) Emitted event via `window.addEventListener(eventName , e => void)`
2) Emitted message via `window.postMessage({eventName: string}, ...)`
3) Some kind of callback registration i.e. `wallet.onDisconnect(() => void)` or `wallet.onEvent(eventName => void)`
4) A combination of the two (event/message but with callback on `wallet` object as well
5) Other?

### wallet_disconnected

Emitted when the user disconnects (not just changes) their current account from the page. This means that all `api` methods will return with an `APIError.Refused` error and a new `api` object must be obtained from `wallet.enable()` to continue to interact with the user's wallet.

### account_changed

Emitted when the user changes accounts (i.e. different root key pair and/or network id). The same `api` object will continue to work but will now return results based on the new account. After this event is received dApps should check `api.getNetworkId()` as changing accounts can also change the network.



# Implementations

[nami-wallet](https://github.com/Berry-Pool/nami-wallet/blob/master/src/pages/Content/injected.js)

0 comments on commit a63ba37

Please sign in to comment.