-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,10 @@ const QUERY = ` | |
} | ||
} | ||
} | ||
annotations { | ||
url | ||
schema | ||
} | ||
} | ||
} | ||
` | ||
|
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,76 @@ | ||
import SUBGRAPH from "./subgraph" | ||
import { ChainId, Target } from "./types" | ||
|
||
interface Props { | ||
address: string | ||
chainId: ChainId | ||
} | ||
|
||
const QUERY = ` | ||
query RolesMod($id: String) { | ||
rolesModifier(id: $id) { | ||
address | ||
owner | ||
avatar | ||
target | ||
roles { | ||
members { | ||
member { | ||
address | ||
} | ||
} | ||
targets { | ||
address | ||
} | ||
} | ||
} | ||
} | ||
` | ||
|
||
export const fetchRolesMod = async ({ | ||
address, | ||
chainId, | ||
}: Props): Promise<RolesModifier> => { | ||
const res = await fetch(SUBGRAPH[chainId], { | ||
method: "POST", | ||
body: JSON.stringify({ | ||
query: QUERY, | ||
variables: { id: address.toLowerCase() }, | ||
operationName: "Roles", | ||
}), | ||
}) | ||
const { data, error } = await res.json() | ||
if (error) { | ||
throw new Error(error) | ||
} | ||
if (!data || !data.rolesModifier) { | ||
throw new Error(`Roles modifier ${address} not found on chain #${chainId}`) | ||
} | ||
|
||
return mapGraphQl(data.rolesModifier) | ||
} | ||
|
||
interface RoleSummary { | ||
key: string | ||
members: `0x${string}`[] | ||
targets: `0x${string}`[] | ||
} | ||
|
||
interface RolesModifier { | ||
address: `0x${string}` | ||
owner: `0x${string}` | ||
avatar: `0x${string}` | ||
target: `0x${string}` | ||
roles: RoleSummary[] | ||
} | ||
|
||
const mapGraphQl = (rolesModifier: any): RolesModifier => ({ | ||
...rolesModifier, | ||
roles: rolesModifier.roles.map(mapGraphQlRole), | ||
}) | ||
|
||
const mapGraphQlRole = (role: any): RoleSummary => ({ | ||
key: role.key, | ||
members: role.members.map((assignment: any) => assignment.member.address), | ||
targets: role.targets.map((target: any): Target => target.address), | ||
}) |
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