From 1aff1f801378d90f495883049eb69967f47aa404 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Tue, 20 Jul 2021 14:33:38 +0200 Subject: [PATCH] Remove usage of Gnosis Safe subgraph --- src/base/orgs/Org.ts | 16 ++-------------- src/config.json | 3 --- src/config.ts | 1 - src/utils.ts | 18 ++++++++++++++++++ 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/base/orgs/Org.ts b/src/base/orgs/Org.ts index 3d08dd61e..488d80ef1 100644 --- a/src/base/orgs/Org.ts +++ b/src/base/orgs/Org.ts @@ -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 { - 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 }) => { diff --git a/src/config.json b/src/config.json index 9250563bf..942c50174 100644 --- a/src/config.json +++ b/src/config.json @@ -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": [] diff --git a/src/config.ts b/src/config.ts index f3749c2d0..ebf93806f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -24,7 +24,6 @@ export class Config { safe: { api?: string; client?: SafeServiceClient; - subgraph: string; viewer: string | null; }; abi: { [contract: string]: string[] }; diff --git a/src/utils.ts b/src/utils.ts index ca913e6ac..22d2c0598 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -266,6 +266,24 @@ export async function getSafe(address: string, config: Config): Promise { + 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>