update reward notification for msm

This commit is contained in:
keyan 2024-03-29 20:53:07 -05:00
parent 45f90bd3f9
commit 1e3a836fbc
4 changed files with 24 additions and 5 deletions

View File

@ -49,9 +49,25 @@ async function getActiveRewards (models) {
) u`
}
async function getMonthlyRewards (when, models) {
return await models.$queryRaw`
SELECT
(sum(total) / 1000)::INT as total,
date_trunc('month', ${when?.[0]}::text::timestamp) AT TIME ZONE 'America/Chicago' as time,
json_build_array(
json_build_object('name', 'donations', 'value', (sum(donations) / 1000)::INT),
json_build_object('name', 'fees', 'value', (sum(fees) / 1000)::INT),
json_build_object('name', 'boost', 'value', (sum(boost) / 1000)::INT),
json_build_object('name', 'jobs', 'value', (sum(jobs) / 1000)::INT),
json_build_object('name', 'anon''s stack', 'value', (sum(anons_stack) / 1000)::INT)
) AS sources
FROM rewards_days
WHERE date_trunc('month', rewards_days.t) = date_trunc('month', ${when?.[0]}::text::timestamp - interval '1 month')`
}
async function getRewards (when, models) {
if (when) {
if (when.length > 2) {
if (when.length > 1) {
throw new GraphQLError('too many dates', { extensions: { code: 'BAD_USER_INPUT' } })
}
when.forEach(w => {
@ -62,6 +78,10 @@ async function getRewards (when, models) {
if (new Date(when[0]) > new Date(when[when.length - 1])) {
throw new GraphQLError('bad date range', { extensions: { code: 'BAD_USER_INPUT' } })
}
if (new Date(when[0]).getTime() >= new Date('2024-03-01').getTime()) {
return await getMonthlyRewards(when, models)
}
}
const results = await models.$queryRaw`

View File

@ -165,7 +165,7 @@ function EarnNotification ({ n }) {
{n.sources.tipComments > 0 && <span>{(n.sources.comments > 0 || n.sources.posts > 0 || n.sources.tipPosts > 0) && ' \\ '}{numWithUnits(n.sources.tipComments, { abbreviate: false })} for zapping top comments early</span>}
</div>}
<div style={{ lineHeight: '140%' }}>
SN distributes the sats it earns back to its best stackers daily. These sats come from <Link href='/~jobs'>jobs</Link>, boosts, posting fees, and donations. You can see the daily rewards pool and make a donation <Link href='/rewards'>here</Link>.
SN distributes the sats it earns back to its best stackers. These sats come from <Link href='/~jobs'>jobs</Link>, boosts, posting fees, and donations. You can see the rewards pool and make a donation <Link href='/rewards'>here</Link>.
</div>
<small className='text-muted ms-1 pb-1 fw-normal'>click for details</small>
</div>

View File

@ -16,8 +16,7 @@ const GrowthPieChart = dynamic(() => import('@/components/charts').then(mod => m
})
export const getServerSideProps = getGetServerSideProps({
query: ME_REWARDS,
notFound: (data, params) => data.rewards.reduce((a, r) => a || new Date(r.time) > new Date(), false)
query: ME_REWARDS
})
export default function Rewards ({ ssrData }) {

View File

@ -52,7 +52,7 @@ export async function earn ({ name }) {
// get earners { userId, id, type, rank, proportion }
const earners = await models.$queryRaw`
SELECT id AS "userId", sum(proportion) as proportion
SELECT id AS "userId", sum(proportion) as proportion, ROW_NUMBER() OVER (ORDER BY sum(proportion) DESC) as rank
FROM user_values_days
WHERE date_trunc('month', user_values_days.t) = date_trunc('month', (now() - interval '1 month') AT TIME ZONE 'America/Chicago')
AND NOT (id = ANY (${SN_USER_IDS}))