From faf71f744ca7914cba97f7d61e0294e1684fd065 Mon Sep 17 00:00:00 2001 From: keyan Date: Wed, 30 Aug 2023 10:00:47 -0500 Subject: [PATCH] handle some rewards corner cases --- api/resolvers/rewards.js | 5 ++++- api/ssrApollo.js | 12 ++++++++---- components/notifications.js | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/api/resolvers/rewards.js b/api/resolvers/rewards.js index f82a24d2..9b28bc1c 100644 --- a/api/resolvers/rewards.js +++ b/api/resolvers/rewards.js @@ -16,6 +16,9 @@ export default { throw new GraphQLError('invalid date', { extensions: { code: 'BAD_USER_INPUT' } }) } }) + if (new Date(when[0]) > new Date(when[when.length - 1])) { + throw new GraphQLError('bad date range', { extensions: { code: 'BAD_USER_INPUT' } }) + } } const results = await models.$queryRaw` @@ -59,7 +62,7 @@ export default { GROUP BY days_cte.day ORDER BY days_cte.day ASC` - return results.length ? results : [{ total: 0, time: 0, sources: [] }] + return results.length ? results : [{ total: 0, time: '0', sources: [] }] }, meRewards: async (parent, { when }, { me, models }) => { if (!me) { diff --git a/api/ssrApollo.js b/api/ssrApollo.js index 10e605de..4db1f759 100644 --- a/api/ssrApollo.js +++ b/api/ssrApollo.js @@ -93,10 +93,14 @@ export function getGetServerSideProps ({ query, variables, notFound, authRequire let error = null; let data = null; let props = {} if (query) { - ({ error, data } = await client.query({ - query, - variables: vars - })) + try { + ({ error, data } = await client.query({ + query, + variables: vars + })) + } catch (e) { + console.error(e) + } if (error || !data || (notFound && notFound(data, vars))) { return { diff --git a/components/notifications.js b/components/notifications.js index 20d1726e..f4fe2e18 100644 --- a/components/notifications.js +++ b/components/notifications.js @@ -172,9 +172,10 @@ function EarnNotification ({ n }) { {n.sources.tipPosts > 0 && {(n.sources.comments > 0 || n.sources.posts > 0) && ' \\ '}{numWithUnits(n.sources.tipPosts, { abbreviate: false })} for zapping top posts early} {n.sources.tipComments > 0 && {(n.sources.comments > 0 || n.sources.posts > 0 || n.sources.tipPosts > 0) && ' \\ '}{numWithUnits(n.sources.tipComments, { abbreviate: false })} for zapping top comments early} } -
+
SN distributes the sats it earns back to its best stackers daily. These sats come from jobs, boosts, posting fees, and donations. You can see the daily rewards pool and make a donation here.
+ click for details
)