-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eng 61 update subgraph endpoints #2708
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
fac0260
Remove a bunch of graphql / apollo stuff from package.json
adamgall 5c2d4a4
Install urql and graphql packages
adamgall d35d015
First pass through of replacing apollo with urql
adamgall daa7538
Remove some more apollo specific configs
adamgall fa72e20
Add more Decent and Sablier config data to the network config files
adamgall fb5481b
Refactor GraphQL client creation and remove URQL provider
adamgall 6208a14
Merge branch 'develop' into ENG-61_update-subgraph-endpoints
adamgall 2380ba3
Remove network-only request policy from GraphQL queries
adamgall 992ea20
Refactor GraphQL queries and client management
adamgall 1548b20
Update GraphQL query names and imports across multiple files
adamgall 9ef3dbb
Rename GraphQL client creation functions for clarity
adamgall b3e7cae
Rename subgraph configuration type and update network configs
adamgall a4d2cac
Remove version from TheGraphConfig and update subgraph URLs
adamgall 003cfc1
Merge branch 'develop' into ENG-61_update-subgraph-endpoints
adamgall a851c43
Update Sepolia Decent Subgraph ID
adamgall 624b344
Rename Subgraph API Key Environment Variable
adamgall 95004a5
Remove redundant build script for Cloudflare
adamgall 406b343
Add type definitions and improve GraphQL query type safety
adamgall 3b3066f
Merge branch 'develop' into ENG-61_update-subgraph-endpoints
adamgall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import { useLazyQuery } from '@apollo/client'; | ||
import { Center, Flex, Icon, Link, Text } from '@chakra-ui/react'; | ||
import { abis } from '@fractal-framework/fractal-contracts'; | ||
import { ArrowElbowDownRight } from '@phosphor-icons/react'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Link as RouterLink } from 'react-router-dom'; | ||
import { Address, getContract, zeroAddress } from 'viem'; | ||
import { DAOQueryDocument } from '../../../.graphclient'; | ||
import { SENTINEL_ADDRESS } from '../../constants/common'; | ||
import { DAO_ROUTES } from '../../constants/routes'; | ||
import { createDecentSubgraphClient } from '../../graphql'; | ||
import { DAOQuery, DAOQueryResponse } from '../../graphql/DAOQueries'; | ||
import { useDecentModules } from '../../hooks/DAO/loaders/useDecentModules'; | ||
import useNetworkPublicClient from '../../hooks/useNetworkPublicClient'; | ||
import { CacheKeys } from '../../hooks/utils/cache/cacheDefaults'; | ||
import { setValue, getValue } from '../../hooks/utils/cache/useLocalStorage'; | ||
import { getValue, setValue } from '../../hooks/utils/cache/useLocalStorage'; | ||
import { useAddressContractType } from '../../hooks/utils/useAddressContractType'; | ||
import { useSafeAPI } from '../../providers/App/hooks/useSafeAPI'; | ||
import { useNetworkConfigStore } from '../../providers/NetworkConfig/useNetworkConfigStore'; | ||
|
@@ -31,6 +31,7 @@ import { BarLoader } from '../ui/loaders/BarLoader'; | |
* From this initial DAO info, the component will get the DAO's children | ||
* and display another DaoNode for each child, and so on for their children. | ||
*/ | ||
|
||
export function DaoHierarchyNode({ | ||
safeAddress, | ||
depth, | ||
|
@@ -43,20 +44,12 @@ export function DaoHierarchyNode({ | |
const safeApi = useSafeAPI(); | ||
const [hierarchyNode, setHierarchyNode] = useState<DaoHierarchyInfo>(); | ||
const [hasErrorLoading, setErrorLoading] = useState<boolean>(false); | ||
const { addressPrefix, subgraph, chain } = useNetworkConfigStore(); | ||
const { addressPrefix, getConfigByChainId, chain } = useNetworkConfigStore(); | ||
const publicClient = useNetworkPublicClient(); | ||
|
||
const { getAddressContractType } = useAddressContractType(); | ||
const lookupModules = useDecentModules(); | ||
|
||
const [getDAOInfo] = useLazyQuery(DAOQueryDocument, { | ||
context: { | ||
subgraphSpace: subgraph.space, | ||
subgraphSlug: subgraph.slug, | ||
subgraphVersion: subgraph.version, | ||
}, | ||
}); | ||
|
||
const getVotingStrategies = useCallback( | ||
async (azoriusModule: DecentModule) => { | ||
const azoriusContract = getContract({ | ||
|
@@ -127,21 +120,38 @@ export function DaoHierarchyNode({ | |
} | ||
try { | ||
const safe = await safeApi.getSafeInfo(_safeAddress); | ||
const graphRawNodeData = await getDAOInfo({ variables: { safeAddress: _safeAddress } }); | ||
|
||
const client = createDecentSubgraphClient(getConfigByChainId(chain.id)); | ||
const queryResult = await client.query<DAOQueryResponse>(DAOQuery, { | ||
safeAddress: _safeAddress, | ||
}); | ||
|
||
if (queryResult.error) { | ||
throw new Error('Query failed'); | ||
} | ||
|
||
if (!queryResult.data) { | ||
throw new Error('No data found'); | ||
} | ||
|
||
const modules = await lookupModules(safe.modules); | ||
const graphDAOData = graphRawNodeData.data?.daos[0]; | ||
const graphDAOData = queryResult.data.daos[0]; | ||
const azoriusModule = getAzoriusModuleFromModules(modules ?? []); | ||
const votingStrategies: DaoHierarchyStrategyType[] = azoriusModule | ||
? await getGovernanceTypes(azoriusModule) | ||
: ['MULTISIG']; | ||
if (!graphRawNodeData || !graphDAOData) { | ||
|
||
if (!graphDAOData) { | ||
throw new Error('No data found'); | ||
} | ||
|
||
return { | ||
daoName: graphDAOData.name ?? null, | ||
safeAddress: _safeAddress, | ||
parentAddress: graphDAOData.parentAddress ?? null, | ||
childAddresses: graphDAOData.hierarchy.map(child => child.address), | ||
parentAddress: graphDAOData.parentAddress as Address | null, | ||
childAddresses: graphDAOData.hierarchy.map( | ||
(child: { address: string }) => child.address as Address, | ||
), | ||
daoSnapshotENS: graphDAOData.snapshotENS ?? null, | ||
proposalTemplatesHash: graphDAOData.proposalTemplatesHash ?? null, | ||
modules, | ||
|
@@ -152,9 +162,10 @@ export function DaoHierarchyNode({ | |
return; | ||
} | ||
}, | ||
[getDAOInfo, getGovernanceTypes, lookupModules, safeApi], | ||
[getConfigByChainId, chain.id, getGovernanceTypes, lookupModules, safeApi], | ||
); | ||
|
||
// Effect to handle query result changes | ||
useEffect(() => { | ||
if (safeAddress) { | ||
const cachedNode = getValue({ | ||
|
@@ -166,9 +177,11 @@ export function DaoHierarchyNode({ | |
setHierarchyNode(cachedNode); | ||
return; | ||
} | ||
|
||
loadDao(safeAddress).then(_node => { | ||
if (!_node) { | ||
setErrorLoading(true); | ||
return; | ||
} | ||
setValue( | ||
{ | ||
|
@@ -181,8 +194,8 @@ export function DaoHierarchyNode({ | |
setHierarchyNode(_node); | ||
}); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
Comment on lines
-184
to
-185
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👀 sweet if we don't need this anymore. tested Myosin good stress tester for org page. |
||
}, [chain.id, loadDao, safeAddress]); | ||
|
||
if (!hierarchyNode) { | ||
// node hasn't loaded yet | ||
return ( | ||
|
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
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,118 @@ | ||
import { Address } from 'viem'; | ||
import { SnapshotPlugin, SnapshotProposalType } from '../types'; | ||
|
||
// Types for Extended Snapshot Proposal | ||
interface Strategy { | ||
name: string; | ||
network: string; | ||
params: Record<string, unknown>; | ||
} | ||
|
||
export interface ExtendedSnapshotProposalResponse { | ||
proposal: { | ||
snapshot: number; | ||
type: SnapshotProposalType; | ||
quorum: number; | ||
privacy: string; | ||
strategies: Strategy[]; | ||
plugins: SnapshotPlugin[]; | ||
choices: string[]; | ||
ipfs: string; | ||
}; | ||
} | ||
|
||
export interface SnapshotVote { | ||
id: string; | ||
voter: Address; | ||
vp: number; | ||
vp_by_strategy: number[]; | ||
vp_state: string; | ||
created: number; | ||
choice: number | Record<string, number>; | ||
} | ||
|
||
export interface SnapshotProposalVotesResponse { | ||
votes: SnapshotVote[]; | ||
} | ||
|
||
// Types for User Voting Weight | ||
interface VotingPower { | ||
vp: number; | ||
vp_by_strategy: number[]; | ||
vp_state: string; | ||
} | ||
|
||
export interface UserVotingWeightResponse { | ||
vp: VotingPower; | ||
} | ||
|
||
// Types for Proposals Query | ||
interface SnapshotProposal { | ||
id: string; | ||
title: string; | ||
body: string; | ||
start: number; | ||
end: number; | ||
state: string; | ||
author: Address; | ||
} | ||
|
||
export interface ProposalsResponse { | ||
proposals: SnapshotProposal[]; | ||
} | ||
|
||
export const ExtendedSnapshotProposalQuery = `query ExtendedSnapshotProposal($snapshotProposalId: String!) { | ||
proposal(id: $snapshotProposalId) { | ||
snapshot | ||
type | ||
quorum | ||
privacy | ||
strategies { | ||
name | ||
network | ||
params | ||
} | ||
plugins | ||
choices | ||
ipfs | ||
} | ||
}`; | ||
|
||
export const SnapshotProposalVotesQuery = `query SnapshotProposalVotes($snapshotProposalId: String!) { | ||
votes(where: { proposal: $snapshotProposalId }, first: 500) { | ||
id | ||
voter | ||
vp | ||
vp_by_strategy | ||
vp_state | ||
created | ||
choice | ||
} | ||
}`; | ||
|
||
export const UserVotingWeightQuery = `query UserVotingWeight($voter: String!, $space: String!, $proposal: String!) { | ||
vp(voter: $voter, space: $space, proposal: $proposal) { | ||
vp | ||
vp_by_strategy | ||
vp_state | ||
} | ||
}`; | ||
|
||
export const ProposalsQuery = `query Proposals($spaceIn: [String!]) { | ||
proposals( | ||
first: 50, | ||
where: { | ||
space_in: $spaceIn | ||
}, | ||
orderBy: "created", | ||
orderDirection: desc | ||
) { | ||
id | ||
title | ||
body | ||
start | ||
end | ||
state | ||
author | ||
} | ||
}`; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