Skip to content

Listening To Events ​

The SDK emits typed events for its background work — balance scans, plan execution, session health, and account changes. Subscribe with on. The listener receives { name, data }, and on returns an unsubscribe function:

ts
import { CURVY_EVENT_TYPES } from "@0xcurvy/curvy-sdk";
import { on } from "@0xcurvy/curvy-sdk/actions";

const unsubscribe = on(CURVY_EVENT_TYPES.BALANCE_REFRESH_PROGRESS, ({ data }) => {
  console.log(`Scanning... ${data.progress}%`);
});

// later:
unsubscribe();

data is narrowed to the payload type of the event you subscribe to.

For abort-driven cleanup — handy in React effects — pass an AbortSignal instead of keeping the unsubscribe function around:

ts
const controller = new AbortController();
on(CURVY_EVENT_TYPES.BALANCE_REFRESH_COMPLETE, onComplete, { signal: controller.signal });

// removes the listener automatically:
controller.abort();

The unsubscribe function is also Disposable, so using removes the listener when the enclosing block ends:

ts
async function shieldWithProgress() {
  using _progress = on(CURVY_EVENT_TYPES.PLAN_EXECUTION_PROGRESS, ({ data }) => render(data));
  await executeIntent(intent);
} // the listener is removed here, also when executeIntent throws

Available events ​

GroupEvents
Balance refreshBALANCE_REFRESH_STARTED, BALANCE_REFRESH_PROGRESS, BALANCE_REFRESH_COMPLETE, BALANCE_REFRESH_CANCELLED, BALANCE_REFRESH_ERROR
Plan executionPLAN_EXECUTION_STARTED, PLAN_EXECUTION_PROGRESS, PLAN_EXECUTION_COMPLETE, PLAN_EXECUTION_ERROR
SessionJWT_REFRESH_SUCCESS, JWT_REFRESH_ERROR, UNAUTHORIZED
AccountsACCOUNT_ADDED, ACCOUNT_REMOVED, ACCOUNT_CHANGED