Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/connect/.env.development
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
VITE_HYPERGRAPH_SYNC_SERVER_ORIGIN="http://localhost:3030"
VITE_HYPERGRAPH_SYNC_SERVER_ORIGIN="http://localhost:3030"
VITE_HYPERGRAPH_CHAIN="geogenesis"
VITE_HYPERGRAPH_API_URL="https://hypergraph-v2.up.railway.app/graphql"
VITE_HYPERGRAPH_RPC_URL="https://rpc-geo-genesis-h0q2s21xx8.t.conduit.xyz"
5 changes: 4 additions & 1 deletion apps/connect/.env.production
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
VITE_HYPERGRAPH_SYNC_SERVER_ORIGIN="https://syncserver.hypergraph.thegraph.com"
VITE_HYPERGRAPH_SYNC_SERVER_ORIGIN="https://syncserver.hypergraph.thegraph.com"
VITE_HYPERGRAPH_CHAIN="geogenesis"
VITE_HYPERGRAPH_API_URL="https://hypergraph-v2.up.railway.app/graphql"
VITE_HYPERGRAPH_RPC_URL="https://rpc-geo-genesis-h0q2s21xx8.t.conduit.xyz"
1 change: 1 addition & 0 deletions apps/connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"clsx": "^2.1.1",
"effect": "^3.16.3",
"framer-motion": "^12.10.1",
"graphql-request": "^7.2.0",
"lucide-react": "^0.508.0",
"react": "^19.1.0",
"react-dom": "^19.1.0",
Expand Down
1 change: 1 addition & 0 deletions apps/connect/src/components/create-space.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function CreateSpace() {

const message: Messages.RequestConnectCreateSpaceEvent = {
type: 'connect-create-space-event',
accountAddress,
event: spaceEvent,
spaceId: spaceEvent.transaction.id,
keyBox: {
Expand Down
4 changes: 2 additions & 2 deletions apps/connect/src/components/spaces.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useSpaces } from '@/hooks/use-spaces';
import { usePrivateSpaces } from '@/hooks/use-private-spaces';

export function Spaces() {
const { isPending, error, data } = useSpaces();
const { isPending, error, data } = usePrivateSpaces();

return (
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getAppInfoByIds } from '@/lib/get-app-info-by-ids';
import { Connect } from '@graphprotocol/hypergraph';
import { useIdentityToken } from '@privy-io/react-auth';
import { useQuery } from '@tanstack/react-query';
import { type UseQueryResult, useQuery } from '@tanstack/react-query';

type SpaceData = {
id: string;
Expand All @@ -15,15 +16,17 @@ type SpaceData = {
}[];
};

export const useSpaces = () => {
export const usePrivateSpaces = (): UseQueryResult<SpaceData[], Error> => {
const { identityToken } = useIdentityToken();

return useQuery<SpaceData[]>({
queryKey: ['spaces'],
queryKey: ['private-spaces'],
queryFn: async () => {
if (!identityToken) return [];
const accountAddress = Connect.loadAccountAddress(localStorage);
if (!accountAddress) return [];
const response = await fetch(`${import.meta.env.VITE_HYPERGRAPH_SYNC_SERVER_ORIGIN}/connect/spaces`, {
headers: { 'privy-id-token': identityToken },
headers: { 'privy-id-token': identityToken, 'account-address': accountAddress },
});
const data = await response.json();
const appIds = new Set<string>();
Expand Down
63 changes: 63 additions & 0 deletions apps/connect/src/hooks/use-public-spaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Connect } from '@graphprotocol/hypergraph';
import { type UseQueryResult, useQuery } from '@tanstack/react-query';
import { gql, request } from 'graphql-request';

const publicSpacesQueryDocument = gql`
query Spaces($accountAddress: String!) {
spaces(filter: {
member: { is: $accountAddress }
}) {
id
type
mainVotingAddress
personalAddress
entity {
name
}
}
}
`;

type SpaceQueryResult = {
id: string;
type: string;
mainVotingAddress: string;
personalAddress: string;
entity: {
name: string;
};
};

type PublicSpacesQueryResult = {
spaces: SpaceQueryResult[];
};

export type PublicSpaceData = {
id: string;
type: string;
mainVotingAddress: string;
personalAddress: string;
name: string;
};

export const usePublicSpaces = (url: string): UseQueryResult<PublicSpaceData[], Error> => {
return useQuery<PublicSpaceData[]>({
queryKey: ['public-spaces'],
queryFn: async () => {
const accountAddress = Connect.loadAccountAddress(localStorage);
if (!accountAddress) return [];
const result = await request<PublicSpacesQueryResult>(url, publicSpacesQueryDocument, {
accountAddress,
});
return result?.spaces
? result.spaces.map((space: SpaceQueryResult) => ({
id: space.id,
name: space.entity.name,
type: space.type,
mainVotingAddress: space.mainVotingAddress,
personalAddress: space.personalAddress,
}))
: [];
},
});
};
Loading
Loading