on
Subscribe to a Curvy event. Delegates to config.emitter.on and returns Emittery's identity-based unsubscribe function.
eventName and listener stay positional (Emittery's natural shape); the trailing options bag carries config and an optional signal for abort-driven auto-cleanup (passed straight through to Emittery).
The generic over the event name narrows eventData to that event's payload (e.g. BALANCE_REFRESH_PROGRESS → { progress, environment? }), mirroring the underlying typed emitter.
Import
import { on } from "@0xcurvy/curvy-sdk/actions";Usage
Example 1
const unsubscribe = on(CURVY_EVENT_TYPES.BALANCE_REFRESH_COMPLETE, (e) => {});
// later: unsubscribe();Example 2
// Auto-cleanup via AbortSignal — no manual off():
on(CURVY_EVENT_TYPES.BALANCE_REFRESH_COMPLETE, (e) => {}, { signal: controller.signal });Signature
function on<Name extends keyof CURVY_EVENTS>(eventName: Name, listener: (eventData: CURVY_EVENTS[Name]) => void | Promise<void>, options?: OnOptions): UnsubscribeReturns
UnsubscribeFunction
The action resolves or returns the value shown in the signature.
Parameters
eventName
- Type:
Name - Required: yes
The Curvy event to subscribe to.
const result = on(
eventName,
listener,
);listener
- Type:
(eventData: CURVY_EVENTS[Name]) => void | Promise<void> - Required: yes
The callback invoked when the event is emitted.
const result = on(
eventName,
listener,
);options
- Type:
OnOptions - Required: no
- Default:
{}
Optional subscription configuration and lifecycle controls.
const result = on(
eventName,
listener,
{
},
);options.config
- Type:
CurvyConfig - Required: no
Override the ambient global config.
const result = on(
eventName,
listener,
{
config,
},
);options.signal
- Type:
AbortSignal - Required: no
Bind the subscription's lifetime to an AbortSignal: when it aborts, the listener is removed automatically — no explicit off() needed. Handled natively by Emittery (it also detaches the abort handler if you unsubscribe manually first, and no-ops when the signal is already aborted).
const result = on(
eventName,
listener,
{
signal,
},
);Errors
Errors from config resolution and the underlying SDK operation are propagated to the caller.
Related
- Listening to events guide
off— Unsubscribe a previously-registered listener.