remove leaderboard
This commit is contained in:
		
							parent
							
								
									de7f96a3a4
								
							
						
					
					
						commit
						26a23ade92
					
				@ -1,6 +1,5 @@
 | 
			
		||||
import { amountSchema, validateSchema } from '@/lib/validate'
 | 
			
		||||
import { getAd, getItem } from './item'
 | 
			
		||||
import { topUsers } from './user'
 | 
			
		||||
import performPaidAction from '../paidAction'
 | 
			
		||||
import { GqlInputError } from '@/lib/error'
 | 
			
		||||
 | 
			
		||||
@ -152,13 +151,6 @@ export default {
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  Rewards: {
 | 
			
		||||
    leaderboard: async (parent, args, { models, ...context }) => {
 | 
			
		||||
      // get to and from using postgres because it's easier to do there
 | 
			
		||||
      const [{ to, from }] = await models.$queryRaw`
 | 
			
		||||
        SELECT date_trunc('day',  (now() AT TIME ZONE 'America/Chicago')) AT TIME ZONE 'America/Chicago' as from,
 | 
			
		||||
               (date_trunc('day',  (now() AT TIME ZONE 'America/Chicago')) AT TIME ZONE 'America/Chicago') + interval '1 day - 1 second' as to`
 | 
			
		||||
      return await topUsers(parent, { when: 'custom', to: new Date(to).getTime().toString(), from: new Date(from).getTime().toString(), limit: 500 }, { models, ...context })
 | 
			
		||||
    },
 | 
			
		||||
    total: async (parent, args, { models }) => {
 | 
			
		||||
      if (!parent.total) {
 | 
			
		||||
        return 0
 | 
			
		||||
 | 
			
		||||
@ -18,7 +18,6 @@ export default gql`
 | 
			
		||||
    total: Int!
 | 
			
		||||
    time: Date!
 | 
			
		||||
    sources: [NameValue!]!
 | 
			
		||||
    leaderboard: UsersNullable
 | 
			
		||||
    ad: Item
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -14,7 +14,6 @@ import dynamic from 'next/dynamic'
 | 
			
		||||
import { FAST_POLL_INTERVAL, SSR } from '@/lib/constants'
 | 
			
		||||
import { useToast } from '@/components/toast'
 | 
			
		||||
import { useLightning } from '@/components/lightning'
 | 
			
		||||
import { ListUsers } from '@/components/user-list'
 | 
			
		||||
import { Col, Row } from 'react-bootstrap'
 | 
			
		||||
import { useData } from '@/components/use-data'
 | 
			
		||||
import { GrowthPieChartSkeleton } from '@/components/charts-skeletons'
 | 
			
		||||
@ -42,25 +41,6 @@ ${ITEM_FULL_FIELDS}
 | 
			
		||||
    ad {
 | 
			
		||||
      ...ItemFullFields
 | 
			
		||||
    }
 | 
			
		||||
    leaderboard {
 | 
			
		||||
      users {
 | 
			
		||||
        id
 | 
			
		||||
        name
 | 
			
		||||
        photoId
 | 
			
		||||
        ncomments
 | 
			
		||||
        nposts
 | 
			
		||||
        proportion
 | 
			
		||||
 | 
			
		||||
        optional {
 | 
			
		||||
          streak
 | 
			
		||||
          gunStreak
 | 
			
		||||
          horseStreak
 | 
			
		||||
          stacked
 | 
			
		||||
          spent
 | 
			
		||||
          referrals
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
`
 | 
			
		||||
@ -98,14 +78,14 @@ export function RewardLine ({ total, time }) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default function Rewards ({ ssrData }) {
 | 
			
		||||
  // only poll for updates to rewards and not leaderboard
 | 
			
		||||
  // only poll for updates to rewards
 | 
			
		||||
  const { data: rewardsData } = useQuery(
 | 
			
		||||
    REWARDS,
 | 
			
		||||
    SSR ? {} : { pollInterval: FAST_POLL_INTERVAL, nextFetchPolicy: 'cache-and-network' })
 | 
			
		||||
  const { data } = useQuery(REWARDS_FULL)
 | 
			
		||||
  const dat = useData(data, ssrData)
 | 
			
		||||
 | 
			
		||||
  let { rewards: [{ total, sources, time, leaderboard, ad }] } = useMemo(() => {
 | 
			
		||||
  let { rewards: [{ total, sources, time, ad }] } = useMemo(() => {
 | 
			
		||||
    return dat || { rewards: [{}] }
 | 
			
		||||
  }, [dat])
 | 
			
		||||
 | 
			
		||||
@ -117,20 +97,6 @@ export default function Rewards ({ ssrData }) {
 | 
			
		||||
 | 
			
		||||
  if (!dat) return <PageLoading />
 | 
			
		||||
 | 
			
		||||
  function EstimatedReward ({ rank, user }) {
 | 
			
		||||
    if (!user) return null
 | 
			
		||||
    const referrerReward = Math.max(Math.floor(total * user.proportion * 0.2), 0)
 | 
			
		||||
    const reward = Math.max(Math.floor(total * user.proportion) - referrerReward, 0)
 | 
			
		||||
 | 
			
		||||
    return (
 | 
			
		||||
      <div className='text-muted fst-italic'>
 | 
			
		||||
        <small>
 | 
			
		||||
          <span>estimated reward: {numWithUnits(reward)} <small className='fw-light'>(+ {numWithUnits(referrerReward)} to referrers)</small></span>
 | 
			
		||||
        </small>
 | 
			
		||||
      </div>
 | 
			
		||||
    )
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <Layout footerLinks>
 | 
			
		||||
      {ad &&
 | 
			
		||||
@ -141,7 +107,7 @@ export default function Rewards ({ ssrData }) {
 | 
			
		||||
          <ListItem item={ad} ad />
 | 
			
		||||
        </div>}
 | 
			
		||||
      <Row className='pb-3'>
 | 
			
		||||
        <Col lg={leaderboard?.users && 5}>
 | 
			
		||||
        <Col>
 | 
			
		||||
          <div
 | 
			
		||||
            className='d-flex flex-column sticky-lg-top py-5'
 | 
			
		||||
          >
 | 
			
		||||
@ -159,13 +125,6 @@ export default function Rewards ({ ssrData }) {
 | 
			
		||||
            <DonateButton />
 | 
			
		||||
          </div>
 | 
			
		||||
        </Col>
 | 
			
		||||
        {leaderboard?.users &&
 | 
			
		||||
          <Col lg={7}>
 | 
			
		||||
            <h2 className='pt-5 text-center text-muted'>leaderboard</h2>
 | 
			
		||||
            <div className='d-flex justify-content-center pt-4'>
 | 
			
		||||
              <ListUsers users={leaderboard.users} rank Embellish={EstimatedReward} />
 | 
			
		||||
            </div>
 | 
			
		||||
          </Col>}
 | 
			
		||||
      </Row>
 | 
			
		||||
    </Layout>
 | 
			
		||||
  )
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user