@@ -4,25 +4,23 @@ 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 { useController } from "@/hooks/controller " ;
17
16
18
17
export function Home ( ) {
19
- const { context, setContext, controller, error, policies, upgrade } =
20
- useConnection ( ) ;
18
+ const { context, setContext, error, policies, upgrade } = useConnection ( ) ;
19
+ const { controller } = useController ( ) ;
20
+
21
21
const [ hasSessionForPolicies , setHasSessionForPolicies ] = useState <
22
22
boolean | undefined
23
23
> ( undefined ) ;
24
- const posthog = usePostHog ( ) ;
25
-
26
24
useEffect ( ( ) => {
27
25
if ( controller && policies ) {
28
26
controller . isRequestedSession ( policies ) . then ( ( isRequestedSession ) => {
@@ -33,29 +31,19 @@ export function Home() {
33
31
}
34
32
} , [ controller , policies ] ) ;
35
33
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
34
if ( error ) {
49
35
return < ErrorPage error = { error } /> ;
50
36
}
51
37
52
- // No controller, send to login
38
+ if ( ! context ) {
39
+ return < > </ > ;
40
+ }
41
+
53
42
if ( ! controller ) {
54
- return < CreateController loginMode = { LoginMode . Controller } /> ;
43
+ return < PageLoading /> ;
55
44
}
56
45
57
46
if ( ! upgrade . isSynced || hasSessionForPolicies === undefined ) {
58
- // This is likely never observable in a real application but just in case.
59
47
return < PageLoading /> ;
60
48
}
61
49
@@ -113,7 +101,12 @@ export function Home() {
113
101
< SignMessage
114
102
origin = { ctx . origin }
115
103
typedData = { ctx . typedData }
116
- onSign = { ( sig : Signature ) => context . resolve ( sig ) }
104
+ onSign = { ( sig : Signature ) =>
105
+ ctx . resolve ( {
106
+ code : ResponseCodes . SUCCESS ,
107
+ ...sig ,
108
+ } )
109
+ }
117
110
onCancel = { ( ) =>
118
111
ctx . resolve ( {
119
112
code : ResponseCodes . CANCELED ,
0 commit comments