{filterType !== 'tokens' && (
- {!isMobile && 'Don\'t see a pool? '}
+ {!isMobile && "Don't see a pool? "}
{
history.push('/find')
@@ -658,7 +655,7 @@ function SearchModal({
)}
{filterType === 'tokens' && (
- {!isMobile && 'Don\'t see a token? '}
+ {!isMobile && "Don't see a token? "}
{
diff --git a/src/components/Slider/index.tsx b/src/components/Slider/index.tsx
index 757005082a..0079c0ae47 100644
--- a/src/components/Slider/index.tsx
+++ b/src/components/Slider/index.tsx
@@ -58,12 +58,15 @@ export default function InputSlider({ value, onChange, override }: InputSliderPr
const [internalVal, setInternalVal] = useState(value)
const debouncedInternalValue = useDebounce(internalVal, 100)
- const handleChange = useCallback((e, val) => {
- setInternalVal(val)
- if (val !== debouncedInternalValue) {
- onChange(val)
- }
- }, [setInternalVal, onChange, debouncedInternalValue])
+ const handleChange = useCallback(
+ (e, val) => {
+ setInternalVal(val)
+ if (val !== debouncedInternalValue) {
+ onChange(val)
+ }
+ },
+ [setInternalVal, onChange, debouncedInternalValue]
+ )
useEffect(() => {
if (override) {
diff --git a/src/components/SlippageTabs/index.tsx b/src/components/SlippageTabs/index.tsx
index 5004f25e38..198e1d1bf4 100644
--- a/src/components/SlippageTabs/index.tsx
+++ b/src/components/SlippageTabs/index.tsx
@@ -61,21 +61,21 @@ const Input = styled.input<{ active?: boolean }>`
color: ${({ theme }) => theme.text1};
text-align: left;
${({ active }) =>
- active &&
- css`
+ active &&
+ css`
color: initial;
cursor: initial;
text-align: right;
`}
${({ placeholder }) =>
- placeholder !== 'Custom' &&
- css`
+ placeholder !== 'Custom' &&
+ css`
text-align: right;
color: ${({ theme }) => theme.text1};
`}
${({ color }) =>
- color === 'red' &&
- css`
+ color === 'red' &&
+ css`
color: ${({ theme }) => theme.red1};
`}
`
@@ -84,8 +84,8 @@ const BottomError = styled(Text)`
font-size: 14px;
font-weight: 400;
${({ show }) =>
- show &&
- css`
+ show &&
+ css`
padding-top: 12px;
`}
`
@@ -94,9 +94,10 @@ const OptionCustom = styled(FancyButton)<{ active?: boolean; warning?: boolean }
height: 2rem;
position: relative;
padding: 0 0.75rem;
- border: ${({ theme, active, warning }) => active && `1px solid ${(warning ? theme.red1 : theme.blue1)}`};
+ border: ${({ theme, active, warning }) => active && `1px solid ${warning ? theme.red1 : theme.blue1}`};
:hover {
- border: ${({ theme, active, warning }) => active && `1px solid ${(warning ? darken(0.1, theme.red1) : darken(0.1, theme.blue1))}`};
+ border: ${({ theme, active, warning }) =>
+ active && `1px solid ${warning ? darken(0.1, theme.red1) : darken(0.1, theme.blue1)}`};
}
input {
@@ -116,12 +117,12 @@ const Percent = styled.div`
font-size: 0, 8rem;
flex-grow: 0;
${({ color, theme }) =>
- (color === 'faded' &&
- css`
+ (color === 'faded' &&
+ css`
color: ${theme.bg1};
`) ||
- (color === 'red' &&
- css`
+ (color === 'red' &&
+ css`
color: ${theme.red1};
`)};
`
@@ -133,7 +134,12 @@ interface TransactionDetailsProps {
setDeadline: (deadline: number) => void
}
-export default function TransactionDetails({ setRawSlippage, rawSlippage, deadline, setDeadline }: TransactionDetailsProps) {
+export default function TransactionDetails({
+ setRawSlippage,
+ rawSlippage,
+ deadline,
+ setDeadline
+}: TransactionDetailsProps) {
const [activeIndex, setActiveIndex] = useState(2)
const [warningType, setWarningType] = useState(WARNING_TYPE.none)
@@ -147,26 +153,10 @@ export default function TransactionDetails({ setRawSlippage, rawSlippage, deadli
const [deadlineInput, setDeadlineInput] = useState(deadline / 60)
- function parseCustomDeadline(e) {
- let val = e.target.value
- const acceptableValues = [/^$/, /^\d+$/]
- if (acceptableValues.some(re => re.test(val))) {
- setDeadlineInput(val)
- setDeadline(val * 60)
- }
- }
-
- const setFromCustom = () => {
- setActiveIndex(4)
- inputRef.current.focus()
- // if there's a value, evaluate the bounds
- checkBounds(debouncedInput)
- }
-
const updateSlippage = useCallback(
newSlippage => {
// round to 2 decimals to prevent ethers error
- let numParsed = newSlippage * 100
+ const numParsed = newSlippage * 100
// set both slippage values in parents
setRawSlippage(numParsed)
@@ -174,39 +164,6 @@ export default function TransactionDetails({ setRawSlippage, rawSlippage, deadli
[setRawSlippage]
)
- // used for slippage presets
- const setFromFixed = useCallback(
- (index, slippage) => {
- // update slippage in parent, reset errors and input state
- updateSlippage(slippage)
- setWarningType(WARNING_TYPE.none)
- setActiveIndex(index)
- },
- [updateSlippage]
- )
-
- useEffect(() => {
- switch (initialSlippage) {
- case 10:
- setFromFixed(1, 0.1)
- break
- case 50:
- setFromFixed(2, 0.5)
- break
- case 100:
- setFromFixed(3, 1)
- break
- default:
- // restrict to 2 decimal places
- let acceptableValues = [/^$/, /^\d{1,2}$/, /^\d{0,2}\.\d{0,2}$/]
- // if its within accepted decimal limit, update the input state
- if (acceptableValues.some(val => val.test('' + (initialSlippage / 100)))) {
- setUserInput('' + (initialSlippage / 100))
- setActiveIndex(4)
- }
- }
- }, [initialSlippage, setFromFixed])
-
const checkBounds = useCallback(
slippageValue => {
setWarningType(WARNING_TYPE.none)
@@ -231,12 +188,60 @@ export default function TransactionDetails({ setRawSlippage, rawSlippage, deadli
[updateSlippage]
)
+ function parseCustomDeadline(e) {
+ const val = e.target.value
+ const acceptableValues = [/^$/, /^\d+$/]
+ if (acceptableValues.some(re => re.test(val))) {
+ setDeadlineInput(val)
+ setDeadline(val * 60)
+ }
+ }
+ const setFromCustom = () => {
+ setActiveIndex(4)
+ inputRef.current.focus()
+ // if there's a value, evaluate the bounds
+ checkBounds(debouncedInput)
+ }
+
+ // used for slippage presets
+ const setFromFixed = useCallback(
+ (index, slippage) => {
+ // update slippage in parent, reset errors and input state
+ updateSlippage(slippage)
+ setWarningType(WARNING_TYPE.none)
+ setActiveIndex(index)
+ },
+ [updateSlippage]
+ )
+
+ useEffect(() => {
+ switch (initialSlippage) {
+ case 10:
+ setFromFixed(1, 0.1)
+ break
+ case 50:
+ setFromFixed(2, 0.5)
+ break
+ case 100:
+ setFromFixed(3, 1)
+ break
+ default:
+ // restrict to 2 decimal places
+ const acceptableValues = [/^$/, /^\d{1,2}$/, /^\d{0,2}\.\d{0,2}$/]
+ // if its within accepted decimal limit, update the input state
+ if (acceptableValues.some(val => val.test('' + initialSlippage / 100))) {
+ setUserInput('' + initialSlippage / 100)
+ setActiveIndex(4)
+ }
+ }
+ }, [initialSlippage, setFromFixed])
+
// check that the theyve entered number and correct decimal
const parseInput = e => {
- let input = e.target.value
+ const input = e.target.value
// restrict to 2 decimal places
- let acceptableValues = [/^$/, /^\d{1,2}$/, /^\d{0,2}\.\d{0,2}$/]
+ const acceptableValues = [/^$/, /^\d{1,2}$/, /^\d{0,2}\.\d{0,2}$/]
// if its within accepted decimal limit, update the input state
if (acceptableValues.some(a => a.test(input))) {
setUserInput(input)
@@ -313,8 +318,8 @@ export default function TransactionDetails({ setRawSlippage, rawSlippage, deadli
placeholder={
activeIndex === 4
? !!userInput
- ? ''
- : '0'
+ ? ''
+ : '0'
: activeIndex !== 4 && userInput !== ''
? userInput
: 'Custom'
@@ -352,8 +357,8 @@ export default function TransactionDetails({ setRawSlippage, rawSlippage, deadli
: warningType !== WARNING_TYPE.none && warningType !== WARNING_TYPE.riskyEntryLow
? 'red'
: warningType === WARNING_TYPE.riskyEntryLow
- ? '#F3841E'
- : ''
+ ? '#F3841E'
+ : ''
}
>
{warningType === WARNING_TYPE.emptyInput && 'Enter a slippage percentage'}
@@ -366,12 +371,16 @@ export default function TransactionDetails({ setRawSlippage, rawSlippage, deadli
Deadline
-
+
-
+
minutes
diff --git a/src/components/TokenLogo/index.tsx b/src/components/TokenLogo/index.tsx
index 9271e9b125..e9392503ab 100644
--- a/src/components/TokenLogo/index.tsx
+++ b/src/components/TokenLogo/index.tsx
@@ -20,7 +20,7 @@ const Image = styled.img<{ size: string }>`
box-shadow: 0px 6px 10px rgba(0, 0, 0, 0.075);
`
-const Emoji = styled.span<{size?:string}>`
+const Emoji = styled.span<{ size?: string }>`
display: flex;
align-items: center;
justify-content: center;
@@ -30,7 +30,7 @@ const Emoji = styled.span<{size?:string}>`
margin-bottom: -4px;
`
-const StyledEthereumLogo = styled(EthereumLogo)<{size: string}>`
+const StyledEthereumLogo = styled(EthereumLogo)<{ size: string }>`
width: ${({ size }) => size};
height: ${({ size }) => size};
`
diff --git a/src/components/TxnPopup/index.tsx b/src/components/TxnPopup/index.tsx
index bcf130a86c..5298345184 100644
--- a/src/components/TxnPopup/index.tsx
+++ b/src/components/TxnPopup/index.tsx
@@ -28,7 +28,7 @@ const delay = 100
export default function TxnPopup({ hash, success, summary, popKey }) {
const { chainId } = useWeb3React()
- let [count, setCount] = useState(1)
+ const [count, setCount] = useState(1)
const [isRunning, setIsRunning] = useState(true)
const [, , removePopup] = usePopups()
@@ -44,9 +44,9 @@ export default function TxnPopup({ hash, success, summary, popKey }) {
return (
setIsRunning(false)} onMouseLeave={() => setIsRunning(true)}>
{success ? (
-
+
) : (
-
+
)}
@@ -54,7 +54,7 @@ export default function TxnPopup({ hash, success, summary, popKey }) {
View on Etherscan
-
+
)
}
diff --git a/src/components/WalletModal/Option.tsx b/src/components/WalletModal/Option.tsx
index 97d6d737f7..52218a0362 100644
--- a/src/components/WalletModal/Option.tsx
+++ b/src/components/WalletModal/Option.tsx
@@ -88,16 +88,16 @@ const IconWrapper = styled.div<{ size?: number }>`
`
export default function Option({
- link = null,
- clickable = true,
- size = null,
- onClick = null,
- color,
- header,
- subheader = null,
- icon,
- active = false
- }) {
+ link = null,
+ clickable = true,
+ size = null,
+ onClick = null,
+ color,
+ header,
+ subheader = null,
+ icon,
+ active = false
+}) {
const content = (
@@ -106,7 +106,7 @@ export default function Option({
{active ? (
-
+
) : (
@@ -117,7 +117,7 @@ export default function Option({
{subheader && {subheader}}
-
+
)
diff --git a/src/components/WalletModal/PendingView.tsx b/src/components/WalletModal/PendingView.tsx
index dbefe47c39..7fcc796620 100644
--- a/src/components/WalletModal/PendingView.tsx
+++ b/src/components/WalletModal/PendingView.tsx
@@ -75,10 +75,10 @@ export default function PendingView({ uri = '', size, connector, error = false,
return (
- {!error && connector === walletconnect && }
+ {!error && connector === walletconnect && }
- {!error && }
+ {!error && }
{error ? (
Error connecting.
diff --git a/src/components/WalletModal/WalletConnectData.tsx b/src/components/WalletModal/WalletConnectData.tsx
index e61167270d..0beed98e6b 100644
--- a/src/components/WalletModal/WalletConnectData.tsx
+++ b/src/components/WalletModal/WalletConnectData.tsx
@@ -21,7 +21,7 @@ export default function WalletConnectData({ uri = '', size }: WalletConnectDataP
return (
{uri && (
-
+
)}
)
diff --git a/src/components/WalletModal/index.tsx b/src/components/WalletModal/index.tsx
index 16a6733868..2a955277d2 100644
--- a/src/components/WalletModal/index.tsx
+++ b/src/components/WalletModal/index.tsx
@@ -286,7 +286,7 @@ export default function WalletModal({ pendingTransactions, confirmedTransactions
return (
-
+
{error instanceof UnsupportedChainIdError ? 'Wrong Network' : 'Error connecting'}
@@ -313,7 +313,7 @@ export default function WalletModal({ pendingTransactions, confirmedTransactions
return (
-
+
{walletView !== WALLET_VIEWS.ACCOUNT ? (
@@ -358,12 +358,7 @@ export default function WalletModal({ pendingTransactions, confirmedTransactions
}
return (
-
+
{getModalContent()}
)
diff --git a/src/components/Web3Status/index.tsx b/src/components/Web3Status/index.tsx
index 0fffbda6ff..62edc2ea65 100644
--- a/src/components/Web3Status/index.tsx
+++ b/src/components/Web3Status/index.tsx
@@ -76,8 +76,8 @@ const Web3StatusConnect = styled(Web3StatusGeneric)`
}
${({ faded }) =>
- faded &&
- css`
+ faded &&
+ css`
background-color: ${({ theme }) => theme.blue5};
border: 1px solid ${({ theme }) => theme.blue5};
color: ${({ theme }) => theme.buttonSecondaryText};
@@ -140,29 +140,29 @@ export default function Web3Status() {
// handle the logo we want to show with the account
function getStatusIcon() {
if (connector === injected) {
- return
+ return
} else if (connector === walletconnect) {
return (
-
+
)
} else if (connector === walletlink) {
return (
-
+
)
} else if (connector === fortmatic) {
return (
-
+
)
} else if (connector === portis) {
return (
-
+
)
}
@@ -174,7 +174,7 @@ export default function Web3Status() {
{hasPendingTransactions ? (
- {pending?.length} Pending
+ {pending?.length} Pending
) : (
{ENSName || shortenAddress(account)}
@@ -185,7 +185,7 @@ export default function Web3Status() {
} else if (error) {
return (
-
+
{error instanceof UnsupportedChainIdError ? 'Wrong Network' : 'Error'}
)
@@ -205,7 +205,7 @@ export default function Web3Status() {
return (
<>
{getWeb3Status()}
-
+
>
)
}
diff --git a/src/connectors/Fortmatic.ts b/src/connectors/Fortmatic.ts
index dfbbd23c12..ba2ad42bbc 100644
--- a/src/connectors/Fortmatic.ts
+++ b/src/connectors/Fortmatic.ts
@@ -14,10 +14,7 @@ export class FortmaticConnector extends FortmaticConnectorCore {
if (!this.fortmatic) {
const { default: Fortmatic } = await import('fortmatic')
const { apiKey, chainId } = this as any
- this.fortmatic = new Fortmatic(
- apiKey,
- chainId === 1 || chainId === 4 ? undefined : chainIdToNetwork[chainId]
- )
+ this.fortmatic = new Fortmatic(apiKey, chainId === 1 || chainId === 4 ? undefined : chainIdToNetwork[chainId])
}
const provider = this.fortmatic.getProvider()
diff --git a/src/connectors/Network.ts b/src/connectors/Network.ts
index e76a2ffd13..13b51b5eff 100644
--- a/src/connectors/Network.ts
+++ b/src/connectors/Network.ts
@@ -3,13 +3,13 @@ import { NetworkConnector as NetworkConnectorCore } from '@web3-react/network-co
export class NetworkConnector extends NetworkConnectorCore {
pause() {
if ((this as any).active) {
- (this as any).providers[(this as any).currentChainId].stop()
+ ;(this as any).providers[(this as any).currentChainId].stop()
}
}
resume() {
if ((this as any).active) {
- (this as any).providers[(this as any).currentChainId].start()
+ ;(this as any).providers[(this as any).currentChainId].start()
}
}
}
diff --git a/src/contexts/Allowances.tsx b/src/contexts/Allowances.tsx
index d7d7693b86..6147ee3912 100644
--- a/src/contexts/Allowances.tsx
+++ b/src/contexts/Allowances.tsx
@@ -1,13 +1,27 @@
-import React, { createContext, useContext, useReducer, useMemo, useCallback, useEffect } from 'react'
-import { Token, TokenAmount, WETH } from '@uniswap/sdk'
+import { BigintIsh, Token, TokenAmount, WETH } from '@uniswap/sdk'
+import { BigNumber } from 'ethers/utils'
+import React, { createContext, useCallback, useContext, useEffect, useMemo, useReducer } from 'react'
import { useWeb3React } from '../hooks'
-import { safeAccess, isAddress, getTokenAllowance } from '../utils'
+import { getTokenAllowance, isAddress } from '../utils'
import { useBlockNumber } from './Application'
const UPDATE = 'UPDATE'
-const AllowancesContext = createContext([])
+interface AllowancesState {
+ [chainId: number]: {
+ [address: string]: {
+ [tokenAddress: string]: {
+ [spenderAddress: string]: {
+ value: BigintIsh
+ blockNumber: BigNumber
+ }
+ }
+ }
+ }
+}
+
+const AllowancesContext = createContext<[AllowancesState, any]>([{}, {}])
function useAllowancesContext() {
return useContext(AllowancesContext)
@@ -20,11 +34,11 @@ function reducer(state, { type, payload }) {
return {
...state,
[networkId]: {
- ...(safeAccess(state, [networkId]) || {}),
+ ...state?.[networkId],
[address]: {
- ...(safeAccess(state, [networkId, address]) || {}),
+ ...state?.[networkId]?.[address],
[tokenAddress]: {
- ...(safeAccess(state, [networkId, address, tokenAddress]) || {}),
+ ...state?.[networkId]?.[address]?.[tokenAddress],
[spenderAddress]: {
value,
blockNumber
@@ -34,9 +48,8 @@ function reducer(state, { type, payload }) {
}
}
}
- default: {
+ default:
throw Error(`Unexpected action type in AllowancesContext reducer: '${type}'.`)
- }
}
}
@@ -60,7 +73,7 @@ export function useAddressAllowance(address: string, token: Token, spenderAddres
const globalBlockNumber = useBlockNumber()
const [state, { update }] = useAllowancesContext()
- const { value, blockNumber } = safeAccess(state, [chainId, address, token?.address, spenderAddress]) || {}
+ const { value, blockNumber } = state?.[chainId]?.[address]?.[token?.address]?.[spenderAddress] ?? {}
useEffect(() => {
if (
@@ -92,6 +105,5 @@ export function useAddressAllowance(address: string, token: Token, spenderAddres
}
}, [address, token, spenderAddress, value, blockNumber, globalBlockNumber, chainId, library, update])
- const newTokenAmount: TokenAmount = value ? new TokenAmount(token, value) : null
- return newTokenAmount
+ return value ? new TokenAmount(token, value) : null
}
diff --git a/src/contexts/Application.tsx b/src/contexts/Application.tsx
index dfdea7f011..c0f6d5bc4a 100644
--- a/src/contexts/Application.tsx
+++ b/src/contexts/Application.tsx
@@ -1,7 +1,6 @@
import React, { createContext, useContext, useReducer, useMemo, useCallback, useEffect } from 'react'
import { useWeb3React } from '../hooks'
-import { safeAccess } from '../utils'
const BLOCK_NUMBER = 'BLOCK_NUMBER'
const USD_PRICE = 'USD_PRICE'
@@ -17,22 +16,25 @@ const USER_ADVANCED = 'USER_ADVANCED'
const TOGGLE_USER_ADVANCED = 'TOGGLE_USER_ADVANCED'
interface ApplicationState {
- BLOCK_NUMBER: {},
- USD_PRICE: {},
- POPUP_LIST: Array<{ key: number; show: boolean; content: React.ReactElement }>,
- POPUP_KEY: number,
- WALLET_MODAL_OPEN: boolean,
+ BLOCK_NUMBER: {}
+ USD_PRICE: {}
+ POPUP_LIST: Array<{ key: number; show: boolean; content: React.ReactElement }>
+ POPUP_KEY: number
+ WALLET_MODAL_OPEN: boolean
USER_ADVANCED: boolean
}
-const ApplicationContext = createContext<[ApplicationState, { [updater: string]: (...args: any[]) => void }]>([{
- [BLOCK_NUMBER]: {},
- [USD_PRICE]: {},
- [POPUP_LIST]: [],
- [POPUP_KEY]: 0,
- [WALLET_MODAL_OPEN]: false,
- [USER_ADVANCED]: false
-}, {}])
+const ApplicationContext = createContext<[ApplicationState, { [updater: string]: (...args: any[]) => void }]>([
+ {
+ [BLOCK_NUMBER]: {},
+ [USD_PRICE]: {},
+ [POPUP_LIST]: [],
+ [POPUP_KEY]: 0,
+ [WALLET_MODAL_OPEN]: false,
+ [USER_ADVANCED]: false
+ },
+ {}
+])
function useApplicationContext() {
return useContext(ApplicationContext)
@@ -45,7 +47,7 @@ function reducer(state: ApplicationState, { type, payload }): ApplicationState {
return {
...state,
[BLOCK_NUMBER]: {
- ...(safeAccess(state, [BLOCK_NUMBER]) || {}),
+ ...state?.[BLOCK_NUMBER],
[networkId]: blockNumber
}
}
@@ -80,9 +82,12 @@ export default function Provider({ children }) {
[USER_ADVANCED]: false
})
- const updateBlockNumber = useCallback((networkId, blockNumber) => {
- dispatch({ type: UPDATE_BLOCK_NUMBER, payload: { networkId, blockNumber } })
- }, [dispatch])
+ const updateBlockNumber = useCallback(
+ (networkId, blockNumber) => {
+ dispatch({ type: UPDATE_BLOCK_NUMBER, payload: { networkId, blockNumber } })
+ },
+ [dispatch]
+ )
const toggleWalletModal = useCallback(() => {
dispatch({ type: TOGGLE_WALLET_MODAL, payload: null })
@@ -92,9 +97,12 @@ export default function Provider({ children }) {
dispatch({ type: TOGGLE_USER_ADVANCED, payload: null })
}, [dispatch])
- const setPopups = useCallback(newList => {
- dispatch({ type: ADD_POPUP, payload: { newList } })
- }, [dispatch])
+ const setPopups = useCallback(
+ newList => {
+ dispatch({ type: ADD_POPUP, payload: { newList } })
+ },
+ [dispatch]
+ )
return (
void, (key: number) => void] {
+export function usePopups(): [
+ ApplicationState['POPUP_LIST'],
+ (content: React.ReactElement) => void,
+ (key: number) => void
+] {
const [state, { setPopups }] = useApplicationContext()
const index = state[POPUP_KEY]
diff --git a/src/contexts/Balances.tsx b/src/contexts/Balances.tsx
index fb87c6c51c..62c538ba00 100644
--- a/src/contexts/Balances.tsx
+++ b/src/contexts/Balances.tsx
@@ -411,7 +411,7 @@ export function useAllBalances(): Array {
if (!state || !state[chainId]) {
return {}
} else {
- let newBalances = {}
+ const newBalances = {}
Object.keys(state[chainId]).map(address => {
return Object.keys(state[chainId][address]).map(tokenAddress => {
if (state[chainId][address][tokenAddress].value) {
diff --git a/src/contexts/Transactions.tsx b/src/contexts/Transactions.tsx
index 226fcd83c1..03579faa02 100644
--- a/src/contexts/Transactions.tsx
+++ b/src/contexts/Transactions.tsx
@@ -3,21 +3,23 @@ import React, { createContext, useContext, useReducer, useMemo, useCallback, use
import TxnPopup from '../components/TxnPopup'
import { useWeb3React } from '../hooks'
-import { safeAccess } from '../utils'
import { useBlockNumber, usePopups } from './Application'
-const RESPONSE = 'response'
-const CUSTOM_DATA = 'CUSTOM_DATA'
-const BLOCK_NUMBER_CHECKED = 'BLOCK_NUMBER_CHECKED'
-const RECEIPT = 'receipt'
-const SUMMARY = 'summary'
-
const ADD = 'ADD'
const CHECK = 'CHECK'
const FINALIZE = 'FINALIZE'
interface TransactionState {
-
+ [chainId: number]: {
+ [txHash: string]: {
+ blockNumberChecked: any
+ response: {
+ customData?: any
+ summary: any
+ }
+ receipt: any
+ }
+ }
}
const TransactionsContext = createContext<[TransactionState, { [updater: string]: (...args: any[]) => void }]>([{}, {}])
@@ -26,21 +28,21 @@ export function useTransactionsContext() {
return useContext(TransactionsContext)
}
-function reducer(state, { type, payload }) {
+function reducer(state: TransactionState, { type, payload }): TransactionState {
switch (type) {
case ADD: {
const { networkId, hash, response } = payload
- if (safeAccess(state, [networkId, hash]) !== null) {
+ if (state[networkId]?.[hash]) {
throw Error('Attempted to add existing transaction.')
}
return {
...state,
[networkId]: {
- ...(safeAccess(state, [networkId]) || {}),
+ ...state[networkId],
[hash]: {
- [RESPONSE]: response
+ response
}
}
}
@@ -48,17 +50,17 @@ function reducer(state, { type, payload }) {
case CHECK: {
const { networkId, hash, blockNumber } = payload
- if (safeAccess(state, [networkId, hash]) === null) {
+ if (!state[networkId]?.[hash]) {
throw Error('Attempted to check non-existent transaction.')
}
return {
...state,
[networkId]: {
- ...(safeAccess(state, [networkId]) || {}),
+ ...state[networkId],
[hash]: {
- ...(safeAccess(state, [networkId, hash]) || {}),
- [BLOCK_NUMBER_CHECKED]: blockNumber
+ ...state[networkId]?.[hash],
+ blockNumberChecked: blockNumber
}
}
}
@@ -66,17 +68,17 @@ function reducer(state, { type, payload }) {
case FINALIZE: {
const { networkId, hash, receipt } = payload
- if (safeAccess(state, [networkId, hash]) === null) {
+ if (!state[networkId]?.[hash]) {
throw Error('Attempted to finalize non-existent transaction.')
}
return {
...state,
[networkId]: {
- ...(safeAccess(state, [networkId]) || {}),
+ ...state[networkId],
[hash]: {
- ...(safeAccess(state, [networkId, hash]) || {}),
- [RECEIPT]: receipt
+ ...state[networkId]?.[hash],
+ receipt
}
}
}
@@ -115,7 +117,7 @@ export function Updater() {
const globalBlockNumber = useBlockNumber()
const [state, { check, finalize }] = useTransactionsContext()
- const allTransactions = safeAccess(state, [chainId]) || {}
+ const allTransactions = state[chainId] ?? {}
// show popup on confirm
const [, addPopup] = usePopups()
@@ -125,7 +127,7 @@ export function Updater() {
let stale = false
Object.keys(allTransactions)
.filter(
- hash => !allTransactions[hash][RECEIPT] && allTransactions[hash][BLOCK_NUMBER_CHECKED] !== globalBlockNumber
+ hash => !allTransactions[hash].receipt && allTransactions[hash].blockNumberChecked !== globalBlockNumber
)
.forEach(hash => {
library
@@ -138,12 +140,22 @@ export function Updater() {
finalize(chainId, hash, receipt)
// add success or failure popup
if (receipt.status === 1) {
- addPopup()
+ addPopup(
+
+ )
} else {
addPopup(
-
+
)
}
}
@@ -173,11 +185,11 @@ export function useTransactionAdder() {
if (!(chainId || chainId === 0)) {
throw Error(`Invalid networkId '${chainId}`)
}
- const hash = safeAccess(response, ['hash'])
+ const hash = response?.hash
if (!hash) {
throw Error('No transaction hash found.')
}
- add(chainId, hash, { ...response, [CUSTOM_DATA]: customData, [SUMMARY]: summary })
+ add(chainId, hash, { ...response, customData: customData, summary })
},
[chainId, add]
)
@@ -188,18 +200,18 @@ export function useAllTransactions() {
const [state] = useTransactionsContext()
- return safeAccess(state, [chainId]) || {}
+ return state[chainId] || {}
}
export function usePendingApproval(tokenAddress) {
const allTransactions = useAllTransactions()
return (
Object.keys(allTransactions).filter(hash => {
- if (allTransactions[hash][RECEIPT]) {
+ if (allTransactions[hash]?.receipt) {
return false
- } else if (!allTransactions[hash][RESPONSE]) {
+ } else if (!allTransactions[hash]?.response) {
return false
- } else if (allTransactions[hash][RESPONSE][CUSTOM_DATA].approval !== tokenAddress) {
+ } else if (allTransactions[hash]?.response?.customData?.approval !== tokenAddress) {
return false
} else {
return true
diff --git a/src/hooks/useInterval.ts b/src/hooks/useInterval.ts
index 8ce326f6de..6674ab588c 100644
--- a/src/hooks/useInterval.ts
+++ b/src/hooks/useInterval.ts
@@ -6,8 +6,6 @@ export default function useInterval(callback: () => void, delay: null | number)
// Remember the latest callback.
useEffect(() => {
savedCallback.current = callback
- return () => {
- }
}, [callback])
// Set up the interval.
@@ -17,10 +15,8 @@ export default function useInterval(callback: () => void, delay: null | number)
}
if (delay !== null) {
- let id = setInterval(tick, delay)
+ const id = setInterval(tick, delay)
return () => clearInterval(id)
}
- return () => {
- }
}, [delay])
-}
\ No newline at end of file
+}
diff --git a/src/pages/App.tsx b/src/pages/App.tsx
index 29b3615191..c2528baead 100644
--- a/src/pages/App.tsx
+++ b/src/pages/App.tsx
@@ -99,21 +99,21 @@ export default function App() {
-
+
-
+
-
+
{/* this Suspense is for route code-splitting */}
- }/>
- }/>
- }/>
- }/>
- }/>
- }/>
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
} else {
- return
+ return
}
}}
/>
@@ -142,19 +142,19 @@ export default function App() {
const t1 =
tokens?.[1] === 'ETH' ? 'ETH' : isAddress(tokens?.[1]) ? isAddress(tokens[1]) : undefined
if (t0 && t1) {
- return
+ return
} else {
- return
+ return
}
}}
/>
-
+
-
+
-
+
diff --git a/src/pages/Pool/AddLiquidity.tsx b/src/pages/Pool/AddLiquidity.tsx
index 73c773e4da..05d1828232 100644
--- a/src/pages/Pool/AddLiquidity.tsx
+++ b/src/pages/Pool/AddLiquidity.tsx
@@ -675,7 +675,7 @@ function AddLiquidity({ token0, token1 }: AddLiquidityProps) {
)
}
- const pendingText: string = `Supplying ${parsedAmounts[Field.INPUT]?.toSignificant(6)} ${
+ const pendingText = `Supplying ${parsedAmounts[Field.INPUT]?.toSignificant(6)} ${
tokens[Field.INPUT]?.symbol
} ${'and'} ${parsedAmounts[Field.OUTPUT]?.toSignificant(6)} ${tokens[Field.OUTPUT]?.symbol}`
diff --git a/src/pages/Pool/RemoveLiquidity.tsx b/src/pages/Pool/RemoveLiquidity.tsx
index 120c4c220f..75f03ffb6c 100644
--- a/src/pages/Pool/RemoveLiquidity.tsx
+++ b/src/pages/Pool/RemoveLiquidity.tsx
@@ -179,15 +179,15 @@ export default function RemoveLiquidity({ token0, token1 }) {
const TokensDeposited: { [field: number]: TokenAmount } = {
[Field.TOKEN0]:
- pair &&
- totalPoolTokens &&
- userLiquidity &&
- pair.getLiquidityValue(tokens[Field.TOKEN0], totalPoolTokens, userLiquidity, false),
+ pair &&
+ totalPoolTokens &&
+ userLiquidity &&
+ pair.getLiquidityValue(tokens[Field.TOKEN0], totalPoolTokens, userLiquidity, false),
[Field.TOKEN1]:
- pair &&
- totalPoolTokens &&
- userLiquidity &&
- pair.getLiquidityValue(tokens[Field.TOKEN1], totalPoolTokens, userLiquidity, false)
+ pair &&
+ totalPoolTokens &&
+ userLiquidity &&
+ pair.getLiquidityValue(tokens[Field.TOKEN1], totalPoolTokens, userLiquidity, false)
}
const route: Route = pair
@@ -282,7 +282,7 @@ export default function RemoveLiquidity({ token0, token1 }) {
)
}
- const handleSliderChange = (newPercent) => {
+ const handleSliderChange = newPercent => {
onUserInput(
Field.LIQUIDITY,
new TokenAmount(
@@ -425,6 +425,13 @@ export default function RemoveLiquidity({ token0, token1 }) {
})
}
+ function resetModalState() {
+ setSigned(false)
+ setSigInputs(null)
+ setAttemptedRemoval(false)
+ setPendingConfirmation(true)
+ }
+
async function onRemove() {
setAttemptedRemoval(true)
const router = getRouterContract(chainId, library, account)
@@ -482,13 +489,13 @@ export default function RemoveLiquidity({ token0, token1 }) {
addTransaction(
response,
'Remove ' +
- parsedAmounts[Field.TOKEN0]?.toSignificant(3) +
- ' ' +
- tokens[Field.TOKEN0]?.symbol +
- ' and ' +
- parsedAmounts[Field.TOKEN1]?.toSignificant(3) +
- ' ' +
- tokens[Field.TOKEN1]?.symbol
+ parsedAmounts[Field.TOKEN0]?.toSignificant(3) +
+ ' ' +
+ tokens[Field.TOKEN0]?.symbol +
+ ' and ' +
+ parsedAmounts[Field.TOKEN1]?.toSignificant(3) +
+ ' ' +
+ tokens[Field.TOKEN1]?.symbol
)
})
)
@@ -499,13 +506,6 @@ export default function RemoveLiquidity({ token0, token1 }) {
})
}
- function resetModalState() {
- setSigned(false)
- setSigInputs(null)
- setAttemptedRemoval(false)
- setPendingConfirmation(true)
- }
-
function modalHeader() {
return (
@@ -514,21 +514,21 @@ export default function RemoveLiquidity({ token0, token1 }) {
{!!parsedAmounts[Field.TOKEN0] && parsedAmounts[Field.TOKEN0].toSignificant(6)}
-
+
{tokens[Field.TOKEN0]?.symbol || ''}
-
+
{!!parsedAmounts[Field.TOKEN1] && parsedAmounts[Field.TOKEN1].toSignificant(6)}
-
+
{tokens[Field.TOKEN1]?.symbol || ''}
@@ -596,7 +596,7 @@ export default function RemoveLiquidity({ token0, token1 }) {
)
}
- const pendingText: string = `Removing ${parsedAmounts[Field.TOKEN0]?.toSignificant(6)} ${
+ const pendingText = `Removing ${parsedAmounts[Field.TOKEN0]?.toSignificant(6)} ${
tokens[Field.TOKEN0]?.symbol
} and ${parsedAmounts[Field.TOKEN1]?.toSignificant(6)} ${tokens[Field.TOKEN1]?.symbol}`
@@ -637,7 +637,7 @@ export default function RemoveLiquidity({ token0, token1 }) {
{!showAdvanced && (
-
+
)}
{!showAdvanced && (
@@ -660,7 +660,7 @@ export default function RemoveLiquidity({ token0, token1 }) {
{!showAdvanced && (
<>
-
+
{' '}
@@ -669,7 +669,7 @@ export default function RemoveLiquidity({ token0, token1 }) {
{formattedAmounts[Field.TOKEN0] ? formattedAmounts[Field.TOKEN0] : '-'}
-
+
{tokens[Field.TOKEN0]?.symbol}
@@ -680,7 +680,7 @@ export default function RemoveLiquidity({ token0, token1 }) {
{formattedAmounts[Field.TOKEN1] ? formattedAmounts[Field.TOKEN1] : '-'}
-
+
{tokens[Field.TOKEN1]?.symbol}
@@ -706,7 +706,7 @@ export default function RemoveLiquidity({ token0, token1 }) {
inputId="liquidityAmount"
/>
-
+
-
+
{
+ .filter(pairAddress => {
return (
allBalances &&
allBalances[account] &&
diff --git a/src/pages/Swap/index.tsx b/src/pages/Swap/index.tsx
index b551da1024..e8a655d4dc 100644
--- a/src/pages/Swap/index.tsx
+++ b/src/pages/Swap/index.tsx
@@ -1,6 +1,7 @@
import React from 'react'
import ExchangePage from '../../components/ExchangePage'
+import { QueryParams } from '../../utils'
-export default function Swap({ params }) {
+export default function Swap({ params }: { params: QueryParams }) {
return
}
diff --git a/src/theme/components.tsx b/src/theme/components.tsx
index 6f7f79c627..82a354b300 100644
--- a/src/theme/components.tsx
+++ b/src/theme/components.tsx
@@ -2,10 +2,9 @@ import styled, { keyframes } from 'styled-components'
import { darken } from 'polished'
import { X } from 'react-feather'
-export const Button = styled.button.attrs<{ warning: boolean }, { backgroundColor: string }>(
- ({ warning, theme }) => ({
- backgroundColor: warning ? theme.red1 : theme.blue1
- }))`
+export const Button = styled.button.attrs<{ warning: boolean }, { backgroundColor: string }>(({ warning, theme }) => ({
+ backgroundColor: warning ? theme.red1 : theme.blue1
+}))`
padding: 1rem 2rem 1rem 2rem;
border-radius: 3rem;
cursor: pointer;
@@ -33,7 +32,7 @@ export const Button = styled.button.attrs<{ warning: boolean }, { backgroundColo
}
`
-export const CloseIcon = styled(X)<{ onClick: () => void}>`
+export const CloseIcon = styled(X)<{ onClick: () => void }>`
cursor: pointer;
`
diff --git a/src/theme/index.tsx b/src/theme/index.tsx
index 148caf9e14..76d287a4b0 100644
--- a/src/theme/index.tsx
+++ b/src/theme/index.tsx
@@ -3,12 +3,12 @@ import styled, {
ThemeProvider as StyledComponentsThemeProvider,
createGlobalStyle,
css,
+ DefaultTheme
} from 'styled-components'
import { getQueryParam, checkSupportedTheme } from '../utils'
import { SUPPORTED_THEMES } from '../constants'
import { useDarkModeManager } from '../contexts/LocalStorage'
import { Text } from 'rebass'
-import { UniswapTheme } from './styled'
export * from './components'
@@ -19,20 +19,95 @@ const MEDIA_WIDTHS = {
upToLarge: 1280
}
-const mediaWidthTemplates: { [width in keyof typeof MEDIA_WIDTHS]: typeof css } =
- Object.keys(MEDIA_WIDTHS)
- .reduce((accumulator, size) => {
- accumulator[size] = (a, b, c) => css`
- @media (max-width: ${MEDIA_WIDTHS[size]}px) {
- ${css(a, b, c)}
- }
- `
- return accumulator
- }, {}) as any
+const mediaWidthTemplates: { [width in keyof typeof MEDIA_WIDTHS]: typeof css } = Object.keys(MEDIA_WIDTHS).reduce(
+ (accumulator, size) => {
+ accumulator[size] = (a, b, c) => css`
+ @media (max-width: ${MEDIA_WIDTHS[size]}px) {
+ ${css(a, b, c)}
+ }
+ `
+ return accumulator
+ },
+ {}
+) as any
const white = '#FFFFFF'
const black = '#000000'
+export function theme(darkMode: boolean): DefaultTheme {
+ return {
+ // base
+ white,
+ black,
+
+ // text
+ text1: darkMode ? '#FFFFFF' : '#000000',
+ text2: darkMode ? '#CED0D9' : '#565A69',
+ text3: darkMode ? '#6C7284' : '#888D9B',
+ text4: darkMode ? '#565A69' : '#C3C5CB',
+ text5: '#EDEEF2',
+
+ // backgrounds / greys
+ bg1: darkMode ? '#212429' : '#FFFFFF',
+ bg2: darkMode ? '#2C2F36' : '#F7F8FA',
+ bg3: darkMode ? '#40444F' : '#EDEEF2',
+ bg4: darkMode ? '#565A69' : '#CED0D9',
+ bg5: darkMode ? '#565A69' : '#888D9B',
+
+ modalBG: darkMode ? 'rgba(0,0,0,0.85)' : 'rgba(0,0,0,0.6)',
+ advancedBG: darkMode ? 'rgba(0,0,0,0.15)' : 'rgba(255,255,255,0.6)',
+
+ //blues
+ blue1: darkMode ? '#2172E5' : '#ff007a',
+ blue2: darkMode ? '#3680E7' : '#1966D2',
+ blue3: darkMode ? '#4D8FEA' : '#165BBB',
+ // blue4: darkMode ? '#153d6f70' : '#C4D9F8',
+ // blue5: darkMode ? '#153d6f70' : '#EBF4FF',
+ blue4: darkMode ? '#153d6f70' : '#F6DDE8',
+ blue5: darkMode ? '#153d6f70' : '#FDEAF1',
+
+ buttonSecondaryText: darkMode ? '#6da8ff' : '#ff007a',
+
+ // blue1: '#ff007a',
+ // blue4: '#F6DDE8',
+ // blue5: '#FDEAF1',
+
+ // pinks
+ pink1: '#DC6BE5',
+ pink2: darkMode ? '#2172E5' : '#ff007a',
+ pink3: darkMode ? '#17000b26' : '#F6DDE8',
+ pink4: darkMode ? '#17000b26' : '#FDEAF1',
+
+ // other
+ red1: '#FF6871',
+ green1: '#27AE60',
+ yellow1: '#FFE270',
+ yellow2: '#F3841E',
+
+ grids: {
+ sm: 8,
+ md: 12,
+ lg: 24
+ },
+
+ //shadows
+ shadow1: darkMode ? '#000' : '#2F80ED',
+
+ // media queries
+ mediaWidth: mediaWidthTemplates,
+
+ // css snippets
+ flexColumnNoWrap: css`
+ display: flex;
+ flex-flow: column nowrap;
+ `,
+ flexRowNoWrap: css`
+ display: flex;
+ flex-flow: row nowrap;
+ `
+ }
+}
+
export default function ThemeProvider({ children }) {
const [darkMode, toggleDarkMode] = useDarkModeManager()
const themeURL = checkSupportedTheme(getQueryParam(window.location, 'theme'))
@@ -40,8 +115,8 @@ export default function ThemeProvider({ children }) {
? themeURL.toUpperCase() === SUPPORTED_THEMES.DARK
? true
: themeURL.toUpperCase() === SUPPORTED_THEMES.LIGHT
- ? false
- : darkMode
+ ? false
+ : darkMode
: darkMode
useEffect(() => {
toggleDarkMode(themeToRender)
@@ -49,78 +124,6 @@ export default function ThemeProvider({ children }) {
return {children}
}
-export const theme: (darkMode: boolean) => UniswapTheme = darkMode => ({
- // base
- white,
- black,
-
- // text
- text1: darkMode ? '#FFFFFF' : '#000000',
- text2: darkMode ? '#CED0D9' : '#565A69',
- text3: darkMode ? '#6C7284' : '#888D9B',
- text4: darkMode ? '#565A69' : '#C3C5CB',
- text5: '#EDEEF2',
-
- // backgrounds / greys
- bg1: darkMode ? '#212429' : '#FFFFFF',
- bg2: darkMode ? '#2C2F36' : '#F7F8FA',
- bg3: darkMode ? '#40444F' : '#EDEEF2',
- bg4: darkMode ? '#565A69' : '#CED0D9',
- bg5: darkMode ? '#565A69' : '#888D9B',
-
- modalBG: darkMode ? 'rgba(0,0,0,0.85)' : 'rgba(0,0,0,0.6)',
- advancedBG: darkMode ? 'rgba(0,0,0,0.15)' : 'rgba(255,255,255,0.6)',
-
- //blues
- blue1: darkMode ? '#2172E5' : '#ff007a',
- blue2: darkMode ? '#3680E7' : '#1966D2',
- blue3: darkMode ? '#4D8FEA' : '#165BBB',
- // blue4: darkMode ? '#153d6f70' : '#C4D9F8',
- // blue5: darkMode ? '#153d6f70' : '#EBF4FF',
- blue4: darkMode ? '#153d6f70' : '#F6DDE8',
- blue5: darkMode ? '#153d6f70' : '#FDEAF1',
-
- buttonSecondaryText: darkMode ? '#6da8ff' : '#ff007a',
-
- // blue1: '#ff007a',
- // blue4: '#F6DDE8',
- // blue5: '#FDEAF1',
-
- // pinks
- pink1: '#DC6BE5',
- pink2: darkMode ? '#2172E5' : '#ff007a',
- pink3: darkMode ? '#17000b26' : '#F6DDE8',
- pink4: darkMode ? '#17000b26' : '#FDEAF1',
-
- // other
- red1: '#FF6871',
- green1: '#27AE60',
- yellow1: '#FFE270',
- yellow2: '#F3841E',
-
- grids: {
- sm: 8,
- md: 12,
- lg: 24
- },
-
- //shadows
- shadow1: darkMode ? '#000' : '#2F80ED',
-
- // media queries
- mediaWidth: mediaWidthTemplates,
-
- // css snippets
- flexColumnNoWrap: css`
- display: flex;
- flex-flow: column nowrap;
- `,
- flexRowNoWrap: css`
- display: flex;
- flex-flow: row nowrap;
- `
-})
-
const TextWrapper = styled(Text)`
color = ${({ color, theme }) => theme[color]}
`
diff --git a/src/theme/styled.d.ts b/src/theme/styled.d.ts
index 09d25657b2..54c0cc9f0a 100644
--- a/src/theme/styled.d.ts
+++ b/src/theme/styled.d.ts
@@ -1,66 +1,62 @@
import { css, FlattenSimpleInterpolation } from 'styled-components'
-export interface UniswapTheme {
- // base
- white: string
- black: string
-
- // text
- text1: string
- text2: string
- text3: string
- text4: string
- text5: string
-
- // backgrounds / greys
- bg1: string
- bg2: string
- bg3: string
- bg4: string
- bg5: string
-
- modalBG: string
- advancedBG: string
-
- //blues
- blue1: string
- blue2: string
- blue3: string
- blue4: string
- blue5: string
-
- buttonSecondaryText: string
-
- // pinks
- pink1: string
- pink2: string
- pink3: string
- pink4: string
-
- // other
- red1: string
- green1: string
- yellow1: string
- yellow2: string
-
- grids: {
- sm: number,
- md: number,
- lg: number
- },
-
- // shadows
- shadow1: string
-
- // media queries
- mediaWidth: { [width in keyof typeof MEDIA_WIDTHS]: typeof css },
- // css snippets
- flexColumnNoWrap: FlattenSimpleInterpolation
- flexRowNoWrap: FlattenSimpleInterpolation
-}
-
declare module 'styled-components' {
- export interface DefaultTheme extends UniswapTheme {
+ export interface DefaultTheme {
+ // base
+ white: string
+ black: string
+
+ // text
+ text1: string
+ text2: string
+ text3: string
+ text4: string
+ text5: string
+
+ // backgrounds / greys
+ bg1: string
+ bg2: string
+ bg3: string
+ bg4: string
+ bg5: string
+
+ modalBG: string
+ advancedBG: string
+
+ //blues
+ blue1: string
+ blue2: string
+ blue3: string
+ blue4: string
+ blue5: string
+
+ buttonSecondaryText: string
+
+ // pinks
+ pink1: string
+ pink2: string
+ pink3: string
+ pink4: string
+
+ // other
+ red1: string
+ green1: string
+ yellow1: string
+ yellow2: string
+
+ grids: {
+ sm: number
+ md: number
+ lg: number
+ }
+
+ // shadows
+ shadow1: string
+
+ // media queries
+ mediaWidth: { [width in keyof typeof MEDIA_WIDTHS]: typeof css }
+ // css snippets
+ flexColumnNoWrap: FlattenSimpleInterpolation
+ flexRowNoWrap: FlattenSimpleInterpolation
}
}
-
diff --git a/src/utils/index.test.ts b/src/utils/index.test.ts
index b62cbe8d52..a2f2605bbe 100644
--- a/src/utils/index.test.ts
+++ b/src/utils/index.test.ts
@@ -9,4 +9,4 @@ describe('utils', () => {
expect(getEtherscanLink(1, 'abc', 'address')).toEqual('https://etherscan.io/address/abc')
})
})
-})
\ No newline at end of file
+})
diff --git a/src/utils/index.ts b/src/utils/index.ts
index 24826bac21..1ed8958c72 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -12,20 +12,19 @@ import { ROUTER_ADDRESS, SUPPORTED_THEMES } from '../constants'
import ERC20_ABI from '../constants/abis/erc20.json'
import ERC20_BYTES32_ABI from '../constants/abis/erc20_bytes32.json'
+export function isAddress(value: any): string | false {
+ try {
+ return getAddress(value.toLowerCase())
+ } catch {
+ return false
+ }
+}
+
export enum ERROR_CODES {
TOKEN_SYMBOL = 1,
TOKEN_DECIMALS = 2
}
-export function safeAccess(object, path) {
- return object
- ? path.reduce(
- (accumulator, currentValue) => (accumulator && accumulator[currentValue] ? accumulator[currentValue] : null),
- object
- )
- : null
-}
-
const ETHERSCAN_PREFIXES = {
1: '',
3: 'ropsten.',
@@ -49,7 +48,7 @@ export function getEtherscanLink(networkId: 1 | 3 | 4 | 5 | 42 | any, data: stri
}
export function getQueryParam(windowLocation, name) {
- var q = windowLocation.search.match(new RegExp('[?&]' + name + '=([^?]*)'))
+ const q = windowLocation.search.match(new RegExp('[?&]' + name + '=([^?]*)'))
return q && q[1]
}
@@ -122,18 +121,6 @@ export function shortenAddress(address, digits = 4) {
return `${address.substring(0, digits + 2)}...${address.substring(42 - digits)}`
}
-export function shortenTransactionHash(hash, digits = 4) {
- return `${hash.substring(0, digits + 2)}...${hash.substring(66 - digits)}`
-}
-
-export function isAddress(value: any): string | false {
- try {
- return getAddress(value.toLowerCase())
- } catch {
- return false
- }
-}
-
export function calculateGasMargin(value: BigNumber) {
return value.mul(BigNumber.from(10000).add(BigNumber.from(1000))).div(BigNumber.from(10000)) // add 10%
}
diff --git a/tsconfig.json b/tsconfig.json
index 0bf892bb35..e5ef24e371 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -20,7 +20,8 @@
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"types": [
- "react-spring"
+ "react-spring",
+ "jest"
]
},
"exclude": [
diff --git a/yarn.lock b/yarn.lock
index 88ad02d534..1128d316ca 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2630,7 +2630,7 @@
dependencies:
"@types/yargs-parser" "*"
-"@typescript-eslint/eslint-plugin@^2.10.0":
+"@typescript-eslint/eslint-plugin@^2.10.0", "@typescript-eslint/eslint-plugin@^2.31.0":
version "2.31.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.31.0.tgz#942c921fec5e200b79593c71fafb1e3f57aa2e36"
integrity sha512-iIC0Pb8qDaoit+m80Ln/aaeu9zKQdOLF4SHcGLarSeY1gurW6aU4JsOPMjKQwXlw70MvWKZQc6S2NamA8SJ/gg==
@@ -2650,7 +2650,7 @@
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"
-"@typescript-eslint/parser@^2.10.0":
+"@typescript-eslint/parser@^2.10.0", "@typescript-eslint/parser@^2.31.0":
version "2.31.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.31.0.tgz#beddd4e8efe64995108b229b2862cd5752d40d6f"
integrity sha512-uph+w6xUOlyV2DLSC6o+fBDzZ5i7+3/TxAsH4h3eC64tlga57oMb96vVlXoMwjR/nN+xyWlsnxtbDkB46M2EPQ==
@@ -6772,6 +6772,13 @@ escodegen@^1.11.0, escodegen@^1.9.1:
optionalDependencies:
source-map "~0.6.1"
+eslint-config-prettier@^6.11.0:
+ version "6.11.0"
+ resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.11.0.tgz#f6d2238c1290d01c859a8b5c1f7d352a0b0da8b1"
+ integrity sha512-oB8cpLWSAjOVFEJhhyMZh6NOEOtBVziaqdDQ86+qhDHFbZXoRTM7pNSvFRfW/W/L/LrQ38C99J5CGuRBBzBsdA==
+ dependencies:
+ get-stdin "^6.0.0"
+
eslint-config-react-app@^5.2.1:
version "5.2.1"
resolved "https://registry.yarnpkg.com/eslint-config-react-app/-/eslint-config-react-app-5.2.1.tgz#698bf7aeee27f0cea0139eaef261c7bf7dd623df"
@@ -6846,12 +6853,19 @@ eslint-plugin-jsx-a11y@6.2.3:
has "^1.0.3"
jsx-ast-utils "^2.2.1"
+eslint-plugin-prettier@^3.1.3:
+ version "3.1.3"
+ resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.3.tgz#ae116a0fc0e598fdae48743a4430903de5b4e6ca"
+ integrity sha512-+HG5jmu/dN3ZV3T6eCD7a4BlAySdN7mLIbJYo0z1cFQuI+r2DiTJEFeF68ots93PsnrMxbzIZ2S/ieX+mkrBeQ==
+ dependencies:
+ prettier-linter-helpers "^1.0.0"
+
eslint-plugin-react-hooks@^1.6.1:
version "1.7.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-1.7.0.tgz#6210b6d5a37205f0b92858f895a4e827020a7d04"
integrity sha512-iXTCFcOmlWvw4+TOE8CLWj6yX1GwzT0Y6cUfHHZqWnSk144VmVIRcVGtUAzrLES7C798lmvnt02C7rxaOX1HNA==
-eslint-plugin-react@7.19.0:
+eslint-plugin-react@7.19.0, eslint-plugin-react@^7.19.0:
version "7.19.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.19.0.tgz#6d08f9673628aa69c5559d33489e855d83551666"
integrity sha512-SPT8j72CGuAP+JFbT0sJHOB80TX/pu44gQ4vXH/cq+hQTiY2PuZ6IHkqXJV6x1b28GDdo1lbInjKUrrdUf0LOQ==
@@ -6904,7 +6918,7 @@ eslint-visitor-keys@^1.0.0, eslint-visitor-keys@^1.1.0:
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz#e2a82cea84ff246ad6fb57f9bde5b46621459ec2"
integrity sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A==
-eslint@^6.6.0:
+eslint@^6.6.0, eslint@^6.8.0:
version "6.8.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-6.8.0.tgz#62262d6729739f9275723824302fb227c8c93ffb"
integrity sha512-K+Iayyo2LtyYhDSYwz5D5QdWw0hCacNzyq1Y821Xna2xSJj7cijoLLYmLxTQgcgZ9mC61nryMy9S7GRbYpI5Ig==
@@ -7800,6 +7814,11 @@ fast-deep-equal@^3.1.1:
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz#545145077c501491e33b15ec408c294376e94ae4"
integrity sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA==
+fast-diff@^1.1.2:
+ version "1.2.0"
+ resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
+ integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==
+
fast-glob@^2.0.2:
version "2.2.7"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-2.2.7.tgz#6953857c3afa475fff92ee6015d52da70a4cd39d"
@@ -8376,6 +8395,11 @@ get-own-enumerable-property-symbols@^3.0.0:
resolved "https://registry.yarnpkg.com/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-3.0.2.tgz#b5fde77f22cbe35f390b4e089922c50bce6ef664"
integrity sha512-I0UBV/XOz1XkIJHEUDMZAbzCThU/H8DxmSfmdGcKPnVhu2VfFqr34jr9777IyaTYvxjedWhqVIilEDsCdP5G6g==
+get-stdin@^6.0.0:
+ version "6.0.0"
+ resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b"
+ integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==
+
get-stream@^2.2.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-2.3.1.tgz#5f38f93f346009666ee0150a054167f91bdd95de"
@@ -13448,6 +13472,13 @@ prepend-http@^2.0.0:
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897"
integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=
+prettier-linter-helpers@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b"
+ integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==
+ dependencies:
+ fast-diff "^1.1.2"
+
prettier@^1.17.0:
version "1.19.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"