Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: hide proposal tally in voting period #873

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 44 additions & 33 deletions infrastructure/httpapi/handlers/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,23 @@ func (handler *Proposals) FindById(ctx *fasthttp.RequestCtx) {
return
}

tally, queryTallyErr := handler.cosmosClient.ProposalTally(idParam)
if queryTallyErr != nil {
if !errors.Is(queryTallyErr, cosmosapp.ErrProposalNotFound) {
handler.logger.Errorf("error retrieving proposal tally: %v", queryTallyErr)
httpapi.InternalServerError(ctx)
return
}
tally = cosmosapp.Tally{
Yes: "0",
Abstain: "0",
No: "0",
NoWithVeto: "0",
tally := cosmosapp.Tally{}

var queryTallyErr error
if proposal.Status != proposal_view.PROPOSAL_STATUS_VOTING_PERIOD {
tally, queryTallyErr = handler.cosmosClient.ProposalTally(idParam)
if queryTallyErr != nil {
if !errors.Is(queryTallyErr, cosmosapp.ErrProposalNotFound) {
handler.logger.Errorf("error retrieving proposal tally: %v", queryTallyErr)
httpapi.InternalServerError(ctx)
return
}
tally = cosmosapp.Tally{
Yes: "0",
Abstain: "0",
No: "0",
NoWithVeto: "0",
}
}
}

Expand Down Expand Up @@ -113,34 +118,40 @@ func (handler *Proposals) FindById(ctx *fasthttp.RequestCtx) {
}
requiredVotingPower := new(big.Float).Mul(totalBonded, quorum)

var votedPowerResult *ProposalVotedPowerResult
totalVotedPower := big.NewInt(0)
for _, votedPowerStr := range []string{
tally.Yes,
tally.No,
tally.NoWithVeto,
tally.Abstain,
} {
votedPower, parseVotedPowerOk := new(big.Int).SetString(votedPowerStr, 10)
if !parseVotedPowerOk {
handler.logger.Error("error parsing voted power")
httpapi.InternalServerError(ctx)
return

if proposal.Status != proposal_view.PROPOSAL_STATUS_VOTING_PERIOD {
for _, votedPowerStr := range []string{
tally.Yes,
tally.No,
tally.NoWithVeto,
tally.Abstain,
} {
votedPower, parseVotedPowerOk := new(big.Int).SetString(votedPowerStr, 10)
if !parseVotedPowerOk {
handler.logger.Error("error parsing voted power")
httpapi.InternalServerError(ctx)
return
}

totalVotedPower = new(big.Int).Add(totalVotedPower, votedPower)
}

totalVotedPower = new(big.Int).Add(totalVotedPower, votedPower)
votedPowerResult = &ProposalVotedPowerResult{
Yes: tally.Yes,
Abstain: tally.Abstain,
No: tally.No,
NoWithVeto: tally.NoWithVeto,
}
}

proposalDetails := ProposalDetails{
proposal,

requiredVotingPower.Text('f', 0),
totalVotedPower.Text(10),
ProposalVotedPowerResult{
Yes: tally.Yes,
Abstain: tally.Abstain,
No: tally.No,
NoWithVeto: tally.NoWithVeto,
},
votedPowerResult,
}

httpapi.Success(ctx, proposalDetails)
Expand Down Expand Up @@ -271,9 +282,9 @@ func (handler *Proposals) ListDepositorsById(ctx *fasthttp.RequestCtx) {
type ProposalDetails struct {
*proposal_view.ProposalWithMonikerRow

RequiredVotingPower string `json:"requiredVotingPower"`
TotalVotedPower string `json:"totalVotedPower"`
VotedPowerResult ProposalVotedPowerResult `json:"votedPowerResult"`
RequiredVotingPower string `json:"requiredVotingPower"`
TotalVotedPower string `json:"totalVotedPower"`
VotedPowerResult *ProposalVotedPowerResult `json:"votedPowerResult"`
}

type ProposalVotedPowerResult struct {
Expand Down
Loading