diff --git a/api/resolvers/notifications.js b/api/resolvers/notifications.js
index 1a1e8050e..5b2928d59 100644
--- a/api/resolvers/notifications.js
+++ b/api/resolvers/notifications.js
@@ -5,6 +5,7 @@ import { pushSubscriptionSchema, validateSchema } from '@/lib/validate'
import { replyToSubscription } from '@/lib/webPush'
import { getSub } from './sub'
import { GqlAuthenticationError, GqlInputError } from '@/lib/error'
+import { msatsToSats } from '@/lib/format'
export default {
Query: {
@@ -361,12 +362,12 @@ export default {
LIMIT ${LIMIT})`
)
- if (meFull.noteDailyStats) {
+ if (meFull.noteSatSummary) {
queries.push(
`(SELECT CONCAT('stats_', date_trunc('day', t))::text as id,
t AS "sortTime",
NULL as "earnedSats",
- 'DailyStats' AS type
+ 'SatSummary' AS type
FROM user_stats_days
WHERE "user_stats_days"."id" = $1
AND t >= date_trunc('day', CURRENT_DATE - INTERVAL '1 day')
@@ -502,27 +503,27 @@ export default {
return res.length ? res[0].type : null
}
},
- DailyStats: {
+ SatSummary: {
date: async (n, args, { models }) => {
return new Date(n.id.replace('stats_', ''))
},
- stacked: async (n, args, { me, models }) => {
- const res = await models.$queryRaw`
- SELECT ((msats_stacked+msats_rewards)::float)/1000.0 as sats_stacked
+ stacked: async (n, args, { me, models }) => { // msats_rewards is already counted in msats_stacked
+ const [{ stacked }] = await models.$queryRaw`
+ SELECT sum(msats_stacked) as stacked
FROM user_stats_days
WHERE id = ${Number(me.id)}
AND t = ${new Date(n.id.replace('stats_', ''))}::timestamp
`
- return res.length ? res[0].sats_stacked : 0
+ return (stacked && msatsToSats(stacked)) || 0
},
spent: async (n, args, { me, models }) => {
- const res = await models.$queryRaw`
- SELECT (msats_spent::float)/1000.0 as sats_spent
+ const [{ spent }] = await models.$queryRaw`
+ SELECT sum(msats_spent) as spent
FROM user_stats_days
WHERE id = ${Number(me.id)}
AND t = ${new Date(n.id.replace('stats_', ''))}::timestamp
`
- return res.length ? res[0].sats_spent : 0
+ return (spent && msatsToSats(spent)) || 0
}
},
Earn: {
diff --git a/api/resolvers/user.js b/api/resolvers/user.js
index a1c62816f..19f360ac8 100644
--- a/api/resolvers/user.js
+++ b/api/resolvers/user.js
@@ -523,14 +523,14 @@ export default {
}
}
- if (user.noteDailyStats) {
- const dailyStats = await models.dailyStats.findFirst({
+ if (user.noteSatSummary) {
+ const satSummary = await models.satSummary.findFirst({
where: {
id: me.id
}
})
- if (dailyStats) {
+ if (satSummary) {
foundNotes()
return true
}
diff --git a/api/typeDefs/notifications.js b/api/typeDefs/notifications.js
index 9b1dac3b1..c70e207fa 100644
--- a/api/typeDefs/notifications.js
+++ b/api/typeDefs/notifications.js
@@ -82,7 +82,7 @@ export default gql`
type: String!
}
- type DailyStats {
+ type SatSummary {
id: ID!
sortTime: Date!
date: Date!
@@ -163,7 +163,7 @@ export default gql`
union Notification = Reply | Votification | Mention
| Invitification | Earn | JobChanged | InvoicePaid | WithdrawlPaid | Referral
- | Streak | DailyStats | FollowActivity | ForwardedVotification | Revenue | SubStatus
+ | Streak | SatSummary | FollowActivity | ForwardedVotification | Revenue | SubStatus
| TerritoryPost | TerritoryTransfer | Reminder | ItemMention | Invoicification
| ReferralReward
diff --git a/api/typeDefs/user.js b/api/typeDefs/user.js
index 000765cdc..0b3504383 100644
--- a/api/typeDefs/user.js
+++ b/api/typeDefs/user.js
@@ -94,7 +94,7 @@ export default gql`
nostrPubkey: String
nostrRelays: [String!]
noteAllDescendants: Boolean!
- noteDailyStats: Boolean
+ noteSatSummary: Boolean
noteCowboyHat: Boolean!
noteDeposits: Boolean!,
noteWithdrawals: Boolean!,
@@ -169,7 +169,7 @@ export default gql`
nostrPubkey: String
nostrRelays: [String!]
noteAllDescendants: Boolean!
- noteDailyStats: Boolean!
+ noteSatSummary: Boolean!
noteCowboyHat: Boolean!
noteDeposits: Boolean!
noteWithdrawals: Boolean!
diff --git a/components/notifications.js b/components/notifications.js
index 7bf081b40..a60b20502 100644
--- a/components/notifications.js
+++ b/components/notifications.js
@@ -58,7 +58,7 @@ function Notification ({ n, fresh }) {
(type === 'WithdrawlPaid' &&