diff --git a/lib/webPush.js b/lib/webPush.js index e8bf06832..390b53e47 100644 --- a/lib/webPush.js +++ b/lib/webPush.js @@ -405,6 +405,7 @@ export const notifyTerritoryRevenue = async (subAct) => { // TODO: needs testing, fix rewards not working first export async function notifyEarner (userId, earnings) { const fmt = msats => numWithUnits(msatsToSats(msats, { abbreviate: false })) + const referralTotal = earnings.FOREVER_REFERRAL.msats + earnings.ONE_DAY_REFERRAL.msats // TODO: remove console.log('notifying earners', JSON.stringify(earnings, null, 2)) @@ -416,8 +417,8 @@ export async function notifyEarner (userId, earnings) { if (earnings.COMMENT) body += `#${earnings.COMMENT.bestRank} among comments with ${fmt(earnings.COMMENT.msats)} in total\n` if (earnings.TIP_POST) body += `#${earnings.TIP_POST.bestRank} in post zapping with ${fmt(earnings.TIP_POST.msats)} in total\n` if (earnings.TIP_COMMENT) body += `#${earnings.TIP_COMMENT.bestRank} in comment zapping with ${fmt(earnings.TIP_COMMENT.msats)} in total\n` - if (earnings.FOREVER_REFERRAL) body += `#${earnings.FOREVER_REFERRAL.bestRank} in referral rewards with ${fmt(earnings.FOREVER_REFERRAL.msats)} in total\n` - if (earnings.ONE_DAY_REFERRAL) body += `#${earnings.ONE_DAY_REFERRAL.bestRank} in referral rewards with ${fmt(earnings.ONE_DAY_REFERRAL.msats)} in total` + if (earnings.ONE_DAY_REFERRAL) body += `in referral rewards with ${fmt(earnings.ONE_DAY_REFERRAL)} in total\n` + if (earnings.FOREVER_REFERRAL) body += `in lifetime referral rewards with ${fmt(earnings.FOREVER_REFERRAL.msats)} in total` try { await sendUserNotification(userId, { title, tag, body }) diff --git a/worker/earn.js b/worker/earn.js index 8c41b0931..04f94c273 100644 --- a/worker/earn.js +++ b/worker/earn.js @@ -149,6 +149,14 @@ export async function earn ({ name }) { type: 'FOREVER_REFERRAL', rank: earner.rank }, { models })) + + const userN = notifications[earner.foreverReferrerId] || {} + const prevMsats = userN.msats || 0 + const msats = foreverReferrerEarnings + prevMsats + notifications[earner.foreverReferrerId] = { + ...userN, + FOREVER_REFERRAL: msats + } } else if (earner.oneDayReferrerId) { // if the person doesn't have a forever referrer yet, they give double to their one day referrer oneDayReferrerEarnings += foreverReferrerEarnings @@ -162,6 +170,14 @@ export async function earn ({ name }) { type: 'ONE_DAY_REFERRAL', rank: earner.rank }, { models })) + + const userN = notifications[earner.oneDayReferrerId] || {} + const prevMsats = userN.msats || 0 + const msats = oneDayReferrerEarnings + prevMsats + notifications[earner.oneDayReferrerId] = { + ...userN, + ONE_DAY_REFERRAL: msats + } } }