Created
September 18, 2020 10:01
Star
You must be signed in to star a gist
XUMM SDK - Subscription - Await based on resolving without using a callback function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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