Skip to content

Commit

Permalink
Fix vote history
Browse files Browse the repository at this point in the history
  • Loading branch information
ChewingGlass committed Nov 28, 2023
1 parent e27793f commit 0d5f2c3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
23 changes: 21 additions & 2 deletions packages/helium-vote-service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { cloneRepo, readProxiesAndUpsert } from "./repo";
import fastifyStatic from "@fastify/static";
import { HNT_MINT, IOT_MINT, MOBILE_MINT } from "@helium/spl-utils";
import { organizationKey } from "@helium/organization-sdk";
import { camelCase, isPlainObject, mapKeys } from "lodash";

const server: FastifyInstance = Fastify({
logger: true,
Expand Down Expand Up @@ -266,7 +267,7 @@ SELECT
'registrar', vms.registrar,
'weight', vms.weight,
'choice', vms.choice,
'choiceName', p.choices[vms.choice]->>'name'
'choiceName', p.choices[vms.choice + 1]->>'name'
)) as votes
FROM exploded_choice_vote_markers vms
JOIN proposals p ON vms.proposal = p.address
Expand All @@ -277,9 +278,27 @@ GROUP BY p.address
OFFSET ${offset}
LIMIT ${limit};
`);
return result[0];
return result[0].map(deepCamelCaseKeys);
});

function deepCamelCaseKeys(obj) {
if (Array.isArray(obj)) {
return obj.map(deepCamelCaseKeys);
} else if (isPlainObject(obj)) {
return mapKeys(
Object.fromEntries(
Object.entries(obj).map(([key, value]) => [
camelCase(key),
deepCamelCaseKeys(value),
])
),
(value, key) => camelCase(key)
);
} else {
return obj;
}
}

const start = async () => {
try {
const port = process.env.PORT ? Number(process.env.PORT) : 8081;
Expand Down
20 changes: 10 additions & 10 deletions packages/helium-vote-service/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ export class Proposal extends Model {
declare namespace: string;
declare owner: string;
declare state: object;
declare created_at: number;
declare proposal_config: string;
declare max_choices_per_voter: number;
declare createdAt: number;
declare proposalConfig: string;
declare maxChoicesPerVoter: number;
declare seed: Buffer;
declare name: string;
declare uri: string;
declare tags: string[];
declare choices: object[];
declare bump_seed: number;
declare refreshed_at: Date;
declare bumpSeed: number;
declare refreshedAt: Date;
}

Proposal.init(
Expand All @@ -76,16 +76,16 @@ Proposal.init(
namespace: DataTypes.STRING,
owner: DataTypes.STRING,
state: DataTypes.JSONB,
created_at: DataTypes.DECIMAL,
proposal_config: DataTypes.STRING,
max_choices_per_voter: DataTypes.INTEGER,
createdAt: DataTypes.DECIMAL,
proposalConfig: DataTypes.STRING,
maxChoicesPerVoter: DataTypes.INTEGER,
seed: DataTypes.BLOB,
name: DataTypes.STRING,
uri: DataTypes.STRING,
tags: DataTypes.ARRAY(DataTypes.STRING),
choices: DataTypes.ARRAY(DataTypes.JSONB),
bump_seed: DataTypes.INTEGER,
refreshed_at: DataTypes.DATE,
bumpSeed: DataTypes.INTEGER,
refreshedAt: DataTypes.DATE,
},
{
sequelize,
Expand Down
2 changes: 1 addition & 1 deletion packages/voter-stake-registry-sdk/src/voteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export type Proposal = {
name: string;
uri: string;
tags: string[];
choices: object[];
choices: { name: string; weight: string; uri: string }[];
bump_seed: number;
refreshed_at: Date;
};
Expand Down

0 comments on commit 0d5f2c3

Please sign in to comment.