From 03723bd5ee71438b2aab18811256cfa1de2de127 Mon Sep 17 00:00:00 2001 From: keyan Date: Thu, 18 Aug 2022 15:57:48 -0500 Subject: [PATCH] fix bad earn link it satistics --- pages/satistics.js | 30 +++++++++++++++++++----------- worker/earn.js | 2 +- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/pages/satistics.js b/pages/satistics.js index 66f80dde..b4decfb7 100644 --- a/pages/satistics.js +++ b/pages/satistics.js @@ -14,6 +14,7 @@ import { Checkbox, Form } from '../components/form' import { useRouter } from 'next/router' import Item from '../components/item' import Comment from '../components/comment' +import React from 'react' export const getServerSideProps = getGetServerSideProps(WALLET_HISTORY) @@ -142,6 +143,8 @@ export default function Satistics ({ data: { me, walletHistory: { facts, cursor case 'withdrawal': case 'invoice': return `/${fact.type}s/${fact.factId}` + case 'earn': + return default: return `/items/${fact.factId}` } @@ -200,17 +203,22 @@ export default function Satistics ({ data: { me, walletHistory: { facts, cursor - {facts.map((f, i) => ( - - - {f.type} - - - - {f.msats / 1000} - - - ))} + {facts.map((f, i) => { + const uri = href(f) + const Wrapper = uri ? Link : React.Fragment + + return ( + + + {f.type} + + + + {Math.floor(f.msats / 1000)} + + + ) + })} diff --git a/worker/earn.js b/worker/earn.js index 1e7c892c..871a95f0 100644 --- a/worker/earn.js +++ b/worker/earn.js @@ -34,7 +34,7 @@ function earn ({ models }) { const earners = await models.$queryRaw(` WITH item_ratios AS ( SELECT *, - "weightedVotes"/(sum("weightedVotes") OVER (PARTITION BY "parentId" IS NULL)) AS ratio + "weightedVotes"/coalesce(NULLIF(sum("weightedVotes") OVER (PARTITION BY "parentId" IS NULL),0), ${TOP_ITEMS}) AS ratio FROM ( SELECT *, ROW_NUMBER() OVER (PARTITION BY "parentId" IS NULL ORDER BY "weightedVotes" desc) AS r