wire sendpayment to socket

This commit is contained in:
Daniel Lugo 2020-01-13 16:26:00 -04:00
parent 9a10bf324f
commit 4947a4dbb6

View file

@ -296,6 +296,7 @@ class Mediator {
this.sendHRWithInitialMsg
)
socket.on(Action.SEND_MESSAGE, this.sendMessage)
socket.on(Action.SEND_PAYMENT, this.sendPayment)
socket.on(Action.SET_AVATAR, this.setAvatar)
socket.on(Action.SET_DISPLAY_NAME, this.setDisplayName)
@ -563,6 +564,39 @@ class Mediator {
}
}
/**
* @param {Readonly<{ uuid: string, recipientPub: string, amount: number, memo: string, token: string }>} reqBody
*/
sendPayment = async reqBody => {
try {
const { recipientPub, amount, memo, token } = reqBody
await throwOnInvalidToken(token)
await API.Actions.sendPayment(
recipientPub,
amount,
memo,
gun,
user,
mySEA
)
this.socket.emit(Action.SEND_PAYMENT, {
ok: true,
msg: null,
origBody: reqBody
})
} catch (err) {
console.log(err)
this.socket.emit(Action.SEND_PAYMENT, {
ok: false,
msg: err.message,
origBody: reqBody
})
}
}
/**
* @param {Readonly<{ avatar: string|null , token: string }>} body
*/