Commit 61d9dfe1 authored by Justin Domingue's avatar Justin Domingue Committed by GitHub

chore: simplify redux types with ts inference (#1758)

* chore: simplify app dispatch and selector types with ts inference

* update SearchModal to use new types inference
parent d990dfde
...@@ -14,8 +14,8 @@ import { ExternalLink } from '../../theme/components' ...@@ -14,8 +14,8 @@ import { ExternalLink } from '../../theme/components'
import ListLogo from 'components/ListLogo' import ListLogo from 'components/ListLogo'
import { PaddedColumn, Checkbox, TextDot } from './styleds' import { PaddedColumn, Checkbox, TextDot } from './styleds'
import { TokenList } from '@uniswap/token-lists' import { TokenList } from '@uniswap/token-lists'
import { useDispatch } from 'react-redux'
import { AppDispatch } from 'state' import { useAppDispatch } from 'state/hooks'
import { useFetchListCallback } from 'hooks/useFetchListCallback' import { useFetchListCallback } from 'hooks/useFetchListCallback'
import { removeList, enableList } from 'state/lists/actions' import { removeList, enableList } from 'state/lists/actions'
import { CurrencyModalView } from './CurrencySearchModal' import { CurrencyModalView } from './CurrencySearchModal'
...@@ -37,7 +37,7 @@ interface ImportProps { ...@@ -37,7 +37,7 @@ interface ImportProps {
export function ImportList({ listURL, list, setModalView, onDismiss }: ImportProps) { export function ImportList({ listURL, list, setModalView, onDismiss }: ImportProps) {
const theme = useTheme() const theme = useTheme()
const dispatch = useDispatch<AppDispatch>() const dispatch = useAppDispatch()
// user must accept // user must accept
const [confirmed, setConfirmed] = useState(false) const [confirmed, setConfirmed] = useState(false)
......
import React, { memo, useCallback, useMemo, useRef, useState, useEffect } from 'react' import React, { memo, useCallback, useMemo, useRef, useState, useEffect } from 'react'
import { Settings, CheckCircle } from 'react-feather' import { Settings, CheckCircle } from 'react-feather'
import ReactGA from 'react-ga' import ReactGA from 'react-ga'
import { useAppDispatch, useAppSelector } from 'state/hooks'
import { usePopper } from 'react-popper' import { usePopper } from 'react-popper'
import { useDispatch, useSelector } from 'react-redux'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
import { useFetchListCallback } from '../../hooks/useFetchListCallback' import { useFetchListCallback } from '../../hooks/useFetchListCallback'
import { useOnClickOutside } from '../../hooks/useOnClickOutside' import { useOnClickOutside } from '../../hooks/useOnClickOutside'
...@@ -10,7 +10,6 @@ import { TokenList } from '@uniswap/token-lists' ...@@ -10,7 +10,6 @@ import { TokenList } from '@uniswap/token-lists'
import { t, Trans } from '@lingui/macro' import { t, Trans } from '@lingui/macro'
import useToggle from '../../hooks/useToggle' import useToggle from '../../hooks/useToggle'
import { AppDispatch, AppState } from '../../state'
import { acceptListUpdate, removeList, disableList, enableList } from '../../state/lists/actions' import { acceptListUpdate, removeList, disableList, enableList } from '../../state/lists/actions'
import { useIsListActive, useAllLists, useActiveListUrls } from '../../state/lists/hooks' import { useIsListActive, useAllLists, useActiveListUrls } from '../../state/lists/hooks'
import { ExternalLink, LinkStyledButton, TYPE, IconWrapper } from '../../theme' import { ExternalLink, LinkStyledButton, TYPE, IconWrapper } from '../../theme'
...@@ -94,8 +93,8 @@ function listUrlRowHTMLId(listUrl: string) { ...@@ -94,8 +93,8 @@ function listUrlRowHTMLId(listUrl: string) {
} }
const ListRow = memo(function ListRow({ listUrl }: { listUrl: string }) { const ListRow = memo(function ListRow({ listUrl }: { listUrl: string }) {
const listsByUrl = useSelector<AppState, AppState['lists']['byUrl']>((state) => state.lists.byUrl) const listsByUrl = useAppSelector((state) => state.lists.byUrl)
const dispatch = useDispatch<AppDispatch>() const dispatch = useAppDispatch()
const { current: list, pendingUpdate: pending } = listsByUrl[listUrl] const { current: list, pendingUpdate: pending } = listsByUrl[listUrl]
const theme = useTheme() const theme = useTheme()
......
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'
import { AppDispatch, AppState } from 'state'
export const useAppDispatch = () => useDispatch<AppDispatch>()
export const useAppSelector: TypedUseSelectorHook<AppState> = useSelector
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment