Documentation / @cashconnect-js/dapp / dapp-console
CashConnectDappConsole
Defined in: cashconnect-js/packages/dapp/src/dapp-console.ts:59
Extends
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends Template | Template |
Constructors
Constructor
new CashConnectDappConsole<T>(
template,
chain,
opts,
allowedTokens): CashConnectDappConsole<T>;Defined in: cashconnect-js/packages/dapp/src/dapp-console.ts:83
Parameters
| Parameter | Type | Default value |
|---|---|---|
template | T | undefined |
chain | string | 'bch:bchtest' |
opts | Partial<SignClientTypes.Options> | {} |
allowedTokens | string[] | [] |
Returns
Overrides
Methods
from()
static from<T>(
template,
chain,
opts,
allowedTokens): Promise<CashConnectDappConsole<T>>;Defined in: cashconnect-js/packages/dapp/src/dapp-console.ts:62
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends object | object |
Parameters
| Parameter | Type | Default value |
|---|---|---|
template | T | undefined |
chain | string | 'bch:bchtest' |
opts | Partial<SignClientTypes.Options> | {} |
allowedTokens | string[] | [] |
Returns
Promise<CashConnectDappConsole<T>>
start()
start(): Promise<void>;Defined in: cashconnect-js/packages/dapp/src/dapp.ts:130
Returns
Promise<void>
Inherited from
connect()
connect(): Promise<boolean>;Defined in: cashconnect-js/packages/dapp/src/dapp.ts:141
Returns
Promise<boolean>
Inherited from
newSession()
newSession(): Promise<"CONNECTED" | "CANCELLED">;Defined in: cashconnect-js/packages/dapp/src/dapp.ts:177
Returns
Promise<"CONNECTED" | "CANCELLED">
Inherited from
reconnectSession()
reconnectSession(silent): Promise<"CONNECTED" | "CANCELLED" | "NEW_SESSION">;Defined in: cashconnect-js/packages/dapp/src/dapp.ts:264
Parameters
| Parameter | Type | Default value |
|---|---|---|
silent | boolean | false |
Returns
Promise<"CONNECTED" | "CANCELLED" | "NEW_SESSION">
Inherited from
CashConnectDapp.reconnectSession
disconnect()
disconnect(): Promise<void>;Defined in: cashconnect-js/packages/dapp/src/dapp.ts:347
Returns
Promise<void>
Inherited from
executeAction()
executeAction<A>(
actionName,
params,
opts): Promise<ActionResult<T, A>>;Defined in: cashconnect-js/packages/dapp/src/dapp.ts:374
Type Parameters
| Type Parameter |
|---|
A extends string |
Parameters
| Parameter | Type |
|---|---|
actionName | A |
params | { [K in string | number | symbol]: ({ [K in string | number | symbol as T["actions"][A]["params"][K] extends { required: false } ? never : K]: ProcessVariable<T["actions"][A]["params"][K]> } & { [K in string | number | symbol as T["actions"][A]["params"][K] extends { required: false } ? K : never]?: ProcessVariable<T["actions"][A]["params"][K]> })[K] } |
opts | RequestOpts |
Returns
Promise<ActionResult<T, A>>
Inherited from
getBalances()
getBalances(): Promise<any>;Defined in: cashconnect-js/packages/dapp/src/dapp.ts:438
Returns
Promise<any>
Inherited from
getTokens()
getTokens(): Promise<any>;Defined in: cashconnect-js/packages/dapp/src/dapp.ts:459
Returns
Promise<any>
Inherited from
disconnectInactiveSessions()
disconnectInactiveSessions(): Promise<void>;Defined in: cashconnect-js/packages/dapp/src/dapp.ts:480
Returns
Promise<void>
Inherited from
CashConnectDapp.disconnectInactiveSessions
onSessionDisconnect()
onSessionDisconnect(): Promise<void>;Defined in: cashconnect-js/packages/dapp/src/dapp.ts:501
Returns
Promise<void>
Inherited from
CashConnectDapp.onSessionDisconnect
onSessionUpdate()
onSessionUpdate(): Promise<void>;Defined in: cashconnect-js/packages/dapp/src/dapp.ts:505
Returns
Promise<void>
Inherited from
CashConnectDapp.onSessionUpdate
onSessionEvent()
onSessionEvent(event): Promise<void>;Defined in: cashconnect-js/packages/dapp/src/dapp.ts:509
Parameters
| Parameter | Type |
|---|---|
event | BaseEventArgs<{ event: { name: string; data: any; }; chainId: string; }> |
Returns
Promise<void>
Inherited from
CashConnectDapp.onSessionEvent
on()
on<K>(
type,
listener,
debounceMilliseconds?): OffCallback;Defined in: cashconnect-js/packages/core/dist/primitives.d.ts:593
Registers a listener for the specified event type.
Type Parameters
| Type Parameter | Description |
|---|---|
K extends keyof CashConnectDappEvents | The event type key |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | The event type to listen for |
listener | Listener<CashConnectDappEvents[K]> | The function to call when the event is emitted |
debounceMilliseconds? | number | Optional debounce time in milliseconds |
Returns
OffCallback
A callback function that can be used to unregister this listener
Example
const off = emitter.on('data-change', (data) => {
console.log('Data updated:', data);
}, 300); // Debounce for 300ms
// Later, unregister the listener
off();Inherited from
once()
once<K>(
type,
listener,
debounceMilliseconds?): OffCallback;Defined in: cashconnect-js/packages/core/dist/primitives.d.ts:611
Registers a one-time listener for the specified event type. The listener will be automatically removed after being called once.
Type Parameters
| Type Parameter | Description |
|---|---|
K extends keyof CashConnectDappEvents | The event type key |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | The event type to listen for |
listener | Listener<CashConnectDappEvents[K]> | The function to call when the event is emitted |
debounceMilliseconds? | number | Optional debounce time in milliseconds |
Returns
OffCallback
A callback function that can be used to unregister this listener before it fires
Example
emitter.once('user-login', ({ userId }) => {
console.log(`Welcome ${userId}! This will only show once.`);
});Inherited from
off()
off<K>(type, listener): void;Defined in: cashconnect-js/packages/core/dist/primitives.d.ts:626
Removes a specific listener for the given event type.
Type Parameters
| Type Parameter | Description |
|---|---|
K extends keyof CashConnectDappEvents | The event type key |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | The event type to remove the listener from |
listener | Listener<CashConnectDappEvents[K]> | The listener function to remove |
Returns
void
Example
const handler = (data) => console.log(data);
emitter.on('test', handler);
emitter.off('test', handler); // Removes the listenerInherited from
emit()
emit<K>(type, payload): boolean;Defined in: cashconnect-js/packages/core/dist/primitives.d.ts:648
Emits an event of the specified type with the given payload. All registered listeners for this event type will be called.
Type Parameters
| Type Parameter | Description |
|---|---|
K extends keyof CashConnectDappEvents | The event type key |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | The event type to emit |
payload | CashConnectDappEvents[K] | The data to pass to all listeners |
Returns
boolean
true if there were listeners for this event, false otherwise
Example
const hasListeners = emitter.emit('user-login', {
userId: '123',
timestamp: Date.now()
});
if (!hasListeners) {
console.log('No one was listening for user-login events');
}Inherited from
removeAllListeners()
removeAllListeners(): void;Defined in: cashconnect-js/packages/core/dist/primitives.d.ts:659
Removes all listeners for all events. This effectively resets the EventEmitter to its initial state.
Returns
void
Example
emitter.removeAllListeners();
// All previously registered listeners are now goneInherited from
CashConnectDapp.removeAllListeners
waitFor()
waitFor<K>(
type,
predicate,
timeoutMs?): Promise<CashConnectDappEvents[K]>;Defined in: cashconnect-js/packages/core/dist/primitives.d.ts:685
Returns a Promise that resolves when an event of the specified type is emitted and matches the given predicate.
Type Parameters
| Type Parameter | Description |
|---|---|
K extends keyof CashConnectDappEvents | The event type key |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | The event type to wait for |
predicate | (payload) => boolean | A function that determines if the event payload matches what we're waiting for |
timeoutMs? | number | Optional timeout in milliseconds. If specified, the promise will reject after this time |
Returns
Promise<CashConnectDappEvents[K]>
A Promise that resolves with the event payload when the condition is met
Throws
If the timeout is reached before a matching event occurs
Example
try {
const loginData = await emitter.waitFor(
'user-login',
({ userId }) => userId === 'admin',
5000 // Wait up to 5 seconds
);
console.log('Admin logged in:', loginData);
} catch (error) {
console.log('Timeout: Admin never logged in');
}Inherited from
Properties
| Property | Modifier | Type | Default value | Inherited from | Defined in |
|---|---|---|---|---|---|
template | readonly | T | undefined | CashConnectDapp.template | cashconnect-js/packages/dapp/src/dapp-console.ts:84 |
chain | readonly | string | 'bch:bchtest' | CashConnectDapp.chain | cashconnect-js/packages/dapp/src/dapp-console.ts:85 |
opts | readonly | Partial<SignClientTypes.Options> | {} | - | cashconnect-js/packages/dapp/src/dapp-console.ts:86 |
allowedTokens | readonly | string[] | [] | CashConnectDapp.allowedTokens | cashconnect-js/packages/dapp/src/dapp-console.ts:87 |
client | public | SignClient | undefined | CashConnectDapp.client | cashconnect-js/packages/dapp/src/dapp.ts:114 |
session? | public | Struct | undefined | CashConnectDapp.session | cashconnect-js/packages/dapp/src/dapp.ts:115 |
onConnected? | public | (session) => Promise<void> | undefined | CashConnectDapp.onConnected | cashconnect-js/packages/dapp/src/dapp.ts:118 |
options | readonly | Options | undefined | CashConnectDapp.options | cashconnect-js/packages/dapp/src/dapp.ts:121 |
dialogs | readonly | DappDialogs | undefined | CashConnectDapp.dialogs | cashconnect-js/packages/dapp/src/dapp.ts:125 |