diff --git a/api/resolvers/rewards.js b/api/resolvers/rewards.js
index 53d4d4a1..c420406f 100644
--- a/api/resolvers/rewards.js
+++ b/api/resolvers/rewards.js
@@ -2,6 +2,7 @@ import { GraphQLError } from 'graphql'
import { amountSchema, ssValidate } from '../../lib/validate'
import serialize from './serial'
import { ANON_USER_ID } from '../../lib/constants'
+import { getItem } from './item'
export default {
Query: {
@@ -59,7 +60,7 @@ export default {
SELECT coalesce(sum(sats), 0) as total, json_agg("Earn".*) as rewards
FROM day_cte
CROSS JOIN LATERAL (
- (SELECT FLOOR("Earn".msats / 1000.0) as sats, type, rank
+ (SELECT FLOOR("Earn".msats / 1000.0) as sats, type, rank, "typeId"
FROM "Earn"
WHERE "Earn"."userId" = ${me.id}
AND date_trunc('day', "Earn".created_at AT TIME ZONE 'UTC' AT TIME ZONE 'America/Chicago') = day_cte.day
@@ -84,5 +85,14 @@ export default {
return sats
}
+ },
+ Reward: {
+ item: async (reward, args, { me, models }) => {
+ if (!reward.typeId) {
+ return null
+ }
+
+ return getItem(reward, { id: reward.typeId }, { me, models })
+ }
}
}
diff --git a/api/typeDefs/rewards.js b/api/typeDefs/rewards.js
index e00c9661..eebd1e1c 100644
--- a/api/typeDefs/rewards.js
+++ b/api/typeDefs/rewards.js
@@ -20,6 +20,7 @@ export default gql`
type: String
rank: Int
sats: Int!
+ item: Item
}
type MeRewards {
diff --git a/components/items.js b/components/items.js
index 547b2986..b14da3c9 100644
--- a/components/items.js
+++ b/components/items.js
@@ -40,13 +40,7 @@ export default function Items ({ ssrData, variables = {}, query, destructureData
{items.filter(filter).map((item, i) => (
{pinMap && pinMap[i + 1] && }
- {item.parentId
- ?
- : (item.isJob
- ?
- : (item.searchText
- ?
- : ))}
+
))}
@@ -59,6 +53,18 @@ export default function Items ({ ssrData, variables = {}, query, destructureData
)
}
+export function ListItem ({ item, ...props }) {
+ return (
+ item.parentId
+ ?
+ : (item.isJob
+ ?
+ : (item.searchText
+ ?
+ : ))
+ )
+}
+
export function ItemsSkeleton ({ rank, startRank = 0, limit = LIMIT }) {
const items = new Array(limit).fill(null)
diff --git a/fragments/rewards.js b/fragments/rewards.js
index 191b5569..a4291766 100644
--- a/fragments/rewards.js
+++ b/fragments/rewards.js
@@ -1,4 +1,5 @@
import gql from 'graphql-tag'
+import { ITEM_FULL_FIELDS } from './items'
export const REWARDS = gql`
query rewards($when: String) {
@@ -13,6 +14,7 @@ export const REWARDS = gql`
}`
export const ME_REWARDS = gql`
+ ${ITEM_FULL_FIELDS}
query meRewards($when: String) {
rewards(when: $when) {
total
@@ -28,6 +30,10 @@ export const ME_REWARDS = gql`
type
rank
sats
+ item {
+ ...ItemFullFields
+ text
+ }
}
}
}`
diff --git a/pages/rewards/[when].js b/pages/rewards/[when].js
index aac8c5c9..0843a66d 100644
--- a/pages/rewards/[when].js
+++ b/pages/rewards/[when].js
@@ -7,6 +7,7 @@ import { useRouter } from 'next/router'
import { getGetServerSideProps } from '../../api/ssrApollo'
import { fixedDecimal } from '../../lib/format'
import Trophy from '../../svgs/trophy-fill.svg'
+import { ListItem } from '../../components/items'
const GrowthPieChart = dynamic(() => import('../../components/charts').then(mod => mod.GrowthPieChart), {
loading: () =>
Loading...
@@ -51,7 +52,7 @@ export default function Rewards ({ ssrData }) {
)
}
-function Reward ({ rank, type, sats }) {
+function Reward ({ rank, type, sats, item }) {
if (!rank) return null
const color = rank <= 3 ? 'text-primary' : 'text-muted'
@@ -73,8 +74,14 @@ function Reward ({ rank, type, sats }) {
}
return (
-
-
#{rank} {category} for
{sats} sats
+
+
+ #{rank} {category} for {sats} sats
+
+ {item &&
+
+
+
}
)
}
diff --git a/worker/earn.js b/worker/earn.js
index 8b6026fb..867ceca8 100644
--- a/worker/earn.js
+++ b/worker/earn.js
@@ -65,7 +65,7 @@ function earn ({ models }) {
- how early they upvoted it
- how the post/comment scored
- Now: 100% of earnings go to zappers of the top 21% of posts/comments
+ Now: 100% of earnings go to top 21% of posts/comments
*/
// get earners { userId, id, type, rank, proportion }
@@ -118,11 +118,9 @@ function earn ({ models }) {
JOIN users on "userId" = users.id
GROUP BY "userId", "parentId" IS NULL
)
- SELECT "userId", NULL as id, type, ROW_NUMBER() OVER (PARTITION BY "isPost" ORDER BY upvoter_ratio DESC) as rank,
- upvoter_ratio/(sum(upvoter_ratio) OVER (PARTITION BY "isPost"))/2 as proportion
- FROM upvoter_ratios
- WHERE upvoter_ratio > 0
- ORDER BY "isPost", rank ASC`
+ SELECT "userId", id, type, rank, ratio/2.0 as proportion
+ FROM item_ratios
+ ORDER BY type, rank ASC`
// in order to group earnings for users we use the same createdAt time for
// all earnings