1- import type { XyoGatewayProvider } from '@xyo-network/xl1-protocol'
1+ import type { XyoClient } from '@xyo-network/xl1-protocol'
22import { useSyncExternalStore } from 'react'
33
4- import { getXyoGateway } from '../helpers/index.ts'
4+ import { getXyoClient } from '../helpers/index.ts'
55
6- interface GatewayState {
6+ interface ClientState {
7+ client ?: XyoClient
78 error : Error | null
8- gateway ?: XyoGatewayProvider
99 isLoading : boolean
1010}
1111
12- let currentState : GatewayState = {
13- gateway : undefined ,
12+ let currentState : ClientState = {
13+ client : undefined ,
1414 error : null ,
1515 isLoading : false ,
1616}
@@ -21,20 +21,20 @@ const emitChange = () => {
2121 for ( const listener of listeners ) listener ( )
2222}
2323
24- const updateState = ( newState : Partial < GatewayState > ) => {
24+ const updateState = ( newState : Partial < ClientState > ) => {
2525 currentState = { ...currentState , ...newState }
2626 emitChange ( )
2727}
2828
29- const initializeGateway = async ( ) => {
30- if ( currentState . isLoading || currentState . gateway ) return
29+ const initializeClient = async ( ) => {
30+ if ( currentState . isLoading || currentState . client ) return
3131
3232 updateState ( { isLoading : true , error : null } )
3333
3434 try {
35- const gateway = await getXyoGateway ( )
35+ const client = await getXyoClient ( )
3636 updateState ( {
37- gateway , isLoading : false , error : null ,
37+ client , isLoading : false , error : null ,
3838 } )
3939 } catch ( error ) {
4040 updateState ( { error : error as Error , isLoading : false } )
@@ -44,15 +44,15 @@ const initializeGateway = async () => {
4444const subscribe = ( listener : ( ) => void ) => {
4545 listeners . add ( listener )
4646
47- void initializeGateway ( )
47+ void initializeClient ( )
4848
4949 return ( ) => {
5050 listeners . delete ( listener )
5151 }
5252}
5353
54- const getSnapshot = ( ) : GatewayState => currentState
54+ const getSnapshot = ( ) : ClientState => currentState
5555
56- export const useDefaultGateway = ( ) => {
56+ export const useClient = ( ) => {
5757 return useSyncExternalStore ( subscribe , getSnapshot )
5858}
0 commit comments