tip amount in new location
This commit is contained in:
parent
5dafed1a00
commit
890d2601b9
1 changed files with 11 additions and 12 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* @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')
|
||||||
|
|
@ -36,16 +37,13 @@ const _lookupInvoice = hash =>
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const _getPostTipInfo = ({ postID, page }) =>
|
const _getPostTipInfo = ({ postID }) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise(resolve => {
|
||||||
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 (post && post.date) {
|
if (typeof post === 'object' && post && post.date) {
|
||||||
const { tipCounter, tipValue } = post
|
const { tipCounter, tipValue } = post
|
||||||
console.log(post)
|
console.log(post)
|
||||||
resolve({
|
resolve({
|
||||||
|
|
@ -58,7 +56,7 @@ const _getPostTipInfo = ({ postID, page }) =>
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const _incrementPost = ({ postID, page, orderAmount }) =>
|
const _incrementPost = ({ postID, orderAmount }) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
const parsedAmount = parseFloat(orderAmount)
|
const parsedAmount = parseFloat(orderAmount)
|
||||||
|
|
||||||
|
|
@ -69,7 +67,7 @@ const _incrementPost = ({ postID, page, orderAmount }) =>
|
||||||
|
|
||||||
Logger.info('[POST TIP] Getting Post Tip Values...')
|
Logger.info('[POST TIP] Getting Post Tip Values...')
|
||||||
|
|
||||||
return _getPostTipInfo({ postID, page })
|
return _getPostTipInfo({ postID })
|
||||||
.then(({ tipValue, tipCounter }) => {
|
.then(({ tipValue, tipCounter }) => {
|
||||||
const updatedTip = {
|
const updatedTip = {
|
||||||
tipCounter: tipCounter + 1,
|
tipCounter: tipCounter + 1,
|
||||||
|
|
@ -77,9 +75,6 @@ const _incrementPost = ({ postID, page, 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, () => {
|
||||||
|
|
@ -158,7 +153,6 @@ 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
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -172,14 +166,18 @@ 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 })
|
||||||
|
|
||||||
|
|
@ -188,6 +186,7 @@ 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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue