types#ChainEventNotification TypeScript Examples

The following examples show how to use types#ChainEventNotification. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: chainEventsNs.ts    From commonwealth with GNU General Public License v3.0 6 votes vote down vote up
public async init() {
    this.ceNs = io(`/${WebsocketNamespaces.ChainEvents}`, {
      transports: ['websocket'],
    });
    this.ceNs.on('connect', this.onConnect.bind(this));
    this.ceNs.on('disconnect', this.onDisconnect.bind(this));
    this.ceNs.on(
        WebsocketMessageNames.ChainEventNotification,
        this.onChainEvent.bind(this)
    );
  }
Example #2
Source File: chainEventsNs.ts    From commonwealth with GNU General Public License v3.0 6 votes vote down vote up
private onChainEvent(notification: ChainEventNotification) {
    const subscription = app.user.notifications.subscriptions.find(
      (sub) => sub.ChainEventType?.id === notification.ChainEvent.ChainEventType.id
    );
    if (!subscription) {
      // will theoretically never happen as subscriptions are added/removed on Socket.io as they happen locally
      console.log("Local subscription not found. Re-sync subscriptions!");
      return;
    }
    const notificationObj = Notification.fromJSON(notification, subscription);
    app.user.notifications.update(notificationObj);
  }