@@ -57,54 +57,72 @@ export const useProviders = (config: LedgerProviderConfig = DEFAULT_CONFIG) => {
5757 [ ] ,
5858 ) ;
5959
60- const initializeProviderWithConfig = useCallback ( ( configToUse : LedgerProviderConfig ) => {
61- if ( ! isLoaded || ! LedgerButtonModule ) return ;
62-
63- if ( cleanupRef . current ) {
64- cleanupRef . current ( ) ;
65- cleanupRef . current = null ;
66- }
67-
68- const { initializeLedgerProvider } = LedgerButtonModule ;
69-
70-
71- const disableEventTracking =
72- process . env . NEXT_PUBLIC_DISABLE_EVENT_TRACKING === "true" ;
73-
74- const cleanup = initializeLedgerProvider ( {
75- target : document . body ,
76- floatingButtonPosition : configToUse . buttonPosition as "bottom-right" | "bottom-left" | "top-right" | "top-left" ,
77- dAppIdentifier : configToUse . dAppIdentifier ,
78- apiKey : configToUse . apiKey ,
79- loggerLevel : configToUse . logLevel as "debug" | "info" | "warn" | "error" ,
80- environment : configToUse . environment as "production" | "staging" ,
81- dmkConfig : undefined ,
82- walletTransactionFeatures : [ "send" , "receive" , "swap" , "buy" , "earn" , "sell" ] ,
83- devConfig : disableEventTracking
84- ? {
85- stub : {
86- base : true ,
87- } ,
88- }
89- : undefined ,
90- } ) ;
91-
92- cleanupRef . current = cleanup ;
93- setIsInitialized ( true ) ;
60+ const initializeProviderWithConfig = useCallback (
61+ ( configToUse : LedgerProviderConfig ) => {
62+ if ( ! isLoaded || ! LedgerButtonModule ) return ;
63+
64+ if ( cleanupRef . current ) {
65+ cleanupRef . current ( ) ;
66+ cleanupRef . current = null ;
67+ }
68+
69+ const { initializeLedgerProvider } = LedgerButtonModule ;
70+
71+ const disableEventTracking =
72+ process . env . NEXT_PUBLIC_DISABLE_EVENT_TRACKING === "true" ;
73+
74+ const cleanup = initializeLedgerProvider ( {
75+ target : document . body ,
76+ floatingButtonPosition : configToUse . buttonPosition as
77+ | "bottom-right"
78+ | "bottom-left"
79+ | "top-right"
80+ | "top-left"
81+ | "middle-right" ,
82+ dAppIdentifier : configToUse . dAppIdentifier ,
83+ apiKey : configToUse . apiKey ,
84+ loggerLevel : configToUse . logLevel as
85+ | "debug"
86+ | "info"
87+ | "warn"
88+ | "error" ,
89+ environment : configToUse . environment as "production" | "staging" ,
90+ dmkConfig : undefined ,
91+ walletTransactionFeatures : [
92+ "send" ,
93+ "receive" ,
94+ "swap" ,
95+ "buy" ,
96+ "earn" ,
97+ "sell" ,
98+ ] ,
99+ devConfig : disableEventTracking
100+ ? {
101+ stub : {
102+ base : true ,
103+ } ,
104+ }
105+ : undefined ,
106+ } ) ;
94107
95- window . addEventListener (
96- "eip6963:announceProvider" ,
97- handleAnnounceProvider as EventListener ,
98- ) ;
108+ cleanupRef . current = cleanup ;
109+ setIsInitialized ( true ) ;
99110
100- return ( ) => {
101- cleanup ( ) ;
102- window . removeEventListener (
111+ window . addEventListener (
103112 "eip6963:announceProvider" ,
104113 handleAnnounceProvider as EventListener ,
105114 ) ;
106- } ;
107- } , [ isLoaded , handleAnnounceProvider ] ) ;
115+
116+ return ( ) => {
117+ cleanup ( ) ;
118+ window . removeEventListener (
119+ "eip6963:announceProvider" ,
120+ handleAnnounceProvider as EventListener ,
121+ ) ;
122+ } ;
123+ } ,
124+ [ isLoaded , handleAnnounceProvider ] ,
125+ ) ;
108126
109127 useEffect ( ( ) => {
110128 if ( ! isLoaded ) return ;
@@ -113,20 +131,23 @@ export const useProviders = (config: LedgerProviderConfig = DEFAULT_CONFIG) => {
113131 return cleanup ;
114132 } , [ isLoaded , initializeProviderWithConfig ] ) ;
115133
116- const reinitialize = useCallback ( ( newConfig ?: LedgerProviderConfig ) => {
117- const configToUse = newConfig || configRef . current ;
134+ const reinitialize = useCallback (
135+ ( newConfig ?: LedgerProviderConfig ) => {
136+ const configToUse = newConfig || configRef . current ;
118137
119- if ( cleanupRef . current ) {
120- cleanupRef . current ( ) ;
121- cleanupRef . current = null ;
122- }
138+ if ( cleanupRef . current ) {
139+ cleanupRef . current ( ) ;
140+ cleanupRef . current = null ;
141+ }
123142
124- setProviders ( [ ] ) ;
125- setSelectedProvider ( null ) ;
126- setIsInitialized ( false ) ;
143+ setProviders ( [ ] ) ;
144+ setSelectedProvider ( null ) ;
145+ setIsInitialized ( false ) ;
127146
128- initializeProviderWithConfig ( configToUse ) ;
129- } , [ initializeProviderWithConfig ] ) ;
147+ initializeProviderWithConfig ( configToUse ) ;
148+ } ,
149+ [ initializeProviderWithConfig ] ,
150+ ) ;
130151
131152 return {
132153 providers,
0 commit comments