Remove usage of Gnosis Safe subgraph

This commit is contained in:
Alexis Sellier
2021-07-20 14:33:38 +02:00
parent 77145b1359
commit 1aff1f8013
4 changed files with 20 additions and 18 deletions
+2 -14
View File
@@ -29,15 +29,6 @@ const GetOrgs = `
}
`;
const GetSafes = `
query GetSafes($owners: [String!]!) {
wallets(where: { owners_contains: $owners }) {
id
owners
}
}
`;
const GetOrgsByOwner = `
query GetOrgsByOwner($owners: [String!]!) {
orgs(where: { owner_in: $owners }) {
@@ -225,11 +216,8 @@ export class Org {
}
static async getOrgsByMember(memberAddr: string, config: Config): Promise<Org[]> {
const safeResult = await utils.querySubgraph(
config.safe.subgraph, GetSafes, { owners: [memberAddr] }
);
const wallets: { id: string }[] = safeResult.wallets;
const owners = wallets.map(wallet => wallet.id).concat([memberAddr]);
const wallets = await utils.getOwnerSafes(memberAddr, config);
const owners = wallets?.concat([memberAddr]);
const orgsResult = await utils.querySubgraph(config.orgs.subgraph, GetOrgsByOwner, { owners });
return orgsResult.orgs.map((o: { id: string; owner: string }) => {
-3
View File
@@ -16,7 +16,6 @@
},
"safe": {
"api": "https://safe-transaction.gnosis.io",
"subgraph": "https://api.thegraph.com/subgraphs/name/radicle-dev/gnosis-safe",
"viewer": "https://gnosis-safe.io/app/#/safes"
},
"tokens": []
@@ -38,7 +37,6 @@
},
"safe": {
"api": null,
"subgraph": null,
"viewer": null
},
"tokens": []
@@ -60,7 +58,6 @@
},
"safe": {
"api": "https://safe-transaction.rinkeby.gnosis.io",
"subgraph": "https://api.thegraph.com/subgraphs/name/radicle-dev/gnosis-safe-rinkeby",
"viewer": "https://rinkeby.gnosis-safe.io/app/#/safes"
},
"tokens": []
-1
View File
@@ -24,7 +24,6 @@ export class Config {
safe: {
api?: string;
client?: SafeServiceClient;
subgraph: string;
viewer: string | null;
};
abi: { [contract: string]: string[] };
+18
View File
@@ -266,6 +266,24 @@ export async function getSafe(address: string, config: Config): Promise<Safe | n
};
}
// Get the Gnosis Safe addresses owned by the given address.
export async function getOwnerSafes(owner: string, config: Config): Promise<string[] | null> {
if (! config.safe.api) return null;
const addr = ethers.utils.getAddress(owner);
const response = await fetch(`${config.safe.api}/api/v1/owners/${addr}/safes/`, {
method: 'GET',
headers: { 'Accept': 'application/json' }
});
if (! response.ok) {
return null;
}
const json = await response.json();
return json.safes;
}
// Get token balances for an address.
export async function getTokens(address: string, config: Config):
Promise<Array<{ tokenName: string; tokenLogo: string }>>