-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from orcaprotocol/willkim/fetch-supers
feat: add get super pod/proposal
- Loading branch information
Showing
4 changed files
with
224 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import axios from 'axios'; | ||
import { config } from '../../config'; | ||
|
||
/** | ||
* Returns an array of addresses of all pod members. | ||
* @param id | ||
*/ | ||
export async function fetchPodUsers(id: number): Promise<string[]> { | ||
const { data } = await axios.post(config.subgraphUrl, { | ||
query: `query GetPodUsers($id: ID!) { | ||
pod(id: $id) { | ||
users { | ||
user { | ||
id | ||
} | ||
} | ||
} | ||
}`, | ||
variables: { id }, | ||
}); | ||
const { users } = data.data.pod || { users: [] }; | ||
return users.map(user => user.user.id); | ||
} | ||
|
||
/** | ||
* Returns a list of Pod IDs from subgraph that user is a member of. | ||
* @param address | ||
*/ | ||
export async function fetchUserPodIds(address: string): Promise<number[]> { | ||
const { data } = await axios.post(config.subgraphUrl, { | ||
query: `query GetUserPods($id: ID!) { | ||
user(id: $id) { | ||
pods { | ||
id | ||
pod { | ||
id | ||
} | ||
} | ||
} | ||
}`, | ||
variables: { id: address.toLowerCase() }, | ||
}); | ||
const { pods } = data?.data?.user || { pods: [] }; | ||
// Remove GraphQL nested layer for UserPod | ||
const podIds = pods.map(({ pod }) => parseInt(pod.id, 10)); | ||
return podIds; | ||
} | ||
|
||
/** | ||
* Returns an array of Pod IDs from sub graph that an address is the admin of | ||
* @param address | ||
*/ | ||
export async function fetchAdminPodIds(address: string): Promise<number[]> { | ||
const { data } = await axios.post(config.subgraphUrl, { | ||
query: `query GetUserPods($id: ID!) { | ||
user(id: $id) { | ||
adminPods | ||
} | ||
}`, | ||
variables: { id: address.toLowerCase() }, | ||
}); | ||
const { adminPods } = data.data.user || { adminPods: [] }; | ||
const podIds = adminPods.map(pod => parseInt(pod, 10)); | ||
return podIds; | ||
} |
Oops, something went wrong.