Skip to content

Instantly share code, notes, and snippets.

@WietseWind
Created September 18, 2020 10:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save WietseWind/76890afd39a01e9876c8a629b3e58174 to your computer and use it in GitHub Desktop.
XUMM SDK - Subscription - Await based on resolving without using a callback function
import {XummSdk} from 'xumm-sdk'
import type WebSocket from 'ws'
const Sdk = new XummSdk()
const main = async () => {
const payloadByUuid = '1289e9ae-7d5d-4d5f-b89c-18633112ce09'
const subscription = await Sdk.payload.subscribe(payloadByUuid)
subscription.websocket.onmessage = (message: WebSocket.MessageEvent) => {
if (message.data.toString().match(/signed/)) {
subscription.resolve()
}
}
await subscription.resolved
console.log(`Payload ${subscription.payload.meta.uuid} resolved`)
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment