Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
fix getOptionVotingForRankedChoice and send back ranked preference array
Browse files Browse the repository at this point in the history
  • Loading branch information
jparklev committed May 6, 2020
1 parent aadce3f commit 31e05bc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions packages/dai-plugin-governance/src/GovPollingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PrivateService } from '@makerdao/services-core';
import { POLLING } from './utils/constants';
import { MKR } from './utils/constants';
import BigNumber from 'bignumber.js';
import { fromBuffer } from './utils/helpers';
import { fromBuffer, toBuffer, paddedArray } from './utils/helpers';

const POSTGRES_MAX_INT = 2147483647;

Expand Down Expand Up @@ -82,10 +82,12 @@ export default class GovPollingService extends PrivateService {
}

async getOptionVotingForRankedChoice(address, pollId) {
return this.get('govQueryApi').getOptionVotingForRankedChoice(
address.toLowerCase(),
pollId
);
const optionIdRaw = await this.get(
'govQueryApi'
).getOptionVotingForRankedChoice(address.toLowerCase(), pollId);
const ballotBuffer = toBuffer(optionIdRaw, { endian: 'little' });
const ballot = paddedArray(32 - ballotBuffer.length, ballotBuffer);
return ballot.reverse().filter(choice => choice !== 0 && choice !== '0');
}

async getNumUniqueVoters(pollId) {
Expand Down
2 changes: 1 addition & 1 deletion packages/dai-plugin-governance/src/GovQueryApiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default class QueryApi extends PublicService {
}`;
const response = await this.getQueryResponse(this.serverUrl, query);
if (!response.currentVote.nodes[0]) return null;
return response.currentVote.nodes[0].optionId;
return response.currentVote.nodes[0].optionIdRaw;
}

async getBlockNumber(unixTime) {
Expand Down

0 comments on commit 31e05bc

Please sign in to comment.