Skip to content

Commit

Permalink
feat: return fields from networks.json in network operation
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Oct 19, 2023
1 parent 90a83e6 commit 0ca5df0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/graphql/operations/networks.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import { capture } from '@snapshot-labs/snapshot-sentry';
import networks from '@snapshot-labs/snapshot.js/src/networks.json';
import db from '../../helpers/mysql';

export default async function () {
const query = `
SELECT
JSON_UNQUOTE(JSON_EXTRACT(settings, '$.network')) as network,
COUNT(name) AS spacesCount
COUNT(name) AS count
FROM spaces
GROUP BY network
ORDER BY spacesCount DESC;
ORDER BY count DESC;
`;

try {
return (await db.queryAsync(query)).map(v => ({ ...v, id: v.network }));
const results = new Map(await db.queryAsync(query).map(r => [r.network, r.count]));

return Object.values(networks)
.map((network: any) => {
network.id = network.key;
network.spacesCount = results.get(network.id) || 0;
network.testnet ||= false;
return network;
})
.sort((a, b) => b.spacesCount - a.spacesCount);
} catch (e: any) {
capture(e);
return Promise.reject(new Error('request failed'));
Expand Down
19 changes: 18 additions & 1 deletion src/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type Query {

skins: [Item]

networks: [Item]
networks: [Network]

validations: [Item]

Expand Down Expand Up @@ -555,3 +555,20 @@ type Vp {
vp_by_strategy: [Float]
vp_state: String
}

type Network {
key: String
id: String
spacesCount: Int
name: String
chainId: String
network: String
explorer: NetworkExplorer
logo: String
testnet: Boolean
}

type NetworkExplorer {
url: String
apiUrl: String
}

0 comments on commit 0ca5df0

Please sign in to comment.