Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions apps/connect/.env.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
VITE_HYPERGRAPH_SYNC_SERVER_ORIGIN="http://localhost:3030"
# VITE_HYPERGRAPH_CHAIN="geo-testnet"
# VITE_HYPERGRAPH_API_URL="https://hypergraph-v2-testnet.up.railway.app/graphql"
# VITE_HYPERGRAPH_RPC_URL="https://rpc-geo-test-zc16z3tcvf.t.conduit.xyz"
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"
7 changes: 5 additions & 2 deletions apps/connect/src/routes/__root.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Logout } from '@/components/logout';
import { StoreConnect } from '@graphprotocol/hypergraph';
import { usePrivy } from '@privy-io/react-auth';
import { Link, Outlet, createRootRoute, useLayoutEffect, useRouter } from '@tanstack/react-router';
import { TanStackRouterDevtools } from '@tanstack/router-devtools';
import { useSelector } from '@xstate/store/react';

export const Route = createRootRoute({
component: () => {
const accountAddress = useSelector(StoreConnect.store, (state) => state.context.accountAddress);
const { authenticated, ready } = usePrivy();
const router = useRouter();

Expand All @@ -13,15 +16,15 @@ export const Route = createRootRoute({
return;
}

if (ready && !authenticated) {
if (ready && (!authenticated || !accountAddress)) {
if (router.state.location.href.startsWith('/authenticate')) {
localStorage.setItem('geo-connect-authenticate-redirect', router.state.location.href);
}
router.navigate({
to: '/login',
});
}
}, [authenticated, ready]);
}, [authenticated, ready, accountAddress]);

return (
<>
Expand Down
1 change: 1 addition & 0 deletions apps/connect/src/routes/authenticate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ function AuthenticateComponent() {
console.log('smart session created');
const smartAccountClient = await getSmartAccountWalletClient({
owner: walletClient,
address: accountAddress,
chain: CHAIN,
rpcUrl: import.meta.env.VITE_HYPERGRAPH_RPC_URL,
});
Expand Down
3 changes: 3 additions & 0 deletions apps/connect/src/routes/login.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function Login() {

const hypergraphLogin = useCallback(
async (walletClient: WalletClient, embeddedWallet: ConnectedWallet) => {
console.log('hypergraphLogin');
if (!identityToken) {
return;
}
Expand Down Expand Up @@ -57,12 +58,14 @@ function Login() {
);

useEffect(() => {
console.log('useEffect in login.lazy.tsx');
if (
!hypergraphLoginStarted && // avoid re-running the effect to often
privyAuthenticated && // privy must be authenticated to run it
walletsReady && // wallets must be ready to run it
wallets.length > 0 // wallets must have at least one wallet to run it
) {
console.log('running login effect');
setHypergraphLoginStarted(true);
(async () => {
try {
Expand Down
7 changes: 6 additions & 1 deletion apps/events/src/Boot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ declare module '@tanstack/react-router' {

export function Boot() {
return (
<HypergraphAppProvider storage={localStorage} syncServerUri="http://localhost:3030" mapping={mapping}>
<HypergraphAppProvider
storage={localStorage}
syncServerUri="http://localhost:3030"
mapping={mapping}
chainId={80451}
>
<RouterProvider router={router} />
</HypergraphAppProvider>
);
Expand Down
25 changes: 12 additions & 13 deletions apps/events/src/components/create-events.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { getSmartAccountWalletClient } from '@/lib/smart-account';
import { type GeoSmartAccount, Graph, type Op } from '@graphprotocol/grc-20';
import { publishOps } from '@graphprotocol/hypergraph-react';
import { Graph, type Op } from '@graphprotocol/grc-20';
import type { Connect } from '@graphprotocol/hypergraph';
import { publishOps, useHypergraphApp } from '@graphprotocol/hypergraph-react';
import { Button } from './ui/button';

const createEvents = async ({
smartAccountWalletClient,
smartSessionClient,
space,
}: { smartAccountWalletClient: GeoSmartAccount; space: string }) => {
}: { smartSessionClient: Connect.SmartSessionClient; space: string }) => {
try {
const ops: Array<Op> = [];

Expand Down Expand Up @@ -46,7 +46,7 @@ const createEvents = async ({
});
ops.push(...createCompanyTypeOps);

const { id: eventTypeId, ops: createEventTypeOps } = Graph.createEntity({
const { ops: createEventTypeOps } = Graph.createEntity({
name: 'My Test Event',
types: ['6b8dbe76-389f-4bde-acdd-db9d5e387882'],
relations: {
Expand All @@ -57,10 +57,9 @@ const createEvents = async ({

const result = await publishOps({
ops,
walletClient: smartAccountWalletClient,
walletClient: smartSessionClient,
space,
name: 'Create Job Offers, Companies and Events',
network: 'TESTNET',
});
console.log('result', result);
alert('Events created');
Expand All @@ -70,17 +69,17 @@ const createEvents = async ({
};

export const CreateEvents = ({ space }: { space: string }) => {
const { getSmartSessionClient } = useHypergraphApp();
return (
<div>
<Button
onClick={async () => {
const smartAccountWalletClient = await getSmartAccountWalletClient();
if (!smartAccountWalletClient) {
throw new Error('Missing smartAccountWalletClient');
const smartSessionClient = await getSmartSessionClient();
if (!smartSessionClient) {
throw new Error('Missing smartSessionClient');
}
await createEvents({
// @ts-expect-error TODO: in the future we probably only only use one smart account wallet client
smartAccountWalletClient,
smartSessionClient,
space,
});
}}
Expand Down
23 changes: 11 additions & 12 deletions apps/events/src/components/create-properties-and-types-event.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { getSmartAccountWalletClient } from '@/lib/smart-account';
import { type GeoSmartAccount, Graph, type Op } from '@graphprotocol/grc-20';
import { publishOps } from '@graphprotocol/hypergraph-react';
import { Graph, type Op } from '@graphprotocol/grc-20';
import type { Connect } from '@graphprotocol/hypergraph';
import { publishOps, useHypergraphApp } from '@graphprotocol/hypergraph-react';
import { useState } from 'react';
import { Button } from './ui/button';
import { Card, CardContent } from './ui/card';

const createPropertiesAndTypesEvent = async ({
smartAccountWalletClient,
smartSessionClient,
space,
}: { smartAccountWalletClient: GeoSmartAccount; space: string }) => {
}: { smartSessionClient: Connect.SmartSessionClient; space: string }) => {
const ops: Array<Op> = [];
const { id: salaryPropertyId, ops: createSalaryPropertyOps } = Graph.createProperty({
dataType: 'NUMBER',
Expand Down Expand Up @@ -50,10 +50,9 @@ const createPropertiesAndTypesEvent = async ({

const result = await publishOps({
ops,
walletClient: smartAccountWalletClient,
walletClient: smartSessionClient,
space,
name: 'Create properties and types',
network: 'TESTNET',
});
return {
result,
Expand All @@ -68,6 +67,7 @@ const createPropertiesAndTypesEvent = async ({

export const CreatePropertiesAndTypesEvent = ({ space }: { space: string }) => {
const [mapping, setMapping] = useState<string>('');
const { getSmartSessionClient } = useHypergraphApp();

return (
<div>
Expand All @@ -80,9 +80,9 @@ export const CreatePropertiesAndTypesEvent = ({ space }: { space: string }) => {
)}
<Button
onClick={async () => {
const smartAccountWalletClient = await getSmartAccountWalletClient();
if (!smartAccountWalletClient) {
throw new Error('Missing smartAccountWalletClient');
const smartSessionClient = await getSmartSessionClient();
if (!smartSessionClient) {
throw new Error('Missing smartSessionClient');
}
const {
eventTypeId,
Expand All @@ -92,8 +92,7 @@ export const CreatePropertiesAndTypesEvent = ({ space }: { space: string }) => {
jobOffersRelationTypeId,
sponsorsRelationTypeId,
} = await createPropertiesAndTypesEvent({
// @ts-expect-error TODO: in the future we probably only only use one smart account wallet client
smartAccountWalletClient,
smartSessionClient,
space,
});

Expand Down
24 changes: 11 additions & 13 deletions apps/events/src/components/create-properties-and-types-todos.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { getSmartAccountWalletClient } from '@/lib/smart-account';
import { type GeoSmartAccount, Graph, type Op } from '@graphprotocol/grc-20';
import { publishOps } from '@graphprotocol/hypergraph-react';
import { Graph, type Op } from '@graphprotocol/grc-20';
import type { Connect } from '@graphprotocol/hypergraph';
import { publishOps, useHypergraphApp } from '@graphprotocol/hypergraph-react';
import { useState } from 'react';
import { Button } from './ui/button';
import { Card, CardContent } from './ui/card';

const createPropertiesAndTypesTodos = async ({
smartAccountWalletClient,
smartSessionClient,
space,
}: { smartAccountWalletClient: GeoSmartAccount; space: string }) => {
}: { smartSessionClient: Connect.SmartSessionClient; space: string }) => {
const ops: Array<Op> = [];
const { id: checkedPropertyId, ops: createCheckedPropertyOps } = Graph.createProperty({
dataType: 'CHECKBOX',
Expand Down Expand Up @@ -67,10 +67,9 @@ const createPropertiesAndTypesTodos = async ({

const result = await publishOps({
ops,
walletClient: smartAccountWalletClient,
walletClient: smartSessionClient,
space,
name: 'Create properties and types',
network: 'TESTNET',
});
return {
result,
Expand All @@ -87,7 +86,7 @@ const createPropertiesAndTypesTodos = async ({

export const CreatePropertiesAndTypesTodos = ({ space }: { space: string }) => {
const [mapping, setMapping] = useState<string>('');

const { getSmartSessionClient } = useHypergraphApp();
return (
<div>
{mapping && (
Expand All @@ -99,9 +98,9 @@ export const CreatePropertiesAndTypesTodos = ({ space }: { space: string }) => {
)}
<Button
onClick={async () => {
const smartAccountWalletClient = await getSmartAccountWalletClient();
if (!smartAccountWalletClient) {
throw new Error('Missing smartAccountWalletClient');
const smartSessionClient = await getSmartSessionClient();
if (!smartSessionClient) {
throw new Error('Missing smartSessionClient');
}
const {
todoTypeId,
Expand All @@ -113,8 +112,7 @@ export const CreatePropertiesAndTypesTodos = ({ space }: { space: string }) => {
websitePropertyId,
amountPropertyId,
} = await createPropertiesAndTypesTodos({
// @ts-expect-error - TODO: fix the types error
smartAccountWalletClient,
smartSessionClient,
space,
});

Expand Down
14 changes: 9 additions & 5 deletions apps/events/src/components/playground.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { getSmartAccountWalletClient } from '@/lib/smart-account';
import { _useCreateEntityPublic, _useDeleteEntityPublic, useQuery } from '@graphprotocol/hypergraph-react';
import {
_useCreateEntityPublic,
_useDeleteEntityPublic,
useHypergraphApp,
useQuery,
} from '@graphprotocol/hypergraph-react';
import { useState } from 'react';
import { Event } from '../schema';
import { Button } from './ui/button';
Expand All @@ -15,6 +19,7 @@ export const Playground = () => {
});
const [isDeleting, setIsDeleting] = useState(false);
const [isCreating, setIsCreating] = useState(false);
const { getSmartSessionClient } = useHypergraphApp();

const deleteEntity = _useDeleteEntityPublic(Event, {
space: '1c954768-7e14-4f0f-9396-0fe9dcd55fe8',
Expand All @@ -34,7 +39,7 @@ export const Playground = () => {
disabled={isCreating}
onClick={async () => {
setIsCreating(true);
const walletClient = await getSmartAccountWalletClient();
const walletClient = await getSmartSessionClient();
if (!walletClient) {
alert('Wallet client not found');
setIsCreating(false);
Expand All @@ -60,14 +65,13 @@ export const Playground = () => {
<Button
onClick={async () => {
setIsDeleting(true);
const walletClient = await getSmartAccountWalletClient();
const walletClient = await getSmartSessionClient();
if (!walletClient) {
alert('Wallet client not found');
return;
}
await deleteEntity({
id: event.id,
// @ts-expect-error - TODO: fix the types error
walletClient,
});
setIsDeleting(false);
Expand Down
21 changes: 10 additions & 11 deletions apps/events/src/components/todo/todos-public.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { getSmartAccountWalletClient } from '@/lib/smart-account';
import { Id } from '@graphprotocol/grc-20';
import { _generateDeleteOps, publishOps, useCreateEntity, useQuery, useSpace } from '@graphprotocol/hypergraph-react';
import { useHypergraphApp } from '@graphprotocol/hypergraph-react';
import { useGenerateCreateOps } from '@graphprotocol/hypergraph-react/internal/use-generate-create-ops';
import { Todo2 } from '../../schema';
import { Spinner } from '../spinner';
import { Button } from '../ui/button';

export const TodosPublic = () => {
const { id: spaceId } = useSpace({ mode: 'public' });
const { getSmartSessionClient } = useHypergraphApp();
const {
data: dataPublic,
isLoading: isLoadingPublic,
Expand Down Expand Up @@ -44,15 +45,14 @@ export const TodosPublic = () => {

<Button
onClick={async () => {
const smartAccountWalletClient = await getSmartAccountWalletClient();
if (!smartAccountWalletClient) {
throw new Error('Missing smartAccountWalletClient');
const smartSessionClient = await getSmartSessionClient();
if (!smartSessionClient) {
throw new Error('Missing smartSessionClient');
}
const ops = await _generateDeleteOps({ id: todo.id, space: spaceId });
const result = await publishOps({
ops,
// @ts-expect-error - TODO: fix the types error
walletClient: smartAccountWalletClient,
walletClient: smartSessionClient,
space: spaceId,
name: 'Delete Todo',
});
Expand All @@ -65,9 +65,9 @@ export const TodosPublic = () => {
))}
<Button
onClick={async () => {
const smartAccountWalletClient = await getSmartAccountWalletClient();
if (!smartAccountWalletClient) {
throw new Error('Missing smartAccountWalletClient');
const smartSessionClient = await getSmartSessionClient();
if (!smartSessionClient) {
throw new Error('Missing smartSessionClient');
}
const userId = Id.Id('8zPJjTGLBDPtUcj6q2tghg');
const todo = createTodo({
Expand All @@ -84,8 +84,7 @@ export const TodosPublic = () => {
console.log('ops', ops);
const result = await publishOps({
ops,
// @ts-expect-error - TODO: fix the types error
walletClient: smartAccountWalletClient,
walletClient: smartSessionClient,
space: spaceId,
name: 'Create Todo',
});
Expand Down
Loading
Loading