Skip to content

Commit

Permalink
add referralReward types to earnings notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Soxasora committed Feb 2, 2025
1 parent 6c4fbb3 commit 7837559
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/webPush.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 })
Expand Down
16 changes: 16 additions & 0 deletions worker/earn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
}

Expand Down

0 comments on commit 7837559

Please sign in to comment.