diff --git a/utils/lndJobs.js b/utils/lndJobs.js index 1c940415..d5b36b11 100644 --- a/utils/lndJobs.js +++ b/utils/lndJobs.js @@ -1,7 +1,6 @@ /** * @prettier */ -// @ts-check const Logger = require('winston') const { wait } = require('./helpers') const Key = require('../services/gunDB/contact-api/key') @@ -37,13 +36,16 @@ const _lookupInvoice = hash => }) }) -const _getPostTipInfo = ({ postID }) => - new Promise(resolve => { +const _getPostTipInfo = ({ postID, page }) => + new Promise((resolve, reject) => { getUser() + .get(Key.WALL) + .get(Key.PAGES) + .get(page) .get(Key.POSTS) .get(postID) .once(post => { - if (typeof post === 'object' && post && post.date) { + if (post && post.date) { const { tipCounter, tipValue } = post console.log(post) resolve({ @@ -56,7 +58,7 @@ const _getPostTipInfo = ({ postID }) => }) }) -const _incrementPost = ({ postID, orderAmount }) => +const _incrementPost = ({ postID, page, orderAmount }) => new Promise((resolve, reject) => { const parsedAmount = parseFloat(orderAmount) @@ -67,7 +69,7 @@ const _incrementPost = ({ postID, orderAmount }) => Logger.info('[POST TIP] Getting Post Tip Values...') - return _getPostTipInfo({ postID }) + return _getPostTipInfo({ postID, page }) .then(({ tipValue, tipCounter }) => { const updatedTip = { tipCounter: tipCounter + 1, @@ -75,6 +77,9 @@ const _incrementPost = ({ postID, orderAmount }) => } getUser() + .get(Key.WALL) + .get(Key.PAGES) + .get(page) .get(Key.POSTS) .get(postID) .put(updatedTip, () => { @@ -153,6 +158,7 @@ const executeTipAction = (tip, invoice) => { if (tip.targetType === 'post') { _incrementPost({ postID: tip.postID, + page: tip.postPage, orderAmount: invoice.amt_paid_sat }) } @@ -166,18 +172,14 @@ const updateUnverifiedTips = () => { try { if ( !tip || - // @ts-expect-error tip.state !== INVOICE_STATE.OPEN || - // @ts-expect-error (tip._errorCount && tip._errorCount >= ERROR_TRIES_THRESHOLD) ) { return } Logger.info('Unverified invoice found!', tip) - // @ts-expect-error const invoice = await _lookupInvoice(tip.hash) Logger.info('Invoice located:', invoice) - // @ts-expect-error if (invoice.state !== tip.state) { await _updateTipData(id, { state: invoice.state }) @@ -186,7 +188,6 @@ const updateUnverifiedTips = () => { } } catch (err) { Logger.error('[TIP] An error has occurred while updating invoice', err) - // @ts-expect-error const errorCount = tip._errorCount ? tip._errorCount : 0 _updateTipData(id, { _errorCount: errorCount + 1