@@ -4,25 +4,24 @@ import { ResponseCodes } from "@cartridge/controller";
4
4
import { useConnection } from "@/hooks/connection" ;
5
5
import { DeployCtx , ExecuteCtx , SignMessageCtx } from "@/utils/connection" ;
6
6
import { ConfirmTransaction } from "./transaction/ConfirmTransaction" ;
7
- import { CreateController , CreateSession , Logout , Upgrade } from "./connect" ;
8
- import { LoginMode } from "./connect/types" ;
7
+ import { CreateSession , Logout , Upgrade } from "./connect" ;
9
8
import { DeployController } from "./DeployController" ;
10
9
import { ErrorPage } from "./ErrorBoundary" ;
11
10
import { PurchaseCredits } from "./funding/PurchaseCredits" ;
12
11
import { Settings } from "./settings" ;
13
12
import { SignMessage } from "./SignMessage" ;
14
13
import { PageLoading } from "./Loading" ;
15
14
import { execute } from "@/utils/connection/execute" ;
16
- import { usePostHog } from "@/hooks/posthog" ;
15
+ import Controller from "@/utils/controller" ;
16
+ import { useUpgrade } from "@/hooks/upgrade" ;
17
+
18
+ export function Home ( { controller } : { controller : Controller } ) {
19
+ const { context, setContext, error, policies } = useConnection ( ) ;
20
+ const upgrade = useUpgrade ( ) ;
17
21
18
- export function Home ( ) {
19
- const { context, setContext, controller, error, policies, upgrade } =
20
- useConnection ( ) ;
21
22
const [ hasSessionForPolicies , setHasSessionForPolicies ] = useState <
22
23
boolean | undefined
23
24
> ( undefined ) ;
24
- const posthog = usePostHog ( ) ;
25
-
26
25
useEffect ( ( ) => {
27
26
if ( controller && policies ) {
28
27
controller . isRequestedSession ( policies ) . then ( ( isRequestedSession ) => {
@@ -33,29 +32,15 @@ export function Home() {
33
32
}
34
33
} , [ controller , policies ] ) ;
35
34
36
- useEffect ( ( ) => {
37
- if ( context ?. type ) {
38
- posthog ?. capture (
39
- `Call ${ context . type . charAt ( 0 ) . toUpperCase ( ) + context . type . slice ( 1 ) } ` ,
40
- ) ;
41
- }
42
- } , [ context ?. type , posthog ] ) ;
43
-
44
- if ( window . self === window . top || ! context ?. origin ) {
45
- return < > </ > ;
46
- }
47
-
48
35
if ( error ) {
49
36
return < ErrorPage error = { error } /> ;
50
37
}
51
38
52
- // No controller, send to login
53
- if ( ! controller ) {
54
- return < CreateController loginMode = { LoginMode . Controller } /> ;
39
+ if ( ! context ) {
40
+ return < > </ > ;
55
41
}
56
42
57
43
if ( ! upgrade . isSynced || hasSessionForPolicies === undefined ) {
58
- // This is likely never observable in a real application but just in case.
59
44
return < PageLoading /> ;
60
45
}
61
46
0 commit comments