Skip to content

Commit

Permalink
fixed gov proposal total and deposit period loading
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Apr 5, 2024
1 parent 3d0384a commit d8ac389
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 28 deletions.
84 changes: 59 additions & 25 deletions packages/state/recoil/selectors/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,42 +729,76 @@ export const govProposalsSelector = selectorFamily<
let total = 0

// Try to load from indexer first.
const indexerProposals: {
id: string
data: string
}[] =
get(
queryGenericIndexerSelector({
chainId,
formula: 'gov/reverseProposals',
args: {
limit,
offset,
},
})
)?.proposals ?? []
const indexerProposals:
| {
proposals: {
id: string
data: string
}[]
total: number
}
| undefined = get(
queryGenericIndexerSelector({
chainId,
formula: 'gov/reverseProposals',
args: {
limit,
offset,
},
})
)

if (indexerProposals.length) {
if (indexerProposals?.proposals.length) {
if (supportsV1Gov) {
v1Proposals = indexerProposals.flatMap(
v1Proposals = indexerProposals.proposals.flatMap(
({ data }): ProposalV1 | [] => {
try {
return ProposalV1.decode(fromBase64(data))
} catch {
return []
}
const proposal = ProposalV1.decode(fromBase64(data))

if (
status === ProposalStatus.PROPOSAL_STATUS_UNSPECIFIED ||
proposal.status === status
) {
return proposal
}
} catch {}

return []
}
)

if (status === ProposalStatus.PROPOSAL_STATUS_UNSPECIFIED) {
total = indexerProposals.total
} else {
total = v1Proposals.length
}
} else {
v1Beta1Proposals = indexerProposals.flatMap(
v1Beta1Proposals = indexerProposals.proposals.flatMap(
({ data }): ProposalV1Beta1 | [] => {
try {
return ProposalV1Beta1.decode(fromBase64(data), undefined, true)
} catch {
return []
}
const proposal = ProposalV1Beta1.decode(
fromBase64(data),
undefined,
true
)

if (
status === ProposalStatus.PROPOSAL_STATUS_UNSPECIFIED ||
proposal.status === status
) {
return proposal
}
} catch {}

return []
}
)

if (status === ProposalStatus.PROPOSAL_STATUS_UNSPECIFIED) {
total = indexerProposals.total
} else {
total = v1Beta1Proposals.length
}
}

// Fallback to querying chain if indexer failed.
Expand Down
11 changes: 8 additions & 3 deletions packages/stateful/components/gov/GovProposalList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,14 @@ export const GovProposalList = () => {
(a.proposal.proposal.depositEndTime ?? new Date(0)).getTime()
)

const historyCount = loadingAllGovProposals.loading
? 0
: loadingAllGovProposals.data.total - openProposals.length
const historyCount =
loadingAllGovProposals.loading ||
openGovProposalsVotingPeriod.loading ||
govProposalsDepositPeriod.loading
? 0
: loadingAllGovProposals.data.total -
openGovProposalsVotingPeriod.data.total -
govProposalsDepositPeriod.data.total

return (
<StatelessProposalList
Expand Down

0 comments on commit d8ac389

Please sign in to comment.