Skip to content

Commit

Permalink
fix: Allow lowercase voter address on votes query (#868)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaituVR authored Jun 15, 2024
1 parent 37dd10a commit 59fe38d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"prettier": "@snapshot-labs/prettier-config",
"dependencies": {
"@ethersproject/address": "^5.7.0",
"@graphql-tools/schema": "^10.0.0",
"@snapshot-labs/keycard": "^0.5.1",
"@snapshot-labs/snapshot-metrics": "^1.4.1",
Expand Down
17 changes: 17 additions & 0 deletions src/graphql/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getAddress } from '@ethersproject/address';
import graphqlFields from 'graphql-fields';
import fetch from 'node-fetch';
import { jsonParse } from '../helpers/utils';
Expand Down Expand Up @@ -117,7 +118,23 @@ export function formatSpace({
export function buildWhereQuery(fields, alias, where) {
let query: any = '';
const params: any[] = [];

Object.entries(fields).forEach(([field, type]) => {
if (type === 'EVMAddress') {
const conditions = ['', '_not', '_in', '_not_in'];
try {
conditions.forEach(condition => {
const key = `${field}${condition}`;
if (where[key]) {
where[key] = condition.includes('in')
? where[key].map(getAddress)
: getAddress(where[key]);
}
});
} catch (e) {
throw new PublicError(`Invalid ${field} address`);
}
}
if (where[field] !== undefined) {
query += `AND ${alias}.${field} = ? `;
params.push(where[field]);
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/operations/votes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function query(parent, args, context?, info?) {
id: 'string',
ipfs: 'string',
space: 'string',
voter: 'string',
voter: 'EVMAddress',
proposal: 'string',
reason: 'string',
app: 'string',
Expand Down

0 comments on commit 59fe38d

Please sign in to comment.