Created
October 20, 2020 08:26
-
-
Save WietseWind/7f04966c444909649ca43332671fc6d5 to your computer and use it in GitHub Desktop.
Sign request push notification
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
const {XummSdk} = require('xumm-sdk') | |
const Sdk = new XummSdk('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', '...') | |
const main = async () => { | |
const appInfo = await Sdk.ping() | |
console.log(appInfo.application.name) | |
const request = { | |
"txjson": { | |
"TransactionType": "Payment", | |
"Destination": "rwietsevLFg8XSmG3bEZzFein1g8RBqWDZ", | |
"Amount": "10000" | |
}, | |
"user_token": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | |
} | |
const subscription = await Sdk.payload.createAndSubscribe(request, event => { | |
console.log('New payload event:', event.data) | |
// The event data contains a property 'signed' (true or false), return :) | |
if (Object.keys(event.data).indexOf('signed') > -1) { | |
return event.data | |
} | |
}) | |
console.log('New payload created, URL:', subscription.created.next.always) | |
console.log(' > Pushed:', subscription.created.pushed ? 'yes' : 'no') | |
const resolveData = await subscription.resolved | |
if (resolveData.signed === false) { | |
console.log('The sign request was rejected :(') | |
} else { | |
console.log('Woohoo! The sign request was signed :)') | |
/** | |
* Let's fetch the full payload end result and check for | |
* a transaction hash, to verify the transaction on ledger later. | |
*/ | |
const result = await Sdk.payload.get(resolveData.payload_uuidv4) | |
console.log('On ledger TX hash:', result.response.txid) | |
} | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment