From 229919ee57c77230b478c80dfc3aa263fe3076f1 Mon Sep 17 00:00:00 2001 From: Magic Cat Date: Wed, 10 Jan 2024 13:42:02 +0700 Subject: [PATCH 1/3] updated kyve VP --- apps/web-kyve/src/chain.json | 3 +- .../components/online_voting_power/hooks.ts | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 apps/web-kyve/src/screens/home/components/hero/components/online_voting_power/hooks.ts diff --git a/apps/web-kyve/src/chain.json b/apps/web-kyve/src/chain.json index af7f7493a9..ab963914d7 100644 --- a/apps/web-kyve/src/chain.json +++ b/apps/web-kyve/src/chain.json @@ -3,7 +3,8 @@ "title": "Kyve Block Explorer", "extra": { "profile": false, - "graphqlWs": true + "graphqlWs": true, + "votingPowerExponent": 6 }, "previewImage": "https://s3.bigdipper.live/previews/kyve.png", "themes": { diff --git a/apps/web-kyve/src/screens/home/components/hero/components/online_voting_power/hooks.ts b/apps/web-kyve/src/screens/home/components/hero/components/online_voting_power/hooks.ts new file mode 100644 index 0000000000..72647e83ee --- /dev/null +++ b/apps/web-kyve/src/screens/home/components/hero/components/online_voting_power/hooks.ts @@ -0,0 +1,54 @@ +import * as R from 'ramda'; +import { useCallback, useState } from 'react'; +import { OnlineVotingPowerQuery, useOnlineVotingPowerQuery } from '@/graphql/types/general_types'; + +type OnlineVotingPowerState = { + votingPower: number; + totalVotingPower: number; + activeValidators: number; +}; + +const initialState: OnlineVotingPowerState = { + votingPower: 0, + totalVotingPower: 0, + activeValidators: 0, +}; + +const formatOnlineVotingPower = (data: OnlineVotingPowerQuery) => { + const votingPower = data?.validatorVotingPowerAggregate?.aggregate?.sum?.votingPower ?? 0; + const bonded = data?.stakingPool?.[0]?.bonded ?? 0; + const activeValidators = data?.activeTotal?.aggregate?.count ?? 0; + + return { + activeValidators, + votingPower, + totalVotingPower: bonded, + }; +}; + +export const useOnlineVotingPower = () => { + const [state, setState] = useState(initialState); + + const handleSetState = useCallback( + (stateChange: (prevState: OnlineVotingPowerState) => OnlineVotingPowerState) => { + setState(prevState => { + const newState = stateChange(prevState); + return R.equals(prevState, newState) ? prevState : newState; + }); + }, + [] + ); + + useOnlineVotingPowerQuery({ + onCompleted: data => { + handleSetState(prevState => ({ + ...prevState, + ...formatOnlineVotingPower(data), + })); + }, + }); + + return { + state, + }; +}; From 3bf7c7f93bb89a5e523a926f9c397aad5e85ab2f Mon Sep 17 00:00:00 2001 From: Magic Cat Date: Wed, 10 Jan 2024 16:05:47 +0700 Subject: [PATCH 2/3] added changeset --- .changeset/gorgeous-parents-happen.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/gorgeous-parents-happen.md diff --git a/.changeset/gorgeous-parents-happen.md b/.changeset/gorgeous-parents-happen.md new file mode 100644 index 0000000000..2b89175e36 --- /dev/null +++ b/.changeset/gorgeous-parents-happen.md @@ -0,0 +1,5 @@ +--- +'web-kyve': major +--- + +fix voting power display From 62736966c523b9ab578fbb0bd8932a3ce0164d17 Mon Sep 17 00:00:00 2001 From: Magic Cat Date: Wed, 10 Jan 2024 17:09:57 +0700 Subject: [PATCH 3/3] lint --- .../components/hero/components/online_voting_power/hooks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web-kyve/src/screens/home/components/hero/components/online_voting_power/hooks.ts b/apps/web-kyve/src/screens/home/components/hero/components/online_voting_power/hooks.ts index 72647e83ee..4858cde565 100644 --- a/apps/web-kyve/src/screens/home/components/hero/components/online_voting_power/hooks.ts +++ b/apps/web-kyve/src/screens/home/components/hero/components/online_voting_power/hooks.ts @@ -22,7 +22,7 @@ const formatOnlineVotingPower = (data: OnlineVotingPowerQuery) => { return { activeValidators, votingPower, - totalVotingPower: bonded, + totalVotingPower: Number(bonded), }; };