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: use BigInt to compute proposal state #544

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions apps/ui/src/networks/common/graphqlApi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,18 @@ function getProposalState(
proposal: ApiProposal,
current: number
): ProposalState {
// we have broken types, we should unify, this is quick fix for Nimbora PR
// those values are actually strings
// https://github.com/snapshot-labs/sx-monorepo/pull/529/files#r1691071502
const quorum = BigInt(proposal.quorum);
const scoresTotal = BigInt(proposal.scores_total);
const scoresFor = BigInt(proposal.scores_1);
const scoresAgainst = BigInt(proposal.scores_2);
ChaituVR marked this conversation as resolved.
Show resolved Hide resolved

if (proposal.executed) return 'executed';
if (proposal.max_end <= current) {
if (proposal.scores_total < proposal.quorum) return 'rejected';
return proposal.scores_1 > proposal.scores_2 ? 'passed' : 'rejected';
if (scoresTotal < quorum) return 'rejected';
return scoresFor > scoresAgainst ? 'passed' : 'rejected';
}
if (proposal.start > current) return 'pending';

Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/networks/common/graphqlApi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export type ApiProposal = {
min_end: number;
max_end: number;
snapshot: number;
// TODO: those are actually numbers, we need to adjust it across the app at some point
// TODO: those are actually strings, we need to adjust it across the app at some point
scores_1: number;
scores_2: number;
scores_3: number;
Expand Down
Loading