Skip to content

Commit 063c6af

Browse files
authored
Pcv/smart account (#214)
1 parent 0609380 commit 063c6af

38 files changed

Lines changed: 4134 additions & 284 deletions

apps/connect/.env.development

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
VITE_HYPERGRAPH_SYNC_SERVER_ORIGIN="http://localhost:3030"
1+
VITE_HYPERGRAPH_SYNC_SERVER_ORIGIN="http://localhost:3030"
2+
VITE_HYPERGRAPH_CHAIN="geogenesis"
3+
VITE_HYPERGRAPH_API_URL="https://hypergraph-v2.up.railway.app/graphql"
4+
VITE_HYPERGRAPH_RPC_URL="https://rpc-geo-genesis-h0q2s21xx8.t.conduit.xyz"

apps/connect/.env.production

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
VITE_HYPERGRAPH_SYNC_SERVER_ORIGIN="https://syncserver.hypergraph.thegraph.com"
1+
VITE_HYPERGRAPH_SYNC_SERVER_ORIGIN="https://syncserver.hypergraph.thegraph.com"
2+
VITE_HYPERGRAPH_CHAIN="geogenesis"
3+
VITE_HYPERGRAPH_API_URL="https://hypergraph-v2.up.railway.app/graphql"
4+
VITE_HYPERGRAPH_RPC_URL="https://rpc-geo-genesis-h0q2s21xx8.t.conduit.xyz"

apps/connect/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"clsx": "^2.1.1",
2222
"effect": "^3.16.3",
2323
"framer-motion": "^12.10.1",
24+
"graphql-request": "^7.2.0",
2425
"lucide-react": "^0.508.0",
2526
"react": "^19.1.0",
2627
"react-dom": "^19.1.0",

apps/connect/src/components/create-space.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export function CreateSpace() {
5454

5555
const message: Messages.RequestConnectCreateSpaceEvent = {
5656
type: 'connect-create-space-event',
57+
accountAddress,
5758
event: spaceEvent,
5859
spaceId: spaceEvent.transaction.id,
5960
keyBox: {

apps/connect/src/components/spaces.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { useSpaces } from '@/hooks/use-spaces';
1+
import { usePrivateSpaces } from '@/hooks/use-private-spaces';
22

33
export function Spaces() {
4-
const { isPending, error, data } = useSpaces();
4+
const { isPending, error, data } = usePrivateSpaces();
55

66
return (
77
<div>

apps/connect/src/hooks/use-spaces.ts renamed to apps/connect/src/hooks/use-private-spaces.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getAppInfoByIds } from '@/lib/get-app-info-by-ids';
2+
import { Connect } from '@graphprotocol/hypergraph';
23
import { useIdentityToken } from '@privy-io/react-auth';
3-
import { useQuery } from '@tanstack/react-query';
4+
import { type UseQueryResult, useQuery } from '@tanstack/react-query';
45

56
type SpaceData = {
67
id: string;
@@ -15,15 +16,17 @@ type SpaceData = {
1516
}[];
1617
};
1718

18-
export const useSpaces = () => {
19+
export const usePrivateSpaces = (): UseQueryResult<SpaceData[], Error> => {
1920
const { identityToken } = useIdentityToken();
2021

2122
return useQuery<SpaceData[]>({
22-
queryKey: ['spaces'],
23+
queryKey: ['private-spaces'],
2324
queryFn: async () => {
2425
if (!identityToken) return [];
26+
const accountAddress = Connect.loadAccountAddress(localStorage);
27+
if (!accountAddress) return [];
2528
const response = await fetch(`${import.meta.env.VITE_HYPERGRAPH_SYNC_SERVER_ORIGIN}/connect/spaces`, {
26-
headers: { 'privy-id-token': identityToken },
29+
headers: { 'privy-id-token': identityToken, 'account-address': accountAddress },
2730
});
2831
const data = await response.json();
2932
const appIds = new Set<string>();
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { Connect } from '@graphprotocol/hypergraph';
2+
import { type UseQueryResult, useQuery } from '@tanstack/react-query';
3+
import { gql, request } from 'graphql-request';
4+
5+
const publicSpacesQueryDocument = gql`
6+
query Spaces($accountAddress: String!) {
7+
spaces(filter: {
8+
member: { is: $accountAddress }
9+
}) {
10+
id
11+
type
12+
mainVotingAddress
13+
personalAddress
14+
entity {
15+
name
16+
}
17+
}
18+
}
19+
`;
20+
21+
type SpaceQueryResult = {
22+
id: string;
23+
type: string;
24+
mainVotingAddress: string;
25+
personalAddress: string;
26+
entity: {
27+
name: string;
28+
};
29+
};
30+
31+
type PublicSpacesQueryResult = {
32+
spaces: SpaceQueryResult[];
33+
};
34+
35+
export type PublicSpaceData = {
36+
id: string;
37+
type: string;
38+
mainVotingAddress: string;
39+
personalAddress: string;
40+
name: string;
41+
};
42+
43+
export const usePublicSpaces = (url: string): UseQueryResult<PublicSpaceData[], Error> => {
44+
return useQuery<PublicSpaceData[]>({
45+
queryKey: ['public-spaces'],
46+
queryFn: async () => {
47+
const accountAddress = Connect.loadAccountAddress(localStorage);
48+
if (!accountAddress) return [];
49+
const result = await request<PublicSpacesQueryResult>(url, publicSpacesQueryDocument, {
50+
accountAddress,
51+
});
52+
return result?.spaces
53+
? result.spaces.map((space: SpaceQueryResult) => ({
54+
id: space.id,
55+
name: space.entity.name,
56+
type: space.type,
57+
mainVotingAddress: space.mainVotingAddress,
58+
personalAddress: space.personalAddress,
59+
}))
60+
: [];
61+
},
62+
});
63+
};

0 commit comments

Comments
 (0)