diff --git a/services/gunDB/contact-api/actions.js b/services/gunDB/contact-api/actions.js index 39831095..ec8c66fe 100644 --- a/services/gunDB/contact-api/actions.js +++ b/services/gunDB/contact-api/actions.js @@ -1090,12 +1090,16 @@ const sendSpontaneousPayment = async ( const { num_satoshis: decodedAmt } = await decodePayReq(encodedInvoice) if (decodedAmt !== amount.toString()) { - throw new Error('Invoice amount mismatch') + throw new Error( + `Invoice amount mismatch got: ${decodedAmt} expected: ${amount.toString()}` + ) } // double check if (Number(decodedAmt) !== amount) { - throw new Error('Invoice amount mismatch') + throw new Error( + `Invoice amount mismatch got:${decodedAmt} expected:${amount.toString()}` + ) } logger.info('Will now send payment through lightning') diff --git a/services/gunDB/contact-api/jobs/onOrders.js b/services/gunDB/contact-api/jobs/onOrders.js index 23bfbf0a..34e80a25 100644 --- a/services/gunDB/contact-api/jobs/onOrders.js +++ b/services/gunDB/contact-api/jobs/onOrders.js @@ -18,6 +18,8 @@ const Utils = require('../utils') const Gun = require('gun') const { selfContentToken, enrollContentTokens } = require('../../../seed') +const TipForwarder = require('../../../tipsCallback') + const getUser = () => require('../../Mediator').getUser() /** @@ -278,6 +280,13 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => { .get('postToTipCount') .get(postID) .set(null) // each item in the set is a tip + + TipForwarder.notifySocketIfAny( + postID, + order.from, + 'TIPPED YOU', + amt + ' sats' + ) break } case 'spontaneousPayment': { diff --git a/services/tipsCallback.js b/services/tipsCallback.js new file mode 100644 index 00000000..fca084a7 --- /dev/null +++ b/services/tipsCallback.js @@ -0,0 +1,30 @@ +//@ts-nocheck TODO- fix types +class TipsCB { + listeners = {} + + addSocket(postID,socket){ + console.log("subbing new socket for post: "+postID) + + if(!this.listeners[postID]){ + this.listeners[postID] = [] + } + this.listeners[postID].push(socket) + } + + notifySocketIfAny(postID,name,message,amount){ + if(!this.listeners[postID]){ + return + } + this.listeners[postID].forEach(socket => { + if(!socket.connected){ + return + } + socket.emit("update",{ + name,message,amount + }) + }); + } +} + +const TipsForwarder = new TipsCB() +module.exports = TipsForwarder \ No newline at end of file diff --git a/src/index.html b/src/index.html new file mode 100644 index 00000000..d376198f --- /dev/null +++ b/src/index.html @@ -0,0 +1,85 @@ + + + + + + + Document + + + + +
+
+

fdsigfudfsbigbfduigbdfb

+

JUST TIPPED YOU!

+

100sats

+
+
+ + + \ No newline at end of file diff --git a/src/routes.js b/src/routes.js index 3037f99f..0e39d76f 100644 --- a/src/routes.js +++ b/src/routes.js @@ -15,6 +15,7 @@ const isARealUsableNumber = require('lodash/isFinite') const Big = require('big.js') const size = require('lodash/size') const { range, flatten, evolve } = require('ramda') +const path = require('path') const getListPage = require('../utils/paginate') const auth = require('../services/auth/auth') @@ -3271,4 +3272,7 @@ module.exports = async ( }) } }) + ap.get('/api/subscribeStream', (req, res) => { + res.sendFile(path.join(__dirname, '/index.html')) + }) } diff --git a/src/sockets.js b/src/sockets.js index 19fe8280..fcc42b7a 100644 --- a/src/sockets.js +++ b/src/sockets.js @@ -19,6 +19,7 @@ const { deepDecryptIfNeeded } = require('../services/gunDB/rpc') const GunEvents = require('../services/gunDB/contact-api/events') const SchemaManager = require('../services/schema') const { encryptedEmit, encryptedOn } = require('../utils/ECC/socket') +const TipsForwarder = require('../services/tipsCallback') /** * @typedef {import('../services/gunDB/Mediator').SimpleSocket} SimpleSocket * @typedef {import('../services/gunDB/contact-api/SimpleGUN').ValidDataValue} ValidDataValue @@ -685,6 +686,12 @@ module.exports = ( emit('$error', e.message) } }) + io.of('streams').on('connect', socket => { + console.log('a user connected') + socket.on('postID', postID => { + TipsForwarder.addSocket(postID, socket) + }) + }) return io } diff --git a/utils/protectedRoutes.js b/utils/protectedRoutes.js index 44d6e061..fc865dc4 100644 --- a/utils/protectedRoutes.js +++ b/utils/protectedRoutes.js @@ -9,7 +9,8 @@ module.exports = { "/api/lnd/wallet/status": true, "/api/lnd/auth": true, // - "/api/gun/auth": true + "/api/gun/auth": true, + "/api/subscribeStream":true, }, POST: { "/api/lnd/connect": true, @@ -31,5 +32,5 @@ module.exports = { PUT: {}, DELETE: {} }, - nonEncryptedRoutes: ['/api/security/exchangeKeys', "/api/encryption/exchange", '/healthz', '/ping', '/api/lnd/wallet/status', '/api/gun/auth'] + nonEncryptedRoutes: ['/api/security/exchangeKeys', "/api/encryption/exchange", '/healthz', '/ping', '/api/lnd/wallet/status', '/api/gun/auth',"/api/subscribeStream"] } \ No newline at end of file