Skip to content

Commit 59fe38d

Browse files
authored
fix: Allow lowercase voter address on votes query (#868)
1 parent 37dd10a commit 59fe38d

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
},
2222
"prettier": "@snapshot-labs/prettier-config",
2323
"dependencies": {
24+
"@ethersproject/address": "^5.7.0",
2425
"@graphql-tools/schema": "^10.0.0",
2526
"@snapshot-labs/keycard": "^0.5.1",
2627
"@snapshot-labs/snapshot-metrics": "^1.4.1",

src/graphql/helpers.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getAddress } from '@ethersproject/address';
12
import graphqlFields from 'graphql-fields';
23
import fetch from 'node-fetch';
34
import { jsonParse } from '../helpers/utils';
@@ -117,7 +118,23 @@ export function formatSpace({
117118
export function buildWhereQuery(fields, alias, where) {
118119
let query: any = '';
119120
const params: any[] = [];
121+
120122
Object.entries(fields).forEach(([field, type]) => {
123+
if (type === 'EVMAddress') {
124+
const conditions = ['', '_not', '_in', '_not_in'];
125+
try {
126+
conditions.forEach(condition => {
127+
const key = `${field}${condition}`;
128+
if (where[key]) {
129+
where[key] = condition.includes('in')
130+
? where[key].map(getAddress)
131+
: getAddress(where[key]);
132+
}
133+
});
134+
} catch (e) {
135+
throw new PublicError(`Invalid ${field} address`);
136+
}
137+
}
121138
if (where[field] !== undefined) {
122139
query += `AND ${alias}.${field} = ? `;
123140
params.push(where[field]);

src/graphql/operations/votes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function query(parent, args, context?, info?) {
2121
id: 'string',
2222
ipfs: 'string',
2323
space: 'string',
24-
voter: 'string',
24+
voter: 'EVMAddress',
2525
proposal: 'string',
2626
reason: 'string',
2727
app: 'string',

0 commit comments

Comments
 (0)