Merge pull request #239 from shocknet/revert-238-tip-amt

Revert "tip amount in new location"
This commit is contained in:
Daniel Lugo 2020-11-05 12:55:36 -04:00 committed by GitHub
commit b8bd7daa6e

View file

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