Events

The CSPR.click library emits several events you may need to handle to update your app accordingly.

Listen to these events calling the on() method with a callback handler. For example:

csprclick.on('csprclick:signed_in', async (evt) => {
  //update your app content for the new session
  console.log("Connected account: " + evt.account.public_key)
});

csprclick:loaded

This event is emitted when the CSPR.click library initialization is complete. Usually, you shouldn’t call any method in the library (apart from init()) before this event occurs.

Use once() to bind the callback handler instead of on() for this event since it’s triggered only once.

csprclick:signed_in

This event is emitted when the CSPR.click library connects to a new account. Previously, either csprclick.connect() or csprclick.signInWithAccount() methods must have been called by the application.

Receives an AccountType object with data about the newly connected account.

csprclick:switched_account

This event is emitted when CSPR.click library switches connection from one account to another after the application has called csprclick.switchAccount() method.

Receives an AccountType object with data about the newly connected account.

csprclick:unsolicited_account_change

This event is emitted when there's an account connected to the application and the user changes the active account in his wallet, but the application hasn't requested the change calling connect() or switchAccount() methods.

When CSPR.click UI SDK is being used, the application shows a pop up notice where the user can confirm if he wants to switch the current session to the new account or keep the current one.

If you're not using CSPR.click UI SDK, your application should define a handler for this event and confirm the account change by calling signInWithAccount() method. For example:

csprclick.on('csprclick:unsolicited_account_change', async (evt) => {
  window.csprclick.signInWithAccount(evt.account);
});

When the new account is connected, the SDK will emit the event csprclick:signed_in.

csprclick:signed_out

This event is emitted when the CSPR.click library disconnects the active account due to a call to the signOut() SDK method.

csprclick:disconnected

This event is emitted when CSPR.click library receives a disconnect request or event from the connected wallet. The app should close the current session as a consequence of this event.

Receives the provider that has been disconnected.

csprclick:sign_in

Indicates that the signIn() method has been called. In your app, you should typically respond to these event showing the sign-in options to the user (e.g. list of wallets, list of known accounts, etc.).

Last updated