mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-28 17:50:28 +08:00
Remove deprecated the Graph queries
We have run out of funds on the Graph and the org functionality in its current form is deprecated. Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
+5
-66
@@ -8,42 +8,6 @@ import * as cache from "@app/cache";
|
||||
import type { Safe } from "@app/utils";
|
||||
import type { Config } from "@app/config";
|
||||
|
||||
const GetSafesByOwners = `
|
||||
query GetSafesByOwners($owners: [String!]!) {
|
||||
safes(where: { owners_contains: $owners }) {
|
||||
id
|
||||
owners
|
||||
threshold
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const GetOrgsByOwners = `
|
||||
query GetOrgsByOwners($owners: [String!]!) {
|
||||
orgs(where: { owner_in: $owners }) {
|
||||
id
|
||||
owner
|
||||
safe {
|
||||
id
|
||||
owners
|
||||
threshold
|
||||
}
|
||||
creator
|
||||
timestamp
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const GetSafe = `
|
||||
query GetSafe($addr: ID!) {
|
||||
safe(id: $addr) {
|
||||
id
|
||||
owners
|
||||
threshold
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export class Org {
|
||||
address: string;
|
||||
owner: string;
|
||||
@@ -193,36 +157,11 @@ export class Org {
|
||||
}
|
||||
}
|
||||
|
||||
static async getOrgsByMember(owner: string, config: Config): Promise<Org[]> {
|
||||
type Safe = { id: string; owners: string[]; threshold: number };
|
||||
|
||||
// TODO: We use two subgraph queries since we can't do a filter query yet in the subgraph
|
||||
// https://github.com/graphprotocol/graph-node/issues/2539#issuecomment-855979841
|
||||
const safesByOwner = await utils.querySubgraph(
|
||||
config.orgs.subgraph,
|
||||
GetSafesByOwners,
|
||||
{ owners: [owner] },
|
||||
);
|
||||
|
||||
let safes = [];
|
||||
if (safesByOwner && safesByOwner.safes.length > 0) {
|
||||
safes = safesByOwner.safes.reduce(
|
||||
(prev: any, curr: Safe) => prev.concat(curr.id),
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
||||
const orgsByOwner = await utils.querySubgraph(
|
||||
config.orgs.subgraph,
|
||||
GetOrgsByOwners,
|
||||
{ owners: [...safes, owner] },
|
||||
);
|
||||
let orgs: { id: string; owner: string }[] = [];
|
||||
if (orgsByOwner && orgsByOwner.orgs) {
|
||||
orgs = [...orgsByOwner.orgs];
|
||||
}
|
||||
|
||||
return orgs.map(o => new Org(o.id, o.owner));
|
||||
static async getOrgsByMember(
|
||||
_owner: string,
|
||||
_config: Config,
|
||||
): Promise<Org[]> {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
"address": "0xa15bEb4876F20018b6b4A4116B7560c5fcC9336e"
|
||||
},
|
||||
"orgs": {
|
||||
"subgraph": "https://gateway.thegraph.com/api/1758a78ae257ad4906f9c638e4a68c19/subgraphs/id/0x2f0963e77ca6ac0c2dad1bf4147b6b40e0dd8728-0",
|
||||
"contractHash": "0x5c34bb0755876de98e801805e6685456eea739ad0abba1cc450a7ee0f2a70b74",
|
||||
"pinned": [
|
||||
"alt-clients.radicle.eth",
|
||||
@@ -49,7 +48,6 @@
|
||||
"address": "0xF3D04e874D07d680e8b26332eEae5b9B1c263121"
|
||||
},
|
||||
"orgs": {
|
||||
"subgraph": "https://api.thegraph.com/subgraphs/name/radicle-dev/radicle-orgs-rinkeby",
|
||||
"contractHash": "0x5c34bb0755876de98e801805e6685456eea739ad0abba1cc450a7ee0f2a70b74",
|
||||
"pinned": []
|
||||
},
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ export class Config {
|
||||
radToken: { address: string; faucet: string };
|
||||
orgFactory: { address: string };
|
||||
reverseRegistrar: { address: string };
|
||||
orgs: { subgraph: string; contractHash: string; pinned: string[] };
|
||||
orgs: { contractHash: string; pinned: string[] };
|
||||
users: { pinned: string[] };
|
||||
projects: { pinned: { urn: string; name: string; seed: string }[] };
|
||||
seeds: { pinned: Record<string, { emoji: string }> };
|
||||
|
||||
+6
-64
@@ -21,7 +21,6 @@ import {
|
||||
} from "@app/base/registrations/registrar";
|
||||
import { ProfileType } from "@app/profile";
|
||||
import { parseUnits } from "@ethersproject/units";
|
||||
import { GetSafe } from "@app/base/orgs/Org";
|
||||
import * as cache from "@app/cache";
|
||||
import type { marked } from "marked";
|
||||
import emojis from "@app/emojis";
|
||||
@@ -358,45 +357,6 @@ export function safeLink(addr: string, config: Config): string {
|
||||
return explorerLink(addr, config);
|
||||
}
|
||||
|
||||
// Query a subgraph.
|
||||
export async function querySubgraphWithRetry(
|
||||
url: string,
|
||||
query: string,
|
||||
variables: Record<string, any>,
|
||||
retries = 3,
|
||||
): Promise<Record<string, any> | null> {
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query,
|
||||
variables,
|
||||
}),
|
||||
});
|
||||
const json = await response.json();
|
||||
|
||||
if (json.errors) {
|
||||
console.error("querySubgraph:", json.errors);
|
||||
|
||||
if (retries > 0) {
|
||||
return querySubgraphWithRetry(url, query, variables, retries - 1);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return json.data;
|
||||
}
|
||||
}
|
||||
|
||||
export const querySubgraph = cache.cached(
|
||||
querySubgraphWithRetry,
|
||||
(url: string, query: string, variables: Record<string, any>) =>
|
||||
JSON.stringify({ url, query, variables }),
|
||||
{ max: 500, ttl: 5 * 60 * 1000 }, // Cache results for 5 minutes.
|
||||
);
|
||||
|
||||
// Format a name.
|
||||
export function formatName(input: string, config: Config): string {
|
||||
return parseEnsLabel(input, config);
|
||||
@@ -558,36 +518,18 @@ export async function resolveEnsProfile(
|
||||
|
||||
// Check whether a Gnosis Safe exists at an address.
|
||||
export async function isSafe(
|
||||
address: string,
|
||||
config: Config,
|
||||
_address: string,
|
||||
_config: Config,
|
||||
): Promise<boolean> {
|
||||
// For the subgraph we need to pass a lowercase address
|
||||
const query = await querySubgraph(config.orgs.subgraph, GetSafe, {
|
||||
addr: address.toLowerCase(),
|
||||
});
|
||||
|
||||
return Boolean(query?.safe);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get a Gnosis Safe at an address.
|
||||
export async function getSafe(
|
||||
address: string,
|
||||
config: Config,
|
||||
_address: string,
|
||||
_config: Config,
|
||||
): Promise<Safe | null> {
|
||||
// For the subgraph we need to pass a lowercase address
|
||||
const query = await querySubgraph(config.orgs.subgraph, GetSafe, {
|
||||
addr: address.toLowerCase(),
|
||||
});
|
||||
|
||||
if (!query?.safe) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
address: query.safe.id,
|
||||
owners: query.safe.owners,
|
||||
threshold: query.safe.threshold,
|
||||
};
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get token balances for an address.
|
||||
|
||||
Reference in New Issue
Block a user