Skip to content

Commit

Permalink
Merge pull request #13 from arifintahu/fix/proposals
Browse files Browse the repository at this point in the history
Fix/proposals
  • Loading branch information
arifintahu authored Jul 29, 2024
2 parents 44ff3f8 + 6720714 commit 2a861ab
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 48 deletions.
30 changes: 22 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@types/react": "18.0.31",
"@types/react-dom": "18.0.11",
"bech32": "^2.0.0",
"cosmjs-types": "^0.7.2",
"cosmjs-types": "^0.9.0",
"dayjs": "^1.11.7",
"eslint": "8.37.0",
"eslint-config-next": "13.2.4",
Expand Down
30 changes: 13 additions & 17 deletions src/components/Parameters/GovParameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ export default function GovParameters() {
queryGovParams(tmClient, GOV_PARAMS_TYPE.TALLY),
])
.then((responses) => {
if (responses[0].votingParams) {
dispatch(setGovVotingParams(responses[0].votingParams))
if (responses[0].params) {
dispatch(setGovVotingParams(responses[0].params))
}
if (responses[1].depositParams) {
dispatch(setGovDepositParams(responses[1].depositParams))
if (responses[1].params) {
dispatch(setGovDepositParams(responses[1].params))
}
if (responses[2].tallyParams) {
dispatch(setGovTallyParams(responses[2].tallyParams))
if (responses[2].params) {
dispatch(setGovTallyParams(responses[2].params))
}
setIsLoaded(true)
})
Expand Down Expand Up @@ -118,7 +118,7 @@ export default function GovParameters() {
</Heading>
<Text pt="2" fontSize="lg" fontWeight={'medium'}>
{displayDurationSeconds(
depositParams?.maxDepositPeriod?.seconds.low
Number(depositParams?.maxDepositPeriod?.seconds)
)}
</Text>
</Box>
Expand All @@ -129,7 +129,9 @@ export default function GovParameters() {
Voting Period
</Heading>
<Text pt="2" fontSize="lg" fontWeight={'medium'}>
{displayDurationSeconds(votingParams?.votingPeriod?.seconds.low)}
{displayDurationSeconds(
Number(votingParams?.votingPeriod?.seconds)
)}
</Text>
</Box>
</Skeleton>
Expand All @@ -139,9 +141,7 @@ export default function GovParameters() {
Quorum
</Heading>
<Text pt="2" fontSize="lg" fontWeight={'medium'}>
{convertRateToPercent(
fromUtf8(tallyParams?.quorum ?? new Uint8Array())
)}
{convertRateToPercent(tallyParams?.quorum)}
</Text>
</Box>
</Skeleton>
Expand All @@ -151,9 +151,7 @@ export default function GovParameters() {
Threshold
</Heading>
<Text pt="2" fontSize="lg" fontWeight={'medium'}>
{convertRateToPercent(
fromUtf8(tallyParams?.threshold ?? new Uint8Array())
)}
{convertRateToPercent(tallyParams?.threshold)}
</Text>
</Box>
</Skeleton>
Expand All @@ -163,9 +161,7 @@ export default function GovParameters() {
Veto Threshold
</Heading>
<Text pt="2" fontSize="lg" fontWeight={'medium'}>
{convertRateToPercent(
fromUtf8(tallyParams?.vetoThreshold ?? new Uint8Array())
)}
{convertRateToPercent(tallyParams?.vetoThreshold)}
</Text>
</Box>
</Skeleton>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Parameters/MintParameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function MintParameters() {
Blocks per Year
</Heading>
<Text pt="2" fontSize="lg" fontWeight={'medium'}>
{params?.blocksPerYear.low.toLocaleString() ?? ''}
{params?.blocksPerYear ? Number(params?.blocksPerYear) : ''}
</Text>
</Box>
</Skeleton>
Expand Down
6 changes: 4 additions & 2 deletions src/components/Parameters/SlashingParameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export default function SlashingParameters() {
Signed Blocks Window
</Heading>
<Text pt="2" fontSize="lg" fontWeight={'medium'}>
{params?.signedBlocksWindow.low.toLocaleString() ?? ''}
{params?.signedBlocksWindow
? Number(params?.signedBlocksWindow)
: ''}
</Text>
</Box>
</Skeleton>
Expand All @@ -98,7 +100,7 @@ export default function SlashingParameters() {
</Heading>
<Text pt="2" fontSize="lg" fontWeight={'medium'}>
{displayDurationSeconds(
params?.downtimeJailDuration?.seconds.low
Number(params?.downtimeJailDuration?.seconds)
)}
</Text>
</Box>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Parameters/StakingParameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function StakingParameters() {
Unbonding Time
</Heading>
<Text pt="2" fontSize="lg" fontWeight={'medium'}>
{displayDurationSeconds(params?.unbondingTime?.seconds?.low)}
{displayDurationSeconds(Number(params?.unbondingTime?.seconds))}
</Text>
</Box>
</Skeleton>
Expand Down
26 changes: 13 additions & 13 deletions src/pages/proposals/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ import DataTable from '@/components/Datatable'
import { createColumnHelper } from '@tanstack/react-table'
import { getTypeMsg, displayDate } from '@/utils/helper'
import { proposalStatus, proposalStatusList } from '@/utils/constant'
import { decodeContentProposal } from '@/encoding'

type Proposal = {
id: number
id: bigint
title: string
types: string
status: proposalStatus | undefined
Expand Down Expand Up @@ -77,19 +76,19 @@ export default function Proposals() {
setIsLoading(true)
queryProposals(tmClient, page, perPage)
.then((response) => {
setTotal(response.pagination?.total.low ?? 0)
setTotal(Number(response.pagination?.total))
const proposalsList: Proposal[] = response.proposals.map((val) => {
const votingEnd = val.votingEndTime?.nanos
? new Date(val.votingEndTime?.seconds.low * 1000).toISOString()
? new Date(
Number(val.votingEndTime?.seconds) * 1000
).toISOString()
: null
const content = decodeContentProposal(
val.content?.typeUrl ?? '',
val.content?.value ?? new Uint8Array()
)
return {
id: val.proposalId.low,
title: content.data?.title ?? '',
types: getTypeMsg(val.content?.typeUrl ?? ''),
id: val.id,
title: val.title,
types: getTypeMsg(
val.messages.length ? val.messages[0].typeUrl : ''
),
status: proposalStatusList.find(
(item) => item.id === Number(val.status.toString())
),
Expand All @@ -99,9 +98,10 @@ export default function Proposals() {
setProposals(proposalsList)
setIsLoading(false)
})
.catch(() => {
.catch((err) => {
console.error(err)
toast({
title: 'Failed to fetch datatable',
title: 'Failed to fetch proposals',
description: '',
status: 'error',
duration: 5000,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/validators/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function Validators() {
setIsLoading(true)
queryActiveValidators(tmClient, page, perPage)
.then((response) => {
setTotal(response.pagination?.total.low ?? 0)
setTotal(Number(response.pagination?.total))
const validatorData: ValidatorData[] = response.validators.map(
(val) => {
return {
Expand Down
6 changes: 3 additions & 3 deletions src/rpc/abci/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
QueryProposalsResponse,
QueryParamsRequest as QueryGovParamsRequest,
QueryParamsResponse as QueryGovParamsResponse,
} from 'cosmjs-types/cosmos/gov/v1beta1/query'
} from 'cosmjs-types/cosmos/gov/v1/query'
import {
QueryParamsRequest as QueryDistributionParamsRequest,
QueryParamsResponse as QueryDistributionParamsResponse,
Expand Down Expand Up @@ -63,7 +63,7 @@ export async function queryProposals(
})
const req = QueryProposalsRequest.encode(proposalsRequest).finish()
const { value } = await queryClient.queryAbci(
'/cosmos.gov.v1beta1.Query/Proposals',
'/cosmos.gov.v1.Query/Proposals',
req
)
return QueryProposalsResponse.decode(value)
Expand Down Expand Up @@ -102,7 +102,7 @@ export async function queryGovParams(
paramsType: paramsType,
}).finish()
const { value } = await queryClient.queryAbci(
'/cosmos.gov.v1beta1.Query/Params',
'/cosmos.gov.v1.Query/Params',
req
)
return QueryGovParamsResponse.decode(value)
Expand Down
2 changes: 1 addition & 1 deletion src/store/paramsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
VotingParams,
DepositParams,
TallyParams,
} from 'cosmjs-types/cosmos/gov/v1beta1/gov'
} from 'cosmjs-types/cosmos/gov/v1/gov'

// Type for our state
export interface ParamsState {
Expand Down

0 comments on commit 2a861ab

Please sign in to comment.