on(xAppEvent, fn) Certain events are sent to xApps. These events are usually an asynchronous callback containing data requested by calling one of the xApp UI actions.
To subscribe to one of the events emitted to xApps, use the on(...)
method on the SDK's xapp
object to register an event handler (callback function).
Payload
The payload
event is emitted when a payload has been resolved (signed / declined)
Example Response: signed Response: declined
Copy // <script src="https://xumm.app/assets/cdn/xumm.min.js"></script>
var xumm = new Xumm ( 'your-api-key' )
xumm . xapp .on ( 'payload' , data => {
console .log ( 'Payload resolved' , data)
})
Copy {
"reason" : "SIGNED" ,
"uuid" : "the-payload-uuid"
}
Copy {
"reason" : "DECLINED" ,
"uuid" : "the-payload-uuid"
}
QR
The qr
event is emitted when the QR scanner dialog has been opened, and is now closed. If a QR was scanned the data is returned.
Example Response: scanned Response: cancelled Response: invalid
Copy // <script src="https://xumm.app/assets/cdn/xumm.min.js"></script>
var xumm = new Xumm ( 'your-api-key' )
xumm . xapp .on ( 'qr' , data => {
console .log ( 'QR scanned (?)' , data)
})
Copy {
"qrContents" : "the://scanned-qr/contents?..." ,
"reason" : "SCANNED"
}
Copy {
"qrContents" : null ,
"reason" : "USER_CLOSE"
}
Copy {
"qrContents" : null ,
"reason" : "INVALID_QR"
}
Destination
The destination
event is emitted when the destination picker dialog has been openend, and is now closed. If a destinationw as selected, the data is returned.
Example Response: selected Response: cancelled
Copy // <script src="https://xumm.app/assets/cdn/xumm.min.js"></script>
var xumm = new Xumm ( 'your-api-key' )
xumm . xapp .on ( 'destination' , data => {
console .log ( 'Destination account picked (?)' , data)
})
Copy {
"method" : "selectDestination" ,
"destination" : {
"address" : "r..." ,
"tag" : 123456 ,
"name" : "Wietse's Savings"
} ,
"info" : {
"blackHole" : false ,
"disallowIncomingXRP" : false ,
"exist" : true ,
"possibleExchange" : false ,
"requireDestinationTag" : false ,
"risk" : "UNKNOWN"
} ,
"reason" : "SELECTED"
}
Copy {
"reason" : "USER_CLOSE"
}
Network Switch
The user switched the selected network in Xumm while present in the xApp, while your xApp settings (Xumm Developer Console) indicate the xApp shouldn't reload but receive an event.
The event will contain a property network
with a key referring to a network from the rails
endpoint, through getRails() or https://xumm.app/api/v1/jwt/rails
Copy // <script src="https://xumm.app/assets/cdn/xumm.min.js"></script>
var xumm = new Xumm ( 'your-api-key' )
xumm . xapp .on ( "networkswitch" , ({ network }) => {
xumm . helpers .getRails () .then (rails => {
alert ( JSON .stringify (rails?.[network]))
})
})
Last updated 11 months ago