Skip to content

Commit 317047b

Browse files
committed
feat: use smart session client
1 parent 063c6af commit 317047b

File tree

19 files changed

+164
-113
lines changed

19 files changed

+164
-113
lines changed

apps/connect/.env.development

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
VITE_HYPERGRAPH_SYNC_SERVER_ORIGIN="http://localhost:3030"
2+
# VITE_HYPERGRAPH_CHAIN="geo-testnet"
3+
# VITE_HYPERGRAPH_API_URL="https://hypergraph-v2-testnet.up.railway.app/graphql"
4+
# VITE_HYPERGRAPH_RPC_URL="https://rpc-geo-test-zc16z3tcvf.t.conduit.xyz"
25
VITE_HYPERGRAPH_CHAIN="geogenesis"
36
VITE_HYPERGRAPH_API_URL="https://hypergraph-v2.up.railway.app/graphql"
47
VITE_HYPERGRAPH_RPC_URL="https://rpc-geo-genesis-h0q2s21xx8.t.conduit.xyz"

apps/connect/src/routes/__root.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { Logout } from '@/components/logout';
2+
import { StoreConnect } from '@graphprotocol/hypergraph';
23
import { usePrivy } from '@privy-io/react-auth';
34
import { Link, Outlet, createRootRoute, useLayoutEffect, useRouter } from '@tanstack/react-router';
45
import { TanStackRouterDevtools } from '@tanstack/router-devtools';
6+
import { useSelector } from '@xstate/store/react';
57

