-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move sdk initialization to provider
- Loading branch information
Showing
23 changed files
with
113 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
import { checkPackageUpdates } from '@lifi/sdk'; | ||
import { useEffect } from 'react'; | ||
import { name, version } from '../config/version'; | ||
import { useTools } from './useTools'; | ||
|
||
export const useInitializer = () => { | ||
useTools(); | ||
useEffect(() => { | ||
checkPackageUpdates(name, version); | ||
}, []); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import LIFI from '@lifi/sdk'; | ||
import { createContext, useContext, useMemo } from 'react'; | ||
import { useWidgetConfig } from '../WidgetProvider'; | ||
|
||
let lifi: LIFI; | ||
|
||
const SDKContext = createContext<LIFI>(null!); | ||
|
||
export const useLiFi = (): LIFI => useContext(SDKContext); | ||
|
||
export const SDKProvider: React.FC<React.PropsWithChildren> = ({ | ||
children, | ||
}) => { | ||
const { sdkConfig, integrator } = useWidgetConfig(); | ||
const value = useMemo(() => { | ||
const config = { | ||
...sdkConfig, | ||
defaultRouteOptions: { | ||
...sdkConfig?.defaultRouteOptions, | ||
integrator: integrator ?? window.location.hostname, | ||
}, | ||
}; | ||
if (!lifi) { | ||
lifi = new LIFI({ | ||
disableVersionCheck: true, | ||
...config, | ||
}); | ||
} | ||
lifi.setConfig(config); | ||
return lifi; | ||
}, [integrator, sdkConfig]); | ||
|
||
return <SDKContext.Provider value={value}>{children}</SDKContext.Provider>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './SDKProvider'; |
10 changes: 10 additions & 0 deletions
10
packages/widget/src/providers/TelemetryProvider/TelemetryProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { useWidgetConfig } from '..'; | ||
import { useTelemetry } from '../../hooks'; | ||
|
||
export const TelemetryProvider: React.FC<{ | ||
children: React.ReactElement<any, any> | null; | ||
}> = ({ children }) => { | ||
const config = useWidgetConfig(); | ||
useTelemetry(config?.disableTelemetry); | ||
return children; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './TelemetryProvider'; |
Oops, something went wrong.