diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index 35a2debf..c7b520f6 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -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 */