Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
talentlessguy committed Jan 25, 2024
1 parent b635c3f commit 01a6ebe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
21 changes: 8 additions & 13 deletions src/hooks/useLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,23 @@ export const useLocalStorage = <D>(
window.dispatchEvent(new StorageEvent('storage', { key, newValue: JSON.stringify(value) }))
}, [key, value, defaultValue])

useEffect(() => {
const handleStorageChange = (event: StorageEvent) => {
const handleStorageChange = useCallback(
(event: StorageEvent) => {
if (event.key === key && event.newValue && JSON.stringify(value) !== event.newValue) {
setValue(JSON.parse(event.newValue!))
}
}

window.addEventListener('storage', handleStorageChange)
},
[key, value],
)

return () => {
window.removeEventListener('storage', handleStorageChange)
}
}, [key, value])
useEvent('storage', handleStorageChange)

return [value, setValue]
}

type Value<T> = T | null
type LocalStorageValue<T> = T | null

export function useReadLocalStorage<T>(key: string): Value<T> {
// Get from local storage then
// parse stored json or return initialValue
export function useReadLocalStorage<T>(key: string): LocalStorageValue<T> {
const readValue = useCallback((): Value<T> => {
return getStorageValue(key, null)
}, [key])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
} from '@app/components/@molecules/NameTableHeader/NameTableHeader'
import { ScrollBoxWithSpinner, SpinnerRow } from '@app/components/@molecules/ScrollBoxWithSpinner'
import { useNamesForAddress } from '@app/hooks/ensjs/subgraph/useNamesForAddress'
import { useHasGlobalError } from '@app/hooks/errors/useHasGlobalError'
import { useGetPrimaryNameTransactionFlowItem } from '@app/hooks/primary/useGetPrimaryNameTransactionFlowItem'
import { useResolverStatus } from '@app/hooks/resolver/useResolverStatus'
import useDebouncedCallback from '@app/hooks/useDebouncedCallback'
Expand Down Expand Up @@ -308,8 +307,6 @@ const SelectPrimaryName = ({ data: { address }, dispatch, onDismiss }: Props) =>
const hasNoEligibleNames =
!searchQuery && namesData?.pages.length === 1 && namesData.pages[0].length === 0

const hasGlobalError = useHasGlobalError()

if (isLoading)
return (
<LoadingContainer>
Expand Down Expand Up @@ -398,7 +395,7 @@ const SelectPrimaryName = ({ data: { address }, dispatch, onDismiss }: Props) =>
<Button
data-testid="primary-next"
onClick={onConfirm}
disabled={!selectedName || isLoadingName || hasGlobalError}
disabled={!selectedName || isLoadingName}
loading={isLoadingName}
>
{t('action.next', { ns: 'common' })}
Expand Down

0 comments on commit 01a6ebe

Please sign in to comment.