From 4947a4dbb6db6ad65cb3a91c1f28571b80e7c36a Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Mon, 13 Jan 2020 16:26:00 -0400 Subject: [PATCH] wire sendpayment to socket --- services/gunDB/Mediator/index.js | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) 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 */