Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Remove usage of Gnosis Safe subgraph
Alexis Sellier committed 4 years ago
commit 1aff1f801378d90f495883049eb69967f47aa404
parent 77145b13593dcb1314cc83acc4f4d3c135a8297e
4 files changed +20 -18
modified 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<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 }) => {
modified 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": []
modified src/config.ts
@@ -24,7 +24,6 @@ export class Config {
  safe: {
    api?: string;
    client?: SafeServiceClient;
-
    subgraph: string;
    viewer: string | null;
  };
  abi: { [contract: string]: string[] };
modified src/utils.ts
@@ -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 }>>