Skip to content

Commit

Permalink
Aaronmgdr/leaderboard patch (#2055)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmgdr authored and celo-ci-bot-user committed Dec 5, 2019
1 parent 9466636 commit a330768
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/web/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ const FLAGS = {
development: {
ECOFUND: true,
ENV: 'development',
LEADERBOARD: true,
SDK: true,
},
production: {
ECOFUND: true,
ENV: 'production',
LEADERBOARD: true,
SDK: true,
},
staging: {
ECOFUND: true,
ENV: 'staging',
LEADERBOARD: true,
SDK: true,
},
}
Expand Down
10 changes: 8 additions & 2 deletions packages/web/src/dev/LeaderBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface BoardProps {

interface Competitor {
identity: string
address: string
points: number
}

Expand Down Expand Up @@ -69,13 +70,18 @@ class LeaderBoard extends React.PureComponent<BoardProps & I18nProps, State> {
const { isExpanded } = this.state
const showExpandButton = leaders.length >= INITIAL_MAX + 1

if (leaders.length < 1) {
const leadersWithBTUs = leaders.map((leader) => ({
points: leader.points / Math.pow(10, 18),
identity: leader.identity === 'Unknown account' ? leader.address : leader.identity,
}))

if (leadersWithBTUs.length < 1) {
return null
}

const realMax = leaders.length > EXPANDED_MAX ? EXPANDED_MAX : leaders.length

const sortedLeaders = leaders.sort(sorter).slice(0, isExpanded ? realMax : INITIAL_MAX)
const sortedLeaders = leadersWithBTUs.sort(sorter).slice(0, isExpanded ? realMax : INITIAL_MAX)
const maxPoints = round(sortedLeaders[0].points * 1.1, 100)
const width = this.state.width
return (
Expand Down
4 changes: 4 additions & 0 deletions packages/web/src/dev/LeaderBoardApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ const query = gql`
leaderboard {
points
identity
address
}
}
`

class LeaderBoardApp extends React.PureComponent<I18nProps> {
render() {
if (!getConfig().publicRuntimeConfig.FLAGS.LEADERBOARD) {
return null
}
return (
<ApolloProvider client={createApolloClient()}>
<Query query={query}>
Expand Down

0 comments on commit a330768

Please sign in to comment.