68
export const Route = createRootRoute({
79
component: () => {
10+
const accountAddress = useSelector(StoreConnect.store, (state) => state.context.accountAddress);
811
const { authenticated, ready } = usePrivy();
912
const router = useRouter();
1013

@@ -13,15 +16,15 @@ export const Route = createRootRoute({
1316
return;
1417
}
1518

16-
if (ready && !authenticated) {
19+
if (ready && (!authenticated || !accountAddress)) {
1720
if (router.state.location.href.startsWith('/authenticate')) {
1821
localStorage.setItem('geo-connect-authenticate-redirect', router.state.location.href);
1922
}
2023
router.navigate({
2124
to: '/login',
2225
});
2326
}
24-
}, [authenticated, ready]);
27+
}, [authenticated, ready, accountAddress]);
2528

2629
return (
2730
<>

apps/connect/src/routes/login.lazy.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function Login() {
2323

2424
const hypergraphLogin = useCallback(
2525
async (walletClient: WalletClient, embeddedWallet: ConnectedWallet) => {
26+
console.log('hypergraphLogin');
2627
if (!identityToken) {
2728
return;
2829
}
@@ -57,12 +58,14 @@ function Login() {
5758
);
5859

5960
useEffect(() => {
61+
console.log('useEffect in login.lazy.tsx');
6062
if (
6163
!hypergraphLoginStarted && // avoid re-running the effect to often
6264
privyAuthenticated && // privy must be authenticated to run it
6365
walletsReady && // wallets must be ready to run it
6466
wallets.length > 0 // wallets must have at least one wallet to run it
6567
) {
68+
console.log('running login effect');
6669
setHypergraphLoginStarted(true);
6770
(async () => {
6871
try {

apps/events/src/Boot.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ declare module '@tanstack/react-router' {
1515

1616
export function Boot() {
1717
return (
18-
<HypergraphAppProvider storage={localStorage} syncServerUri="http://localhost:3030" mapping={mapping}>
18+
<HypergraphAppProvider
19+
storage={localStorage}
20+
syncServerUri="http://localhost:3030"
21+
mapping={mapping}
22+
chainId={80451}
23+
>
1924
<RouterProvider router={router} />
2025
</HypergraphAppProvider>
2126
);

apps/events/src/components/create-events.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { getSmartAccountWalletClient } from '@/lib/smart-account';
21
import { type GeoSmartAccount, Graph, type Op } from '@graphprotocol/grc-20';
3-
import { publishOps, useHypergraphSpace } from '@graphprotocol/hypergraph-react';
2+
import { Connect } from '@graphprotocol/hypergraph';
3+
import { publishOps, useHypergraphApp, useHypergraphAuth, useHypergraphSpace } from '@graphprotocol/hypergraph-react';
44
import { Button } from './ui/button';
55

66
const createEvents = async ({
7-
smartAccountWalletClient,
7+
smartSessionClient,
88
space,
9-
}: { smartAccountWalletClient: GeoSmartAccount; space: string }) => {
9+
}: { smartSessionClient: Connect.SmartSessionClient; space: string }) => {
1010
try {
1111
const ops: Array<Op> = [];
1212

@@ -57,7 +57,7 @@ const createEvents = async ({
5757

5858
const result = await publishOps({
5959
ops,
60-
walletClient: smartAccountWalletClient,
60+
walletClient: smartSessionClient,
6161
space,
6262
name: 'Create Job Offers, Companies and Events',
6363
network: 'TESTNET',
@@ -71,18 +71,17 @@ const createEvents = async ({
7171

7272
export const CreateEvents = () => {
7373
const space = useHypergraphSpace();
74-
74+
const { getSmartSessionClient } = useHypergraphApp();
7575
return (
7676
<div>
7777
<Button
7878
onClick={async () => {
79-
const smartAccountWalletClient = await getSmartAccountWalletClient();
80-
if (!smartAccountWalletClient) {
81-
throw new Error('Missing smartAccountWalletClient');
79+
const smartSessionClient = await getSmartSessionClient();
80+
if (!smartSessionClient) {
81+
throw new Error('Missing smartSessionClient');
8282
}
8383
await createEvents({
84-
// @ts-expect-error TODO: in the future we probably only only use one smart account wallet client
85-
smartAccountWalletClient,
84+
smartSessionClient,
8685
space,
8786
});
8887
}}

apps/events/src/components/create-properties-and-types-event.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { getSmartAccountWalletClient } from '@/lib/smart-account';
2-
import { type GeoSmartAccount, Graph, type Op } from '@graphprotocol/grc-20';
3-
import { publishOps, useHypergraphSpace } from '@graphprotocol/hypergraph-react';
1+
import { Graph, type Op } from '@graphprotocol/grc-20';
2+
import type { Connect } from '@graphprotocol/hypergraph';
3+
import { publishOps, useHypergraphApp, useHypergraphSpace } from '@graphprotocol/hypergraph-react';
44
import { useState } from 'react';
55
import { Button } from './ui/button';
66
import { Card, CardContent } from './ui/card';
77

88
const createPropertiesAndTypesEvent = async ({
9-
smartAccountWalletClient,
9+
smartSessionClient,
1010
space,
11-
}: { smartAccountWalletClient: GeoSmartAccount; space: string }) => {
11+
}: { smartSessionClient: Connect.SmartSessionClient; space: string }) => {
1212
const ops: Array<Op> = [];
1313
const { id: salaryPropertyId, ops: createSalaryPropertyOps } = Graph.createProperty({
1414
dataType: 'NUMBER',
@@ -50,7 +50,7 @@ const createPropertiesAndTypesEvent = async ({
5050

5151
const result = await publishOps({
5252
ops,
53-
walletClient: smartAccountWalletClient,
53+
walletClient: smartSessionClient,
5454
space,
5555
name: 'Create properties and types',
5656
network: 'TESTNET',
@@ -69,6 +69,7 @@ const createPropertiesAndTypesEvent = async ({
6969
export const CreatePropertiesAndTypesEvent = () => {
7070
const [mapping, setMapping] = useState<string>('');
7171
const space = useHypergraphSpace();
72+
const { getSmartSessionClient } = useHypergraphApp();
7273

7374
return (
7475
<div>
@@ -81,9 +82,9 @@ export const CreatePropertiesAndTypesEvent = () => {
8182
)}
8283
<Button
8384
onClick={async () => {
84-
const smartAccountWalletClient = await getSmartAccountWalletClient();
85-
if (!smartAccountWalletClient) {
86-
throw new Error('Missing smartAccountWalletClient');
85+
const smartSessionClient = await getSmartSessionClient();
86+
if (!smartSessionClient) {
87+
throw new Error('Missing smartSessionClient');
8788
}
8889
const {
8990
eventTypeId,
@@ -93,8 +94,7 @@ export const CreatePropertiesAndTypesEvent = () => {
9394
jobOffersRelationTypeId,
9495
sponsorsRelationTypeId,
9596
} = await createPropertiesAndTypesEvent({
96-
// @ts-expect-error TODO: in the future we probably only only use one smart account wallet client
97-
smartAccountWalletClient,
97+
smartSessionClient,
9898
space,
9999
});
100100

apps/events/src/components/create-properties-and-types-todos.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { getSmartAccountWalletClient } from '@/lib/smart-account';
2-
import { type GeoSmartAccount, Graph, type Op } from '@graphprotocol/grc-20';
3-
import { publishOps, useHypergraphSpace } from '@graphprotocol/hypergraph-react';
1+
import { Graph, type Op } from '@graphprotocol/grc-20';
2+
import type { Connect } from '@graphprotocol/hypergraph';
3+
import { publishOps, useHypergraphApp, useHypergraphSpace } from '@graphprotocol/hypergraph-react';
44
import { useState } from 'react';
55
import { Button } from './ui/button';
66
import { Card, CardContent } from './ui/card';
77

88
const createPropertiesAndTypesTodos = async ({
9-
smartAccountWalletClient,
9+
smartSessionClient,
1010
space,
11-
}: { smartAccountWalletClient: GeoSmartAccount; space: string }) => {
11+
}: { smartSessionClient: Connect.SmartSessionClient; space: string }) => {
1212
const ops: Array<Op> = [];
1313
const { id: checkedPropertyId, ops: createCheckedPropertyOps } = Graph.createProperty({
1414
dataType: 'CHECKBOX',
@@ -67,7 +67,7 @@ const createPropertiesAndTypesTodos = async ({
6767

6868
const result = await publishOps({
6969
ops,
70-
walletClient: smartAccountWalletClient,
70+
walletClient: smartSessionClient,
7171
space,
7272
name: 'Create properties and types',
7373
});
@@ -87,7 +87,7 @@ const createPropertiesAndTypesTodos = async ({
8787
export const CreatePropertiesAndTypesTodos = () => {
8888
const [mapping, setMapping] = useState<string>('');
8989
const space = useHypergraphSpace();
90-
90+
const { getSmartSessionClient } = useHypergraphApp();
9191
return (
9292
<div>
9393
{mapping && (
@@ -99,9 +99,9 @@ export const CreatePropertiesAndTypesTodos = () => {
9999
)}
100100
<Button
101101
onClick={async () => {
102-
const smartAccountWalletClient = await getSmartAccountWalletClient();
103-
if (!smartAccountWalletClient) {
104-
throw new Error('Missing smartAccountWalletClient');
102+
const smartSessionClient = await getSmartSessionClient();
103+
if (!smartSessionClient) {
104+
throw new Error('Missing smartSessionClient');
105105
}
106106
const {
107107
todoTypeId,
@@ -113,7 +113,7 @@ export const CreatePropertiesAndTypesTodos = () => {
113113
websitePropertyId,
114114
amountPropertyId,
115115
} = await createPropertiesAndTypesTodos({
116-
smartAccountWalletClient,
116+
smartSessionClient,
117117
space,
118118
});
119119

apps/events/src/components/playground.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { getSmartAccountWalletClient } from '@/lib/smart-account';
2-
import { _useCreateEntityPublic, _useDeleteEntityPublic, useQuery } from '@graphprotocol/hypergraph-react';
1+
import {
2+
_useCreateEntityPublic,
3+
_useDeleteEntityPublic,
4+
useHypergraphApp,
5+
useQuery,
6+
} from '@graphprotocol/hypergraph-react';
37
import { useState } from 'react';
48
import { Event } from '../schema';
59
import { Button } from './ui/button';
@@ -15,6 +19,7 @@ export const Playground = () => {
1519
});
1620
const [isDeleting, setIsDeleting] = useState(false);
1721
const [isCreating, setIsCreating] = useState(false);
22+
const { getSmartSessionClient } = useHypergraphApp();
1823

1924
const deleteEntity = _useDeleteEntityPublic(Event, {
2025
space: '1c954768-7e14-4f0f-9396-0fe9dcd55fe8',
@@ -34,7 +39,7 @@ export const Playground = () => {
3439
disabled={isCreating}
3540
onClick={async () => {
3641
setIsCreating(true);
37-
const walletClient = await getSmartAccountWalletClient();
42+
const walletClient = await getSmartSessionClient();
3843
if (!walletClient) {
3944
alert('Wallet client not found');
4045
setIsCreating(false);
@@ -60,7 +65,7 @@ export const Playground = () => {
6065
<Button
6166
onClick={async () => {
6267
setIsDeleting(true);
63-
const walletClient = await getSmartAccountWalletClient();
68+
const walletClient = await getSmartSessionClient();
6469
if (!walletClient) {
6570
alert('Wallet client not found');
6671
return;

apps/events/src/components/todo/todos-public.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { getSmartAccountWalletClient } from '@/lib/smart-account';
21
import { Id } from '@graphprotocol/grc-20';
32
import {
43
_generateDeleteOps,
54
publishOps,
65
useCreateEntity,
6+
useHypergraphApp,
77
useHypergraphSpace,
88
useQuery,
99
} from '@graphprotocol/hypergraph-react';
@@ -14,6 +14,7 @@ import { Button } from '../ui/button';
1414

1515
export const TodosPublic = () => {
1616
const space = useHypergraphSpace();
17+
const { getSmartSessionClient } = useHypergraphApp();
1718
const {
1819
data: dataPublic,
1920
isLoading: isLoadingPublic,
@@ -50,14 +51,14 @@ export const TodosPublic = () => {
5051

5152
<Button
5253
onClick={async () => {
53-
const smartAccountWalletClient = await getSmartAccountWalletClient();
54-
if (!smartAccountWalletClient) {
55-
throw new Error('Missing smartAccountWalletClient');
54+
const smartSessionClient = await getSmartSessionClient();
55+
if (!smartSessionClient) {
56+
throw new Error('Missing smartSessionClient');
5657
}
5758
const ops = await _generateDeleteOps({ id: todo.id, space });
5859
const result = await publishOps({
5960
ops,
60-
walletClient: smartAccountWalletClient,
61+
walletClient: smartSessionClient,
6162
space,
6263
name: 'Delete Todo',
6364
});
@@ -70,9 +71,9 @@ export const TodosPublic = () => {
7071
))}
7172
<Button
7273
onClick={async () => {
73-
const smartAccountWalletClient = await getSmartAccountWalletClient();
74-
if (!smartAccountWalletClient) {
75-
throw new Error('Missing smartAccountWalletClient');
74+
const smartSessionClient = await getSmartSessionClient();
75+
if (!smartSessionClient) {
76+
throw new Error('Missing smartSessionClient');
7677
}
7778
const userId = Id.Id('8zPJjTGLBDPtUcj6q2tghg');
7879
const todo = createTodo({
@@ -89,7 +90,7 @@ export const TodosPublic = () => {
8990
console.log('ops', ops);
9091
const result = await publishOps({
9192
ops,
92-
walletClient: smartAccountWalletClient,
93+
walletClient: smartSessionClient,
9394
space,
9495
name: 'Create Todo',
9596
});

apps/events/src/components/todos2.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { getSmartAccountWalletClient } from '@/lib/smart-account';
21
import { cn } from '@/lib/utils';
32
import type { PublishDiffInfo } from '@graphprotocol/hypergraph-react';
43
import {
54
PublishDiff,
65
publishOps,
76
useCreateEntity,
87
useDeleteEntity,
8+
useHypergraphApp,
99
useHypergraphSpace,
1010
useQuery,
1111
useUpdateEntity,
@@ -35,6 +35,7 @@ export const Todos2 = () => {
3535
// preparePublish: preparePublishUsers,
3636
} = useQuery(User, { mode: 'private' });
3737
const space = useHypergraphSpace();
38+
const { getSmartSessionClient } = useHypergraphApp();
3839
const createTodo = useCreateEntity(Todo2);
3940
const updateTodo = useUpdateEntity(Todo2);
4041
const createUser = useCreateEntity(User);
@@ -216,9 +217,9 @@ export const Todos2 = () => {
216217
<Button
217218
onClick={async () => {
218219
try {
219-
const smartAccountWalletClient = await getSmartAccountWalletClient();
220-
if (!smartAccountWalletClient) {
221-
throw new Error('Missing smartAccountWalletClient');
220+
const smartSessionClient = await getSmartSessionClient();
221+
if (!smartSessionClient) {
222+
throw new Error('Missing smartSessionClient');
222223
}
223224
if (publishData) {
224225
setIsPublishing(true);
@@ -229,8 +230,7 @@ export const Todos2 = () => {
229230
].flat();
230231
const publishOpsResult = await publishOps({
231232
ops,
232-
// @ts-expect-error - TODO: fix the types error
233-
walletClient: smartAccountWalletClient,
233+
walletClient: smartSessionClient,
234234
space,
235235
name: 'Update users and todos',
236236
});

0 commit comments

Comments
 (0)