Commit 66a20062 authored by Moody Salem's avatar Moody Salem

more strictness everywhere, fix a pair pricing issue in mint/hooks.ts

parent 610b7f44
...@@ -282,6 +282,7 @@ export default function AccountDetails({ ...@@ -282,6 +282,7 @@ export default function AccountDetails({
</> </>
) )
} }
return null
} }
const clearAllTransactionsCallback = useCallback( const clearAllTransactionsCallback = useCallback(
......
...@@ -65,11 +65,6 @@ const Input = styled.input<{ error?: boolean }>` ...@@ -65,11 +65,6 @@ const Input = styled.input<{ error?: boolean }>`
} }
` `
interface Value {
address: string
name?: string
}
export default function AddressInputPanel({ export default function AddressInputPanel({
id, id,
value, value,
......
...@@ -55,7 +55,7 @@ export default function PopupItem({ ...@@ -55,7 +55,7 @@ export default function PopupItem({
const removePopup = useRemovePopup() const removePopup = useRemovePopup()
const removeThisPopup = useCallback(() => removePopup(popKey), [popKey, removePopup]) const removeThisPopup = useCallback(() => removePopup(popKey), [popKey, removePopup])
useEffect(() => { useEffect(() => {
if (removeAfterMs === null) return if (removeAfterMs === null) return undefined
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
removeThisPopup() removeThisPopup()
......
import React, { useMemo } from 'react' import React, { useMemo } from 'react'
import { AbstractConnector } from '@web3-react/abstract-connector'
import styled, { css } from 'styled-components' import styled, { css } from 'styled-components'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { useWeb3React, UnsupportedChainIdError } from '@web3-react/core' import { useWeb3React, UnsupportedChainIdError } from '@web3-react/core'
...@@ -132,10 +133,41 @@ const SOCK = ( ...@@ -132,10 +133,41 @@ const SOCK = (
</span> </span>
) )
export default function Web3Status() { // eslint-disable-next-line react/prop-types
function StatusIcon({ connector }: { connector: AbstractConnector }) {
if (connector === injected) {
return <Identicon />
} else if (connector === walletconnect) {
return (
<IconWrapper size={16}>
<img src={WalletConnectIcon} alt={''} />
</IconWrapper>
)
} else if (connector === walletlink) {
return (
<IconWrapper size={16}>
<img src={CoinbaseWalletIcon} alt={''} />
</IconWrapper>
)
} else if (connector === fortmatic) {
return (
<IconWrapper size={16}>
<img src={FortmaticIcon} alt={''} />
</IconWrapper>
)
} else if (connector === portis) {
return (
<IconWrapper size={16}>
<img src={PortisIcon} alt={''} />
</IconWrapper>
)
}
return null
}
function Web3StatusInner() {
const { t } = useTranslation() const { t } = useTranslation()
const { active, account, connector, error } = useWeb3React() const { account, connector, error } = useWeb3React()
const contextNetwork = useWeb3React(NetworkContextName)
const { ENSName } = useENSName(account) const { ENSName } = useENSName(account)
...@@ -147,75 +179,58 @@ export default function Web3Status() { ...@@ -147,75 +179,58 @@ export default function Web3Status() {
}, [allTransactions]) }, [allTransactions])
const pending = sortedRecentTransactions.filter(tx => !tx.receipt).map(tx => tx.hash) const pending = sortedRecentTransactions.filter(tx => !tx.receipt).map(tx => tx.hash)
const confirmed = sortedRecentTransactions.filter(tx => tx.receipt).map(tx => tx.hash)
const hasPendingTransactions = !!pending.length const hasPendingTransactions = !!pending.length
const hasSocks = useHasSocks() const hasSocks = useHasSocks()
const toggleWalletModal = useWalletModalToggle() const toggleWalletModal = useWalletModalToggle()
// handle the logo we want to show with the account if (account) {
function getStatusIcon() { return (
if (connector === injected) { <Web3StatusConnected id="web3-status-connected" onClick={toggleWalletModal} pending={hasPendingTransactions}>
return <Identicon /> {hasPendingTransactions ? (
} else if (connector === walletconnect) { <RowBetween>
return ( <Text>{pending?.length} Pending</Text> <Loader stroke="white" />
<IconWrapper size={16}> </RowBetween>
<img src={WalletConnectIcon} alt={''} /> ) : (
</IconWrapper> <>
) {hasSocks ? SOCK : null}
} else if (connector === walletlink) { <Text>{ENSName || shortenAddress(account)}</Text>
return ( </>
<IconWrapper size={16}> )}
<img src={CoinbaseWalletIcon} alt={''} /> {!hasPendingTransactions && <StatusIcon connector={connector} />}
</IconWrapper> </Web3StatusConnected>
) )
} else if (connector === fortmatic) { } else if (error) {
return ( return (
<IconWrapper size={16}> <Web3StatusError onClick={toggleWalletModal}>
<img src={FortmaticIcon} alt={''} /> <NetworkIcon />
</IconWrapper> <Text>{error instanceof UnsupportedChainIdError ? 'Wrong Network' : 'Error'}</Text>
) </Web3StatusError>
} else if (connector === portis) { )
return ( } else {
<IconWrapper size={16}> return (
<img src={PortisIcon} alt={''} /> <Web3StatusConnect id="connect-wallet" onClick={toggleWalletModal} faded={!account}>
</IconWrapper> <Text>{t('Connect to a wallet')}</Text>
) </Web3StatusConnect>
} )
} }
}
function getWeb3Status() { export default function Web3Status() {
if (account) { const { active, account } = useWeb3React()
return ( const contextNetwork = useWeb3React(NetworkContextName)
<Web3StatusConnected id="web3-status-connected" onClick={toggleWalletModal} pending={hasPendingTransactions}>
{hasPendingTransactions ? ( const { ENSName } = useENSName(account)
<RowBetween>
<Text>{pending?.length} Pending</Text> <Loader stroke="white" /> const allTransactions = useAllTransactions()
</RowBetween>
) : ( const sortedRecentTransactions = useMemo(() => {
<> const txs = Object.values(allTransactions)
{hasSocks ? SOCK : null} return txs.filter(recentTransactionsOnly).sort(newTranscationsFirst)
<Text>{ENSName || shortenAddress(account)}</Text> }, [allTransactions])
</>
)} const pending = sortedRecentTransactions.filter(tx => !tx.receipt).map(tx => tx.hash)
{!hasPendingTransactions && getStatusIcon()} const confirmed = sortedRecentTransactions.filter(tx => tx.receipt).map(tx => tx.hash)
</Web3StatusConnected>
)
} else if (error) {
return (
<Web3StatusError onClick={toggleWalletModal}>
<NetworkIcon />
<Text>{error instanceof UnsupportedChainIdError ? 'Wrong Network' : 'Error'}</Text>
</Web3StatusError>
)
} else {
return (
<Web3StatusConnect id="connect-wallet" onClick={toggleWalletModal} faded={!account}>
<Text>{t('Connect to a wallet')}</Text>
</Web3StatusConnect>
)
}
}
if (!contextNetwork.active && !active) { if (!contextNetwork.active && !active) {
return null return null
...@@ -223,7 +238,7 @@ export default function Web3Status() { ...@@ -223,7 +238,7 @@ export default function Web3Status() {
return ( return (
<> <>
{getWeb3Status()} <Web3StatusInner />
<WalletModal ENSName={ENSName} pendingTransactions={pending} confirmedTransactions={confirmed} /> <WalletModal ENSName={ENSName} pendingTransactions={pending} confirmedTransactions={confirmed} />
</> </>
) )
......
...@@ -82,6 +82,6 @@ export function useInactiveListener(suppress = false) { ...@@ -82,6 +82,6 @@ export function useInactiveListener(suppress = false) {
} }
} }
} }
return return undefined
}, [active, error, suppress, activate]) }, [active, error, suppress, activate])
} }
...@@ -19,7 +19,7 @@ export default function useCopyClipboard(timeout = 500): [boolean, (toCopy: stri ...@@ -19,7 +19,7 @@ export default function useCopyClipboard(timeout = 500): [boolean, (toCopy: stri
clearTimeout(hide) clearTimeout(hide)
} }
} }
return return undefined
}, [isCopied, setIsCopied, timeout]) }, [isCopied, setIsCopied, timeout])
return [isCopied, staticCopy] return [isCopied, staticCopy]
......
...@@ -20,6 +20,6 @@ export default function useInterval(callback: () => void, delay: null | number, ...@@ -20,6 +20,6 @@ export default function useInterval(callback: () => void, delay: null | number,
const id = setInterval(tick, delay) const id = setInterval(tick, delay)
return () => clearInterval(id) return () => clearInterval(id)
} }
return return undefined
}, [delay, leading]) }, [delay, leading])
} }
...@@ -16,7 +16,7 @@ export default function useIsWindowVisible(): boolean { ...@@ -16,7 +16,7 @@ export default function useIsWindowVisible(): boolean {
}, [setFocused]) }, [setFocused])
useEffect(() => { useEffect(() => {
if (!VISIBILITY_STATE_SUPPORTED) return if (!VISIBILITY_STATE_SUPPORTED) return undefined
document.addEventListener('visibilitychange', listener) document.addEventListener('visibilitychange', listener)
return () => { return () => {
......
...@@ -31,7 +31,7 @@ export default function Updater() { ...@@ -31,7 +31,7 @@ export default function Updater() {
// attach/detach listeners // attach/detach listeners
useEffect(() => { useEffect(() => {
if (!library || !chainId || !windowVisible) return if (!library || !chainId || !windowVisible) return undefined
setState({ chainId, blockNumber: null }) setState({ chainId, blockNumber: null })
......
...@@ -72,7 +72,7 @@ export function useDerivedMintInfo( ...@@ -72,7 +72,7 @@ export function useDerivedMintInfo(
if (otherTypedValue && currencies[dependentField]) { if (otherTypedValue && currencies[dependentField]) {
return tryParseAmount(otherTypedValue, currencies[dependentField]) return tryParseAmount(otherTypedValue, currencies[dependentField])
} }
return return undefined
} else if (independentAmount) { } else if (independentAmount) {
// we wrap the currencies just to get the price in terms of the other token // we wrap the currencies just to get the price in terms of the other token
const wrappedIndependentAmount = wrappedCurrencyAmount(independentAmount, chainId) const wrappedIndependentAmount = wrappedCurrencyAmount(independentAmount, chainId)
...@@ -85,9 +85,9 @@ export function useDerivedMintInfo( ...@@ -85,9 +85,9 @@ export function useDerivedMintInfo(
: pair.priceOf(tokenB).quote(wrappedIndependentAmount) : pair.priceOf(tokenB).quote(wrappedIndependentAmount)
return dependentCurrency === ETHER ? CurrencyAmount.ether(dependentTokenAmount.raw) : dependentTokenAmount return dependentCurrency === ETHER ? CurrencyAmount.ether(dependentTokenAmount.raw) : dependentTokenAmount
} }
return return undefined
} else { } else {
return return undefined
} }
}, [noLiquidity, otherTypedValue, currencies, dependentField, independentAmount, currencyA, chainId, currencyB, pair]) }, [noLiquidity, otherTypedValue, currencies, dependentField, independentAmount, currencyA, chainId, currencyB, pair])
const parsedAmounts: { [field in Field]: CurrencyAmount | undefined } = { const parsedAmounts: { [field in Field]: CurrencyAmount | undefined } = {
...@@ -95,18 +95,18 @@ export function useDerivedMintInfo( ...@@ -95,18 +95,18 @@ export function useDerivedMintInfo(
[Field.CURRENCY_B]: independentField === Field.CURRENCY_A ? dependentAmount : independentAmount [Field.CURRENCY_B]: independentField === Field.CURRENCY_A ? dependentAmount : independentAmount
} }
const token0Price = pair?.token0Price
const price = useMemo(() => { const price = useMemo(() => {
if (noLiquidity) { if (noLiquidity) {
const { [Field.CURRENCY_A]: currencyAAmount, [Field.CURRENCY_B]: currencyBAmount } = parsedAmounts const { [Field.CURRENCY_A]: currencyAAmount, [Field.CURRENCY_B]: currencyBAmount } = parsedAmounts
if (currencyAAmount && currencyBAmount) { if (currencyAAmount && currencyBAmount) {
return new Price(currencyAAmount.currency, currencyBAmount.currency, currencyAAmount.raw, currencyBAmount.raw) return new Price(currencyAAmount.currency, currencyBAmount.currency, currencyAAmount.raw, currencyBAmount.raw)
} }
return return undefined
} else { } else {
return token0Price const wrappedCurrencyA = wrappedCurrency(currencyA, chainId)
return pair && wrappedCurrencyA ? pair.priceOf(wrappedCurrencyA) : undefined
} }
}, [noLiquidity, token0Price, parsedAmounts]) }, [chainId, currencyA, noLiquidity, pair, parsedAmounts])
// liquidity minted // liquidity minted
const liquidityMinted = useMemo(() => { const liquidityMinted = useMemo(() => {
...@@ -118,7 +118,7 @@ export function useDerivedMintInfo( ...@@ -118,7 +118,7 @@ export function useDerivedMintInfo(
if (pair && totalSupply && tokenAmountA && tokenAmountB) { if (pair && totalSupply && tokenAmountA && tokenAmountB) {
return pair.getLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB) return pair.getLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB)
} else { } else {
return return undefined
} }
}, [parsedAmounts, chainId, pair, totalSupply]) }, [parsedAmounts, chainId, pair, totalSupply])
...@@ -126,7 +126,7 @@ export function useDerivedMintInfo( ...@@ -126,7 +126,7 @@ export function useDerivedMintInfo(
if (liquidityMinted && totalSupply) { if (liquidityMinted && totalSupply) {
return new Percent(liquidityMinted.raw, totalSupply.add(liquidityMinted).raw) return new Percent(liquidityMinted.raw, totalSupply.add(liquidityMinted).raw)
} else { } else {
return return undefined
} }
}, [liquidityMinted, totalSupply]) }, [liquidityMinted, totalSupply])
......
...@@ -30,7 +30,8 @@ function isMethodArg(x: unknown): x is MethodArg { ...@@ -30,7 +30,8 @@ function isMethodArg(x: unknown): x is MethodArg {
function isValidMethodArgs(x: unknown): x is MethodArgs | undefined { function isValidMethodArgs(x: unknown): x is MethodArgs | undefined {
return ( return (
x === undefined || (Array.isArray(x) && x.every(y => isMethodArg(y) || (Array.isArray(y) && y.every(isMethodArg)))) x === undefined ||
(Array.isArray(x) && x.every(xi => isMethodArg(xi) || (Array.isArray(xi) && xi.every(isMethodArg))))
) )
} }
...@@ -67,7 +68,7 @@ function useCallsData(calls: (Call | undefined)[], options?: ListenerOptions): C ...@@ -67,7 +68,7 @@ function useCallsData(calls: (Call | undefined)[], options?: ListenerOptions): C
// update listeners when there is an actual change that persists for at least 100ms // update listeners when there is an actual change that persists for at least 100ms
useEffect(() => { useEffect(() => {
const callKeys: string[] = JSON.parse(serializedCallKeys) const callKeys: string[] = JSON.parse(serializedCallKeys)
if (!chainId || callKeys.length === 0) return if (!chainId || callKeys.length === 0) return undefined
const calls = callKeys.map(key => parseCallKey(key)) const calls = callKeys.map(key => parseCallKey(key))
dispatch( dispatch(
addMulticallListeners({ addMulticallListeners({
......
...@@ -71,7 +71,7 @@ export function useSwapActionHandlers(): { ...@@ -71,7 +71,7 @@ export function useSwapActionHandlers(): {
// try to parse a user entered amount for a given token // try to parse a user entered amount for a given token
export function tryParseAmount(value?: string, currency?: Currency): CurrencyAmount | undefined { export function tryParseAmount(value?: string, currency?: Currency): CurrencyAmount | undefined {
if (!value || !currency) { if (!value || !currency) {
return return undefined
} }
try { try {
const typedValueParsed = parseUnits(value, currency.decimals).toString() const typedValueParsed = parseUnits(value, currency.decimals).toString()
...@@ -85,7 +85,7 @@ export function tryParseAmount(value?: string, currency?: Currency): CurrencyAmo ...@@ -85,7 +85,7 @@ export function tryParseAmount(value?: string, currency?: Currency): CurrencyAmo
console.debug(`Failed to parse input amount: "${value}"`, error) console.debug(`Failed to parse input amount: "${value}"`, error)
} }
// necessary for all paths to return a value // necessary for all paths to return a value
return return undefined
} }
const BAD_RECIPIENT_ADDRESSES: string[] = [ const BAD_RECIPIENT_ADDRESSES: string[] = [
......
...@@ -90,7 +90,7 @@ export function useTokenBalances( ...@@ -90,7 +90,7 @@ export function useTokenBalances(
// get the balance for a single token/account combo // get the balance for a single token/account combo
export function useTokenBalance(account?: string, token?: Token): TokenAmount | undefined { export function useTokenBalance(account?: string, token?: Token): TokenAmount | undefined {
const tokenBalances = useTokenBalances(account, [token]) const tokenBalances = useTokenBalances(account, [token])
if (!token) return if (!token) return undefined
return tokenBalances[token.address] return tokenBalances[token.address]
} }
...@@ -109,10 +109,10 @@ export function useCurrencyBalances( ...@@ -109,10 +109,10 @@ export function useCurrencyBalances(
return useMemo( return useMemo(
() => () =>
currencies?.map(currency => { currencies?.map(currency => {
if (!account || !currency) return if (!account || !currency) return undefined
if (currency instanceof Token) return tokenBalances[currency.address] if (currency instanceof Token) return tokenBalances[currency.address]
if (currency === ETHER) return ethBalance[account] if (currency === ETHER) return ethBalance[account]
return return undefined
}) ?? [], }) ?? [],
[account, currencies, ethBalance, tokenBalances] [account, currencies, ethBalance, tokenBalances]
) )
......
...@@ -6,7 +6,7 @@ import { MIN_ETH } from '../constants' ...@@ -6,7 +6,7 @@ import { MIN_ETH } from '../constants'
* @param currencyAmount to return max of * @param currencyAmount to return max of
*/ */
export function maxAmountSpend(currencyAmount?: CurrencyAmount): CurrencyAmount | undefined { export function maxAmountSpend(currencyAmount?: CurrencyAmount): CurrencyAmount | undefined {
if (!currencyAmount) return if (!currencyAmount) return undefined
if (currencyAmount.currency === ETHER) { if (currencyAmount.currency === ETHER) {
if (JSBI.greaterThan(currencyAmount.raw, MIN_ETH)) { if (JSBI.greaterThan(currencyAmount.raw, MIN_ETH)) {
return CurrencyAmount.ether(JSBI.subtract(currencyAmount.raw, MIN_ETH)) return CurrencyAmount.ether(JSBI.subtract(currencyAmount.raw, MIN_ETH))
......
...@@ -2,6 +2,6 @@ const ENS_NAME_REGEX = /^(([a-zA-Z0-9]+\.)+)eth(\/.*)?$/ ...@@ -2,6 +2,6 @@ const ENS_NAME_REGEX = /^(([a-zA-Z0-9]+\.)+)eth(\/.*)?$/
export function parseENSAddress(ensAddress: string): { ensName: string; ensPath: string | undefined } | undefined { export function parseENSAddress(ensAddress: string): { ensName: string; ensPath: string | undefined } | undefined {
const match = ensAddress.match(ENS_NAME_REGEX) const match = ensAddress.match(ENS_NAME_REGEX)
if (!match) return if (!match) return undefined
return { ensName: `${match[1].toLowerCase()}eth`, ensPath: match[3] } return { ensName: `${match[1].toLowerCase()}eth`, ensPath: match[3] }
} }
...@@ -27,7 +27,7 @@ export default function useUSDCPrice(currency?: Currency): Price | undefined { ...@@ -27,7 +27,7 @@ export default function useUSDCPrice(currency?: Currency): Price | undefined {
return useMemo(() => { return useMemo(() => {
if (!currency || !wrapped || !chainId) { if (!currency || !wrapped || !chainId) {
return return undefined
} }
// handle weth/eth // handle weth/eth
if (wrapped.equals(WETH[chainId])) { if (wrapped.equals(WETH[chainId])) {
...@@ -61,6 +61,6 @@ export default function useUSDCPrice(currency?: Currency): Price | undefined { ...@@ -61,6 +61,6 @@ export default function useUSDCPrice(currency?: Currency): Price | undefined {
return new Price(currency, USDC, usdcPrice.denominator, usdcPrice.numerator) return new Price(currency, USDC, usdcPrice.denominator, usdcPrice.numerator)
} }
} }
return return undefined
}, [chainId, currency, ethPair, ethPairState, usdcEthPair, usdcEthPairState, usdcPair, usdcPairState, wrapped]) }, [chainId, currency, ethPair, ethPairState, usdcEthPair, usdcEthPairState, usdcPair, usdcPairState, wrapped])
} }
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
"noEmit": true, "noEmit": true,
"esModuleInterop": true, "esModuleInterop": true,
"module": "esnext", "module": "esnext",
"noUnusedLocals": true,
"noFallthroughCasesInSwitch": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"moduleResolution": "node", "moduleResolution": "node",
"resolveJsonModule": true, "resolveJsonModule": true,
"isolatedModules": true, "isolatedModules": true,
...@@ -29,8 +33,7 @@ ...@@ -29,8 +33,7 @@
"cypress" "cypress"
], ],
"include": [ "include": [
"**/*.js", "./src/**/*.ts",
"**/*.ts", "./src/**/*.tsx"
"**/*.tsx"
] ]
} }
...@@ -4,10 +4,6 @@ ...@@ -4,10 +4,6 @@
"strict": true, "strict": true,
"noImplicitAny": true, "noImplicitAny": true,
"alwaysStrict": true, "alwaysStrict": true,
"strictNullChecks": true, "strictNullChecks": true
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noFallthroughCasesInSwitch": true
} }
} }
\ No newline at end of file
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