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' && ) || (type === 'Referral' && ) || (type === 'Streak' && ) || - (type === 'DailyStats' && ) || + (type === 'SatSummary' && ) || (type === 'Votification' && ) || (type === 'ForwardedVotification' && ) || (type === 'Mention' && ) || @@ -164,7 +164,7 @@ const defaultOnClick = n => { if (type === 'Referral') return { href: '/referrals/month' } if (type === 'ReferralReward') return { href: '/referrals/month' } if (type === 'Streak') return {} - if (type === 'DailyStats') return {} + if (type === 'SatSummary') return {} if (type === 'TerritoryTransfer') return { href: `/~${n.sub.name}` } if (!n.item) return {} @@ -203,7 +203,7 @@ function Streak ({ n }) { ) } -function DailyStats ({ n }) { // WIP +function SatSummary ({ n }) { // WIP // stacked and spent return (
diff --git a/fragments/notifications.js b/fragments/notifications.js index d08d9448f..5cd15577f 100644 --- a/fragments/notifications.js +++ b/fragments/notifications.js @@ -88,7 +88,7 @@ export const NOTIFICATIONS = gql` days type } - ... on DailyStats { + ... on SatSummary { id sortTime date diff --git a/fragments/users.js b/fragments/users.js index e38b76b80..61f2d4925 100644 --- a/fragments/users.js +++ b/fragments/users.js @@ -82,7 +82,7 @@ export const SETTINGS_FIELDS = gql` noteWithdrawals noteInvites noteJobIndicator - noteDailyStats + noteSatSummary noteCowboyHat noteForwardedSats hideInvoiceDesc diff --git a/lib/apollo.js b/lib/apollo.js index ed7b8e050..f412fbfae 100644 --- a/lib/apollo.js +++ b/lib/apollo.js @@ -63,7 +63,7 @@ function getClient (uri) { 'WithdrawlPaid', 'Referral', 'Streak', - 'DailyStats', + 'SatSummary', 'FollowActivity', 'ForwardedVotification', 'Revenue', diff --git a/lib/webPush.js b/lib/webPush.js index 3084285c4..b0123ea1b 100644 --- a/lib/webPush.js +++ b/lib/webPush.js @@ -46,7 +46,7 @@ const createUserFilter = (tag) => { EARN: 'noteEarning', DEPOSIT: 'noteDeposits', WITHDRAWAL: 'noteWithdrawals', - DAILY_STATS: 'noteDailyStats', + DAILY_STATS: 'noteSatSummary', STREAK: 'noteCowboyHat' } const key = tagMap[tag.split('-')[0]] @@ -393,7 +393,7 @@ export async function notifyStreakLost (userId, streak) { } } -export async function notifyDailyStats (userId, stats) { // WIP +export async function notifySatSummary (userId, stats) { // WIP try { await sendUserNotification(userId, { title: 'WIP sats stats', diff --git a/pages/settings/index.js b/pages/settings/index.js index 69e666fcd..4e82b1bad 100644 --- a/pages/settings/index.js +++ b/pages/settings/index.js @@ -138,7 +138,7 @@ export default function Settings ({ ssrData }) { noteInvites: settings?.noteInvites, noteJobIndicator: settings?.noteJobIndicator, noteCowboyHat: settings?.noteCowboyHat, - noteDailyStats: settings?.noteDailyStats, + noteSatSummary: settings?.noteSatSummary, noteForwardedSats: settings?.noteForwardedSats, hideInvoiceDesc: settings?.hideInvoiceDesc, autoDropBolt11s: settings?.autoDropBolt11s, @@ -333,7 +333,7 @@ export default function Settings ({ ssrData }) { />