In a SSA Plugin function running Node.js
In my function, I am generating a QR code. The user then scans the QR code with a mobile wallet app. There is a subscribe function that waits for that connection and then calls an API.
The subscribe is not waiting. This works in regular Node.js locally - any thoughts on how to make it work?
This is the code. I get the QR code returned just fine - the subscribe is what doesn’t happen.
function(properties, context) {
const { Client, UserAccount } = require("@xact-wallet-sdk/client");
const axios = require('axios')
// set keys
const apiKey = context.keys['XACTKEY'];
let err
let response = context.async(async callback => {
try {
/* Create a new instance of Client */
const client = new Client({apiKey});
/* Init the connection */
await client.initConnexion();
/* Generate a QR Code */
qrCode = await client.generateQRCode();
// data to be sent to the POST request
await axios.post('https://hedera.dpub.xyz/version-test/api/1.1/wf/create-account-id',{accountid: 'TEST ACCOUNT ID outside', qrcode: qrCode})
/* Subscribe to new Connections */
client.connect().subscribe(userconnection => {
axios.post('https://hedera.dpub.xyz/version-test/api/1.1/wf/create-account-id',{accountid: 'INSIDE ACCT: ' + userconnection.toString()})
});
callback(null, qrCode)
} catch {
callback(err);
}
})
return {"returned-qrcode" : response}
}
I get the QR code just fine - show it on screen - scan with the app, but subscribe is probably not waiting…