-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webapp): add non-compliant BPs section
- Loading branch information
1 parent
9fe6772
commit c32acfa
Showing
33 changed files
with
438 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ export const PRODUCERS_QUERY = gql` | |
) { | ||
id | ||
owner | ||
url | ||
total_votes | ||
bp_json | ||
total_votes_percent | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { useState, useEffect } from 'react' | ||
import { useLazyQuery } from '@apollo/client' | ||
|
||
import { PRODUCERS_QUERY, SETTING_QUERY } from '../../gql' | ||
|
||
const useNonCompliantState = () => { | ||
const [loadProducers, { loading = true, data: { producers } = {} }] = | ||
useLazyQuery(PRODUCERS_QUERY) | ||
const [loadSettings, { data: { setting } = {} }] = useLazyQuery(SETTING_QUERY) | ||
const [items, setItems] = useState([]) | ||
const [stats, setStats] = useState() | ||
|
||
useEffect(() => { | ||
loadSettings({}) | ||
loadProducers({ | ||
variables: { | ||
where: { total_rewards: { _gte: 100 } }, | ||
offset: 0, | ||
limit: 150, | ||
}, | ||
}) | ||
}, [loadSettings, loadProducers]) | ||
|
||
useEffect(() => { | ||
if (!producers) return | ||
|
||
const { nonCompliantBPs, totalDailyRewards, nonCompliantRewards } = | ||
producers.reduce( | ||
(stats, producer) => { | ||
if (!Object.keys(producer.bp_json).length) { | ||
stats.nonCompliantBPs.push(producer) | ||
stats.nonCompliantRewards += producer.total_rewards | ||
} | ||
|
||
stats.totalDailyRewards += producer.total_rewards | ||
|
||
return stats | ||
}, | ||
{ nonCompliantBPs: [], totalDailyRewards: 0, nonCompliantRewards: 0 }, | ||
) | ||
|
||
const percentageRewards = (nonCompliantRewards / totalDailyRewards) * 100 | ||
|
||
setStats({ | ||
percentageRewards, | ||
dailyRewards: nonCompliantRewards, | ||
tokenPrice: setting?.token_price, | ||
}) | ||
setItems(nonCompliantBPs) | ||
}, [producers, setting]) | ||
|
||
return [ | ||
{ | ||
items, | ||
stats, | ||
loading, | ||
}, | ||
] | ||
} | ||
|
||
export default useNonCompliantState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.