File tree Expand file tree Collapse file tree 1 file changed +3
-1
lines changed
Expand file tree Collapse file tree 1 file changed +3
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ const ACCOUNTS_CHANGED = "accountsChanged"
1515const ON_DISCONNECT = "disconnect"
1616const ONE_MINUTE_IN_MS = 60000
1717const EMPTY_BALANCE = "0.00"
18+ const isFunction = ( f ) => typeof f === "function"
1819
1920function useMetamask ( onMetamaskHook ?) : UseMatamaskAPI {
2021 const [ error , setError ] = useState ( null )
@@ -54,7 +55,8 @@ function useMetamask(onMetamaskHook?): UseMatamaskAPI {
5455 metamask . on ( ACCOUNTS_CHANGED , setAccounts )
5556 metamask . on ( ON_DISCONNECT , handleDisconnect )
5657 metamask . request ( { method : "eth_accounts" } ) . then ( setAccounts )
57- hookCleanerFn = onMetamaskHook ? onMetamaskHook ( metamask ) : noOp
58+ const hookCleaner = isFunction ( onMetamaskHook ) && onMetamaskHook ( metamask )
59+ hookCleanerFn = isFunction ( hookCleaner ) ? hookCleaner : noOp
5860 }
5961 window . addEventListener ( EVENTS . ON_METAMASK_ERROR , handleEventError )
6062 return ( ) => {
You can’t perform that action at this time.
0 commit comments