Commit be156042 authored by Justin Domingue's avatar Justin Domingue Committed by GitHub

fix: replace `t` with `<Trans>` where possible (#2516)

* replace t macro with <Trans>

* replace t macro with <Trans>

* add lint rule for t

* fixed more ts
parent 077570ef
...@@ -48,6 +48,11 @@ ...@@ -48,6 +48,11 @@
{ {
"name": "styled-components", "name": "styled-components",
"message": "Please import from styled-components/macro." "message": "Please import from styled-components/macro."
},
{
"name": "@lingui/macro",
"importNames": ["t"],
"message": "Please use <Trans> instead of t"
} }
], ],
"patterns": [ "patterns": [
......
// eslint-disable-next-line no-restricted-imports
import { t, Trans } from '@lingui/macro' import { t, Trans } from '@lingui/macro'
import { ReactNode, useCallback, useContext } from 'react' import { ReactNode, useCallback, useContext } from 'react'
import styled, { ThemeContext } from 'styled-components/macro' import styled, { ThemeContext } from 'styled-components/macro'
......
// eslint-disable-next-line no-restricted-imports
import { t } from '@lingui/macro' import { t } from '@lingui/macro'
import { Trans } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { CHAIN_INFO, L2_CHAIN_IDS, SupportedChainId } from 'constants/chains' import { CHAIN_INFO, L2_CHAIN_IDS, SupportedChainId } from 'constants/chains'
......
// eslint-disable-next-line no-restricted-imports
import { t, Trans } from '@lingui/macro' import { t, Trans } from '@lingui/macro'
import { Currency, Token } from '@uniswap/sdk-core' import { Currency, Token } from '@uniswap/sdk-core'
import useDebounce from 'hooks/useDebounce' import useDebounce from 'hooks/useDebounce'
......
// eslint-disable-next-line no-restricted-imports
import { t, Trans } from '@lingui/macro' import { t, Trans } from '@lingui/macro'
import { TokenList } from '@uniswap/token-lists' import { TokenList } from '@uniswap/token-lists'
import Card from 'components/Card' import Card from 'components/Card'
......
// eslint-disable-next-line no-restricted-imports
import { t, Trans } from '@lingui/macro' import { t, Trans } from '@lingui/macro'
import { Percent } from '@uniswap/sdk-core' import { Percent } from '@uniswap/sdk-core'
import { SupportedChainId } from 'constants/chains' import { SupportedChainId } from 'constants/chains'
......
import { t, Trans } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { Percent } from '@uniswap/sdk-core' import { Percent } from '@uniswap/sdk-core'
import { L2_CHAIN_IDS } from 'constants/chains' import { L2_CHAIN_IDS } from 'constants/chains'
import { DEFAULT_DEADLINE_FROM_NOW } from 'constants/misc' import { DEFAULT_DEADLINE_FROM_NOW } from 'constants/misc'
...@@ -233,7 +233,7 @@ export default function TransactionSettings({ placeholderSlippage }: Transaction ...@@ -233,7 +233,7 @@ export default function TransactionSettings({ placeholderSlippage }: Transaction
<Trans>Transaction deadline</Trans> <Trans>Transaction deadline</Trans>
</TYPE.black> </TYPE.black>
<QuestionHelper <QuestionHelper
text={t`Your transaction will revert if it is pending for more than this period of time.`} text={<Trans>Your transaction will revert if it is pending for more than this period of time.</Trans>}
/> />
</RowFixed> </RowFixed>
<RowFixed> <RowFixed>
......
// eslint-disable-next-line no-restricted-imports
import { t, Trans } from '@lingui/macro' import { t, Trans } from '@lingui/macro'
import { AbstractConnector } from '@web3-react/abstract-connector' import { AbstractConnector } from '@web3-react/abstract-connector'
import { UnsupportedChainIdError, useWeb3React } from '@web3-react/core' import { UnsupportedChainIdError, useWeb3React } from '@web3-react/core'
......
import { TransactionResponse } from '@ethersproject/providers' import { TransactionResponse } from '@ethersproject/providers'
import { t, Trans } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { useState } from 'react' import { ReactNode, useState } from 'react'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
import { useStakingContract } from '../../hooks/useContract' import { useStakingContract } from '../../hooks/useContract'
...@@ -61,12 +61,12 @@ export default function ClaimRewardModal({ isOpen, onDismiss, stakingInfo }: Sta ...@@ -61,12 +61,12 @@ export default function ClaimRewardModal({ isOpen, onDismiss, stakingInfo }: Sta
} }
} }
let error: string | undefined let error: ReactNode | undefined
if (!account) { if (!account) {
error = t`Connect Wallet` error = <Trans>Connect Wallet</Trans>
} }
if (!stakingInfo?.stakedAmount) { if (!stakingInfo?.stakedAmount) {
error = error ?? t`Enter an amount` error = error ?? <Trans>Enter an amount</Trans>
} }
return ( return (
......
import { TransactionResponse } from '@ethersproject/providers' import { TransactionResponse } from '@ethersproject/providers'
import { t, Trans } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { useState } from 'react' import { ReactNode, useState } from 'react'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
import { useStakingContract } from '../../hooks/useContract' import { useStakingContract } from '../../hooks/useContract'
...@@ -63,12 +63,12 @@ export default function UnstakingModal({ isOpen, onDismiss, stakingInfo }: Staki ...@@ -63,12 +63,12 @@ export default function UnstakingModal({ isOpen, onDismiss, stakingInfo }: Staki
} }
} }
let error: string | undefined let error: ReactNode | undefined
if (!account) { if (!account) {
error = t`Connect a wallet` error = <Trans>Connect a wallet</Trans>
} }
if (!stakingInfo?.stakedAmount) { if (!stakingInfo?.stakedAmount) {
error = error ?? t`Enter an amount` error = error ?? <Trans>Enter an amount</Trans>
} }
return ( return (
......
import { BigNumber } from '@ethersproject/bignumber' import { BigNumber } from '@ethersproject/bignumber'
import { t } from '@lingui/macro' // eslint-disable-next-line no-restricted-imports
import { t, Trans } from '@lingui/macro'
import { Currency, Percent, TradeType } from '@uniswap/sdk-core' import { Currency, Percent, TradeType } from '@uniswap/sdk-core'
import { Router, Trade as V2Trade } from '@uniswap/v2-sdk' import { Router, Trade as V2Trade } from '@uniswap/v2-sdk'
import { SwapRouter, Trade as V3Trade } from '@uniswap/v3-sdk' import { SwapRouter, Trade as V3Trade } from '@uniswap/v3-sdk'
import { useMemo } from 'react' import { ReactNode, useMemo } from 'react'
import { SWAP_ROUTER_ADDRESSES } from '../constants/addresses' import { SWAP_ROUTER_ADDRESSES } from '../constants/addresses'
import { TransactionType } from '../state/transactions/actions' import { TransactionType } from '../state/transactions/actions'
...@@ -191,7 +192,7 @@ function useSwapCallArguments( ...@@ -191,7 +192,7 @@ function useSwapCallArguments(
* This object seems to be undocumented by ethers. * This object seems to be undocumented by ethers.
* @param error an error from the ethers provider * @param error an error from the ethers provider
*/ */
function swapErrorToUserReadableMessage(error: any): string { function swapErrorToUserReadableMessage(error: any): ReactNode {
let reason: string | undefined let reason: string | undefined
while (Boolean(error)) { while (Boolean(error)) {
reason = error.reason ?? error.message ?? reason reason = error.reason ?? error.message ?? reason
...@@ -202,30 +203,64 @@ function swapErrorToUserReadableMessage(error: any): string { ...@@ -202,30 +203,64 @@ function swapErrorToUserReadableMessage(error: any): string {
switch (reason) { switch (reason) {
case 'UniswapV2Router: EXPIRED': case 'UniswapV2Router: EXPIRED':
return t`The transaction could not be sent because the deadline has passed. Please check that your transaction deadline is not too low.` return (
<Trans>
The transaction could not be sent because the deadline has passed. Please check that your transaction deadline
is not too low.
</Trans>
)
case 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT': case 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT':
case 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT': case 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT':
return t`This transaction will not succeed either due to price movement or fee on transfer. Try increasing your slippage tolerance.` return (
<Trans>
This transaction will not succeed either due to price movement or fee on transfer. Try increasing your
slippage tolerance.
</Trans>
)
case 'TransferHelper: TRANSFER_FROM_FAILED': case 'TransferHelper: TRANSFER_FROM_FAILED':
return t`The input token cannot be transferred. There may be an issue with the input token.` return <Trans>The input token cannot be transferred. There may be an issue with the input token.</Trans>
case 'UniswapV2: TRANSFER_FAILED': case 'UniswapV2: TRANSFER_FAILED':
return t`The output token cannot be transferred. There may be an issue with the output token.` return <Trans>The output token cannot be transferred. There may be an issue with the output token.</Trans>
case 'UniswapV2: K': case 'UniswapV2: K':
return t`The Uniswap invariant x*y=k was not satisfied by the swap. This usually means one of the tokens you are swapping incorporates custom behavior on transfer.` return (
<Trans>
The Uniswap invariant x*y=k was not satisfied by the swap. This usually means one of the tokens you are
swapping incorporates custom behavior on transfer.
</Trans>
)
case 'Too little received': case 'Too little received':
case 'Too much requested': case 'Too much requested':
case 'STF': case 'STF':
return t`This transaction will not succeed due to price movement. Try increasing your slippage tolerance. Note: fee on transfer and rebase tokens are incompatible with Uniswap V3.` return (
<Trans>
This transaction will not succeed due to price movement. Try increasing your slippage tolerance. Note: fee on
transfer and rebase tokens are incompatible with Uniswap V3.
</Trans>
)
case 'TF': case 'TF':
return t`The output token cannot be transferred. There may be an issue with the output token. Note: fee on transfer and rebase tokens are incompatible with Uniswap V3.` return (
<Trans>
The output token cannot be transferred. There may be an issue with the output token. Note: fee on transfer and
rebase tokens are incompatible with Uniswap V3.
</Trans>
)
default: default:
if (reason?.indexOf('undefined is not an object') !== -1) { if (reason?.indexOf('undefined is not an object') !== -1) {
console.error(error, reason) console.error(error, reason)
return t`An error occurred when trying to execute this swap. You may need to increase your slippage tolerance. If that does not work, there may be an incompatibility with the token you are trading. Note: fee on transfer and rebase tokens are incompatible with Uniswap V3.` return (
<Trans>
An error occurred when trying to execute this swap. You may need to increase your slippage tolerance. If
that does not work, there may be an incompatibility with the token you are trading. Note: fee on transfer
and rebase tokens are incompatible with Uniswap V3.
</Trans>
)
} }
return t`Unknown error${ return (
reason ? `: "${reason}"` : '' <Trans>
}. Try increasing your slippage tolerance. Note: fee on transfer and rebase tokens are incompatible with Uniswap V3.` Unknown error${reason ? `: "${reason}"` : ''}. Try increasing your slippage tolerance. Note: fee on transfer
and rebase tokens are incompatible with Uniswap V3.
</Trans>
)
} }
} }
...@@ -236,7 +271,7 @@ export function useSwapCallback( ...@@ -236,7 +271,7 @@ export function useSwapCallback(
allowedSlippage: Percent, // in bips allowedSlippage: Percent, // in bips
recipientAddressOrName: string | null, // the ENS name or address of the recipient of the trade, or null if swap should be returned to sender recipientAddressOrName: string | null, // the ENS name or address of the recipient of the trade, or null if swap should be returned to sender
signatureData: SignatureData | undefined | null signatureData: SignatureData | undefined | null
): { state: SwapCallbackState; callback: null | (() => Promise<string>); error: string | null } { ): { state: SwapCallbackState; callback: null | (() => Promise<string>); error: ReactNode | null } {
const { account, chainId, library } = useActiveWeb3React() const { account, chainId, library } = useActiveWeb3React()
const swapCalls = useSwapCallArguments(trade, allowedSlippage, recipientAddressOrName, signatureData) const swapCalls = useSwapCallArguments(trade, allowedSlippage, recipientAddressOrName, signatureData)
...@@ -248,11 +283,11 @@ export function useSwapCallback( ...@@ -248,11 +283,11 @@ export function useSwapCallback(
return useMemo(() => { return useMemo(() => {
if (!trade || !library || !account || !chainId) { if (!trade || !library || !account || !chainId) {
return { state: SwapCallbackState.INVALID, callback: null, error: 'Missing dependencies' } return { state: SwapCallbackState.INVALID, callback: null, error: <Trans>Missing dependencies</Trans> }
} }
if (!recipient) { if (!recipient) {
if (recipientAddressOrName !== null) { if (recipientAddressOrName !== null) {
return { state: SwapCallbackState.INVALID, callback: null, error: 'Invalid recipient' } return { state: SwapCallbackState.INVALID, callback: null, error: <Trans>Invalid recipient</Trans> }
} else { } else {
return { state: SwapCallbackState.LOADING, callback: null, error: null } return { state: SwapCallbackState.LOADING, callback: null, error: null }
} }
...@@ -290,11 +325,11 @@ export function useSwapCallback( ...@@ -290,11 +325,11 @@ export function useSwapCallback(
.call(tx) .call(tx)
.then((result) => { .then((result) => {
console.debug('Unexpected successful call after failed estimate gas', call, gasError, result) console.debug('Unexpected successful call after failed estimate gas', call, gasError, result)
return { call, error: new Error('Unexpected issue with estimating the gas. Please try again.') } return { call, error: <Trans>Unexpected issue with estimating the gas. Please try again.</Trans> }
}) })
.catch((callError) => { .catch((callError) => {
console.debug('Call threw error', call, callError) console.debug('Call threw error', call, callError)
return { call, error: new Error(swapErrorToUserReadableMessage(callError)) } return { call, error: swapErrorToUserReadableMessage(callError) }
}) })
}) })
}) })
...@@ -313,7 +348,7 @@ export function useSwapCallback( ...@@ -313,7 +348,7 @@ export function useSwapCallback(
const firstNoErrorCall = estimatedCalls.find<SwapCallEstimate>( const firstNoErrorCall = estimatedCalls.find<SwapCallEstimate>(
(call): call is SwapCallEstimate => !('error' in call) (call): call is SwapCallEstimate => !('error' in call)
) )
if (!firstNoErrorCall) throw new Error('Unexpected error. Could not estimate gas for the swap.') if (!firstNoErrorCall) throw new Error(t`Unexpected error. Could not estimate gas for the swap.`)
bestCallOption = firstNoErrorCall bestCallOption = firstNoErrorCall
} }
...@@ -362,12 +397,12 @@ export function useSwapCallback( ...@@ -362,12 +397,12 @@ export function useSwapCallback(
.catch((error) => { .catch((error) => {
// if the user rejected the tx, pass this along // if the user rejected the tx, pass this along
if (error?.code === 4001) { if (error?.code === 4001) {
throw new Error('Transaction rejected.') throw new Error(t`Transaction rejected.`)
} else { } else {
// otherwise, the error was unexpected and we need to convey that // otherwise, the error was unexpected and we need to convey that
console.error(`Swap failed`, error, address, calldata, value) console.error(`Swap failed`, error, address, calldata, value)
throw new Error(`Swap failed: ${swapErrorToUserReadableMessage(error)}`) throw new Error(t`Swap failed: ${swapErrorToUserReadableMessage(error)}`)
} }
}) })
}, },
......
import { BigNumber } from '@ethersproject/bignumber' import { BigNumber } from '@ethersproject/bignumber'
import { TransactionResponse } from '@ethersproject/providers' import { TransactionResponse } from '@ethersproject/providers'
import { t, Trans } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { Currency, CurrencyAmount, Percent } from '@uniswap/sdk-core' import { Currency, CurrencyAmount, Percent } from '@uniswap/sdk-core'
import { FeeAmount, NonfungiblePositionManager } from '@uniswap/v3-sdk' import { FeeAmount, NonfungiblePositionManager } from '@uniswap/v3-sdk'
import DowntimeWarning from 'components/DowntimeWarning' import DowntimeWarning from 'components/DowntimeWarning'
...@@ -560,7 +560,7 @@ export default function AddLiquidity({ ...@@ -560,7 +560,7 @@ export default function AddLiquidity({
hash={txHash} hash={txHash}
content={() => ( content={() => (
<ConfirmationModalContent <ConfirmationModalContent
title={t`Add Liquidity`} title={<Trans>Add Liquidity</Trans>}
onDismiss={handleDismissConfirmation} onDismiss={handleDismissConfirmation}
topContent={() => ( topContent={() => (
<Review <Review
......
import { BigNumber } from '@ethersproject/bignumber' import { BigNumber } from '@ethersproject/bignumber'
import { TransactionResponse } from '@ethersproject/providers' import { TransactionResponse } from '@ethersproject/providers'
import { t, Trans } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { Currency, CurrencyAmount, Percent } from '@uniswap/sdk-core' import { Currency, CurrencyAmount, Percent } from '@uniswap/sdk-core'
import UnsupportedCurrencyFooter from 'components/swap/UnsupportedCurrencyFooter' import UnsupportedCurrencyFooter from 'components/swap/UnsupportedCurrencyFooter'
import { SwitchLocaleLink } from 'components/SwitchLocaleLink' import { SwitchLocaleLink } from 'components/SwitchLocaleLink'
...@@ -270,9 +270,12 @@ export default function AddLiquidity({ ...@@ -270,9 +270,12 @@ export default function AddLiquidity({
) )
} }
const pendingText = t`Supplying ${parsedAmounts[Field.CURRENCY_A]?.toSignificant(6)} ${ const pendingText = (
currencies[Field.CURRENCY_A]?.symbol <Trans>
} and ${parsedAmounts[Field.CURRENCY_B]?.toSignificant(6)} ${currencies[Field.CURRENCY_B]?.symbol}` Supplying ${parsedAmounts[Field.CURRENCY_A]?.toSignificant(6)} ${currencies[Field.CURRENCY_A]?.symbol} and $
{parsedAmounts[Field.CURRENCY_B]?.toSignificant(6)} ${currencies[Field.CURRENCY_B]?.symbol}
</Trans>
)
const handleCurrencyASelect = useCallback( const handleCurrencyASelect = useCallback(
(currencyA: Currency) => { (currencyA: Currency) => {
......
// eslint-disable-next-line no-restricted-imports
import { t, Trans } from '@lingui/macro' import { t, Trans } from '@lingui/macro'
import { ResizingTextArea, TextInput } from 'components/TextInput' import { ResizingTextArea, TextInput } from 'components/TextInput'
import React, { memo } from 'react' import React, { memo } from 'react'
......
import { BigNumber } from '@ethersproject/bignumber' import { BigNumber } from '@ethersproject/bignumber'
import { Contract } from '@ethersproject/contracts' import { Contract } from '@ethersproject/contracts'
import { TransactionResponse } from '@ethersproject/providers' import { TransactionResponse } from '@ethersproject/providers'
import { t, Trans } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { Currency, Percent } from '@uniswap/sdk-core' import { Currency, Percent } from '@uniswap/sdk-core'
import { useCallback, useContext, useMemo, useState } from 'react' import { useCallback, useContext, useMemo, useState } from 'react'
import { ArrowDown, Plus } from 'react-feather' import { ArrowDown, Plus } from 'react-feather'
...@@ -371,9 +371,12 @@ export default function RemoveLiquidity({ ...@@ -371,9 +371,12 @@ export default function RemoveLiquidity({
) )
} }
const pendingText = t`Removing ${parsedAmounts[Field.CURRENCY_A]?.toSignificant(6)} ${ const pendingText = (
currencyA?.symbol <Trans>
} and ${parsedAmounts[Field.CURRENCY_B]?.toSignificant(6)} ${currencyB?.symbol}` Removing ${parsedAmounts[Field.CURRENCY_A]?.toSignificant(6)} ${currencyA?.symbol} and $
{parsedAmounts[Field.CURRENCY_B]?.toSignificant(6)} ${currencyB?.symbol}
</Trans>
)
const liquidityPercentChangeCallback = useCallback( const liquidityPercentChangeCallback = useCallback(
(value: number) => { (value: number) => {
......
import { BigNumber } from '@ethersproject/bignumber' import { BigNumber } from '@ethersproject/bignumber'
// eslint-disable-next-line no-restricted-imports
import { t, Trans } from '@lingui/macro' import { t, Trans } from '@lingui/macro'
import { CurrencyAmount, Token } from '@uniswap/sdk-core' import { CurrencyAmount, Token } from '@uniswap/sdk-core'
import useCurrentBlockTimestamp from 'hooks/useCurrentBlockTimestamp' import useCurrentBlockTimestamp from 'hooks/useCurrentBlockTimestamp'
......
import { t } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { Currency, CurrencyAmount, Percent, Token } from '@uniswap/sdk-core' import { Currency, CurrencyAmount, Percent, Token } from '@uniswap/sdk-core'
import { Pair } from '@uniswap/v2-sdk' import { Pair } from '@uniswap/v2-sdk'
import JSBI from 'jsbi' import JSBI from 'jsbi'
import { useCallback } from 'react' import { ReactNode, useCallback } from 'react'
import { useAppDispatch, useAppSelector } from 'state/hooks' import { useAppDispatch, useAppSelector } from 'state/hooks'
import { useTotalSupply } from '../../hooks/useTotalSupply' import { useTotalSupply } from '../../hooks/useTotalSupply'
...@@ -28,7 +28,7 @@ export function useDerivedBurnInfo( ...@@ -28,7 +28,7 @@ export function useDerivedBurnInfo(
[Field.CURRENCY_A]?: CurrencyAmount<Currency> [Field.CURRENCY_A]?: CurrencyAmount<Currency>
[Field.CURRENCY_B]?: CurrencyAmount<Currency> [Field.CURRENCY_B]?: CurrencyAmount<Currency>
} }
error?: string error?: ReactNode
} { } {
const { account } = useActiveWeb3React() const { account } = useActiveWeb3React()
...@@ -122,13 +122,13 @@ export function useDerivedBurnInfo( ...@@ -122,13 +122,13 @@ export function useDerivedBurnInfo(
: undefined, : undefined,
} }
let error: string | undefined let error: ReactNode | undefined
if (!account) { if (!account) {
error = t`Connect Wallet` error = <Trans>Connect Wallet</Trans>
} }
if (!parsedAmounts[Field.LIQUIDITY] || !parsedAmounts[Field.CURRENCY_A] || !parsedAmounts[Field.CURRENCY_B]) { if (!parsedAmounts[Field.LIQUIDITY] || !parsedAmounts[Field.CURRENCY_A] || !parsedAmounts[Field.CURRENCY_B]) {
error = error ?? t`Enter an amount` error = error ?? <Trans>Enter an amount</Trans>
} }
return { pair, parsedAmounts, error } return { pair, parsedAmounts, error }
......
import { t } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { Currency, CurrencyAmount, Percent } from '@uniswap/sdk-core' import { Currency, CurrencyAmount, Percent } from '@uniswap/sdk-core'
import { Position } from '@uniswap/v3-sdk' import { Position } from '@uniswap/v3-sdk'
import { useToken } from 'hooks/Tokens' import { useToken } from 'hooks/Tokens'
import { usePool } from 'hooks/usePools' import { usePool } from 'hooks/usePools'
import { useV3PositionFees } from 'hooks/useV3PositionFees' import { useV3PositionFees } from 'hooks/useV3PositionFees'
import { useActiveWeb3React } from 'hooks/web3' import { useActiveWeb3React } from 'hooks/web3'
import { useCallback, useMemo } from 'react' import { ReactNode, useCallback, useMemo } from 'react'
import { useAppDispatch, useAppSelector } from 'state/hooks' import { useAppDispatch, useAppSelector } from 'state/hooks'
import { PositionDetails } from 'types/position' import { PositionDetails } from 'types/position'
import { unwrappedToken } from 'utils/unwrappedToken' import { unwrappedToken } from 'utils/unwrappedToken'
...@@ -28,7 +28,7 @@ export function useDerivedV3BurnInfo( ...@@ -28,7 +28,7 @@ export function useDerivedV3BurnInfo(
feeValue0?: CurrencyAmount<Currency> feeValue0?: CurrencyAmount<Currency>
feeValue1?: CurrencyAmount<Currency> feeValue1?: CurrencyAmount<Currency>
outOfRange: boolean outOfRange: boolean
error?: string error?: ReactNode
} { } {
const { account } = useActiveWeb3React() const { account } = useActiveWeb3React()
const { percent } = useBurnV3State() const { percent } = useBurnV3State()
...@@ -74,12 +74,12 @@ export function useDerivedV3BurnInfo( ...@@ -74,12 +74,12 @@ export function useDerivedV3BurnInfo(
const outOfRange = const outOfRange =
pool && position ? pool.tickCurrent < position.tickLower || pool.tickCurrent > position.tickUpper : false pool && position ? pool.tickCurrent < position.tickLower || pool.tickCurrent > position.tickUpper : false
let error: string | undefined let error: ReactNode | undefined
if (!account) { if (!account) {
error = t`Connect Wallet` error = <Trans>Connect Wallet</Trans>
} }
if (percent === 0) { if (percent === 0) {
error = error ?? t`Enter a percent` error = error ?? <Trans>Enter a percent</Trans>
} }
return { return {
position: positionSDK, position: positionSDK,
......
...@@ -4,6 +4,7 @@ import { Contract } from '@ethersproject/contracts' ...@@ -4,6 +4,7 @@ import { Contract } from '@ethersproject/contracts'
import { TransactionResponse } from '@ethersproject/providers' import { TransactionResponse } from '@ethersproject/providers'
import { toUtf8String, Utf8ErrorFuncs, Utf8ErrorReason } from '@ethersproject/strings' import { toUtf8String, Utf8ErrorFuncs, Utf8ErrorReason } from '@ethersproject/strings'
import { formatUnits } from '@ethersproject/units' import { formatUnits } from '@ethersproject/units'
// eslint-disable-next-line no-restricted-imports
import { t } from '@lingui/macro' import { t } from '@lingui/macro'
import { abi as GOV_ABI } from '@uniswap/governance/build/GovernorAlpha.json' import { abi as GOV_ABI } from '@uniswap/governance/build/GovernorAlpha.json'
import { CurrencyAmount, Token } from '@uniswap/sdk-core' import { CurrencyAmount, Token } from '@uniswap/sdk-core'
......
import { t } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { Currency, CurrencyAmount, Percent, Price, Token } from '@uniswap/sdk-core' import { Currency, CurrencyAmount, Percent, Price, Token } from '@uniswap/sdk-core'
import { Pair } from '@uniswap/v2-sdk' import { Pair } from '@uniswap/v2-sdk'
import JSBI from 'jsbi' import JSBI from 'jsbi'
import { useCallback, useMemo } from 'react' import { ReactNode, useCallback, useMemo } from 'react'
import { useAppDispatch, useAppSelector } from 'state/hooks' import { useAppDispatch, useAppSelector } from 'state/hooks'
import { useTotalSupply } from '../../hooks/useTotalSupply' import { useTotalSupply } from '../../hooks/useTotalSupply'
...@@ -59,7 +59,7 @@ export function useDerivedMintInfo( ...@@ -59,7 +59,7 @@ export function useDerivedMintInfo(
noLiquidity?: boolean noLiquidity?: boolean
liquidityMinted?: CurrencyAmount<Token> liquidityMinted?: CurrencyAmount<Token>
poolTokenPercentage?: Percent poolTokenPercentage?: Percent
error?: string error?: ReactNode
} { } {
const { account } = useActiveWeb3React() const { account } = useActiveWeb3React()
...@@ -176,27 +176,27 @@ export function useDerivedMintInfo( ...@@ -176,27 +176,27 @@ export function useDerivedMintInfo(
} }
}, [liquidityMinted, totalSupply]) }, [liquidityMinted, totalSupply])
let error: string | undefined let error: ReactNode | undefined
if (!account) { if (!account) {
error = t`Connect Wallet` error = <Trans>Connect Wallet</Trans>
} }
if (pairState === PairState.INVALID) { if (pairState === PairState.INVALID) {
error = error ?? t`Invalid pair` error = error ?? <Trans>Invalid pair</Trans>
} }
if (!parsedAmounts[Field.CURRENCY_A] || !parsedAmounts[Field.CURRENCY_B]) { if (!parsedAmounts[Field.CURRENCY_A] || !parsedAmounts[Field.CURRENCY_B]) {
error = error ?? t`Enter an amount` error = error ?? <Trans>Enter an amount</Trans>
} }
const { [Field.CURRENCY_A]: currencyAAmount, [Field.CURRENCY_B]: currencyBAmount } = parsedAmounts const { [Field.CURRENCY_A]: currencyAAmount, [Field.CURRENCY_B]: currencyBAmount } = parsedAmounts
if (currencyAAmount && currencyBalances?.[Field.CURRENCY_A]?.lessThan(currencyAAmount)) { if (currencyAAmount && currencyBalances?.[Field.CURRENCY_A]?.lessThan(currencyAAmount)) {
error = t`Insufficient ${currencies[Field.CURRENCY_A]?.symbol} balance` error = <Trans>Insufficient ${currencies[Field.CURRENCY_A]?.symbol} balance</Trans>
} }
if (currencyBAmount && currencyBalances?.[Field.CURRENCY_B]?.lessThan(currencyBAmount)) { if (currencyBAmount && currencyBalances?.[Field.CURRENCY_B]?.lessThan(currencyBAmount)) {
error = t`Insufficient ${currencies[Field.CURRENCY_B]?.symbol} balance` error = <Trans>Insufficient ${currencies[Field.CURRENCY_B]?.symbol} balance</Trans>
} }
return { return {
......
import { t } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { Currency, CurrencyAmount, Price, Rounding, Token } from '@uniswap/sdk-core' import { Currency, CurrencyAmount, Price, Rounding, Token } from '@uniswap/sdk-core'
import { import {
encodeSqrtRatioX96, encodeSqrtRatioX96,
...@@ -13,7 +13,7 @@ import { ...@@ -13,7 +13,7 @@ import {
} from '@uniswap/v3-sdk' } from '@uniswap/v3-sdk'
import { usePool } from 'hooks/usePools' import { usePool } from 'hooks/usePools'
import JSBI from 'jsbi' import JSBI from 'jsbi'
import { useCallback, useMemo } from 'react' import { ReactNode, useCallback, useMemo } from 'react'
import { useAppDispatch, useAppSelector } from 'state/hooks' import { useAppDispatch, useAppSelector } from 'state/hooks'
import { getTickToPrice } from 'utils/getTickToPrice' import { getTickToPrice } from 'utils/getTickToPrice'
...@@ -112,7 +112,7 @@ export function useV3DerivedMintInfo( ...@@ -112,7 +112,7 @@ export function useV3DerivedMintInfo(
parsedAmounts: { [field in Field]?: CurrencyAmount<Currency> } parsedAmounts: { [field in Field]?: CurrencyAmount<Currency> }
position: Position | undefined position: Position | undefined
noLiquidity?: boolean noLiquidity?: boolean
errorMessage?: string errorMessage?: ReactNode
invalidPool: boolean invalidPool: boolean
outOfRange: boolean outOfRange: boolean
invalidRange: boolean invalidRange: boolean
...@@ -218,7 +218,7 @@ export function useV3DerivedMintInfo( ...@@ -218,7 +218,7 @@ export function useV3DerivedMintInfo(
// if pool exists use it, if not use the mock pool // if pool exists use it, if not use the mock pool
const poolForPosition: Pool | undefined = pool ?? mockPool const poolForPosition: Pool | undefined = pool ?? mockPool
// lower and upper limits in the tick space for `feeAmount` // lower and upper limits in the tick space for `feeAmoun<Trans>
const tickSpaceLimits: { const tickSpaceLimits: {
[bound in Bound]: number | undefined [bound in Bound]: number | undefined
} = useMemo( } = useMemo(
...@@ -423,34 +423,34 @@ export function useV3DerivedMintInfo( ...@@ -423,34 +423,34 @@ export function useV3DerivedMintInfo(
tickUpper, tickUpper,
]) ])
let errorMessage: string | undefined let errorMessage: ReactNode | undefined
if (!account) { if (!account) {
errorMessage = t`Connect Wallet` errorMessage = <Trans>Connect Wallet</Trans>
} }
if (poolState === PoolState.INVALID) { if (poolState === PoolState.INVALID) {
errorMessage = errorMessage ?? t`Invalid pair` errorMessage = errorMessage ?? <Trans>Invalid pair</Trans>
} }
if (invalidPrice) { if (invalidPrice) {
errorMessage = errorMessage ?? t`Invalid price input` errorMessage = errorMessage ?? <Trans>Invalid price input</Trans>
} }
if ( if (
(!parsedAmounts[Field.CURRENCY_A] && !depositADisabled) || (!parsedAmounts[Field.CURRENCY_A] && !depositADisabled) ||
(!parsedAmounts[Field.CURRENCY_B] && !depositBDisabled) (!parsedAmounts[Field.CURRENCY_B] && !depositBDisabled)
) { ) {
errorMessage = errorMessage ?? t`Enter an amount` errorMessage = errorMessage ?? <Trans>Enter an amount</Trans>
} }
const { [Field.CURRENCY_A]: currencyAAmount, [Field.CURRENCY_B]: currencyBAmount } = parsedAmounts const { [Field.CURRENCY_A]: currencyAAmount, [Field.CURRENCY_B]: currencyBAmount } = parsedAmounts
if (currencyAAmount && currencyBalances?.[Field.CURRENCY_A]?.lessThan(currencyAAmount)) { if (currencyAAmount && currencyBalances?.[Field.CURRENCY_A]?.lessThan(currencyAAmount)) {
errorMessage = t`Insufficient ${currencies[Field.CURRENCY_A]?.symbol} balance` errorMessage = <Trans>Insufficient ${currencies[Field.CURRENCY_A]?.symbol} balance</Trans>
} }
if (currencyBAmount && currencyBalances?.[Field.CURRENCY_B]?.lessThan(currencyBAmount)) { if (currencyBAmount && currencyBalances?.[Field.CURRENCY_B]?.lessThan(currencyBAmount)) {
errorMessage = t`Insufficient ${currencies[Field.CURRENCY_B]?.symbol} balance` errorMessage = <Trans>Insufficient ${currencies[Field.CURRENCY_B]?.symbol} balance</Trans>
} }
const invalidPool = poolState === PoolState.INVALID const invalidPool = poolState === PoolState.INVALID
......
import { Interface } from '@ethersproject/abi' import { Interface } from '@ethersproject/abi'
import { t } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { abi as STAKING_REWARDS_ABI } from '@uniswap/liquidity-staker/build/StakingRewards.json' import { abi as STAKING_REWARDS_ABI } from '@uniswap/liquidity-staker/build/StakingRewards.json'
import { CurrencyAmount, Token } from '@uniswap/sdk-core' import { CurrencyAmount, Token } from '@uniswap/sdk-core'
import { Pair } from '@uniswap/v2-sdk' import { Pair } from '@uniswap/v2-sdk'
import useCurrentBlockTimestamp from 'hooks/useCurrentBlockTimestamp' import useCurrentBlockTimestamp from 'hooks/useCurrentBlockTimestamp'
import JSBI from 'jsbi' import JSBI from 'jsbi'
import { useMemo } from 'react' import { ReactNode, useMemo } from 'react'
import { DAI, UNI, USDC, USDT, WBTC, WETH9_EXTENDED } from '../../constants/tokens' import { DAI, UNI, USDC, USDT, WBTC, WETH9_EXTENDED } from '../../constants/tokens'
import { useActiveWeb3React } from '../../hooks/web3' import { useActiveWeb3React } from '../../hooks/web3'
...@@ -250,7 +250,7 @@ export function useDerivedStakeInfo( ...@@ -250,7 +250,7 @@ export function useDerivedStakeInfo(
userLiquidityUnstaked: CurrencyAmount<Token> | undefined userLiquidityUnstaked: CurrencyAmount<Token> | undefined
): { ): {
parsedAmount?: CurrencyAmount<Token> parsedAmount?: CurrencyAmount<Token>
error?: string error?: ReactNode
} { } {
const { account } = useActiveWeb3React() const { account } = useActiveWeb3React()
...@@ -261,12 +261,12 @@ export function useDerivedStakeInfo( ...@@ -261,12 +261,12 @@ export function useDerivedStakeInfo(
? parsedInput ? parsedInput
: undefined : undefined
let error: string | undefined let error: ReactNode | undefined
if (!account) { if (!account) {
error = t`Connect Wallet` error = <Trans>Connect Wallet</Trans>
} }
if (!parsedAmount) { if (!parsedAmount) {
error = error ?? t`Enter an amount` error = error ?? <Trans>Enter an amount</Trans>
} }
return { return {
......
import { parseUnits } from '@ethersproject/units' import { parseUnits } from '@ethersproject/units'
import { t } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { Currency, CurrencyAmount, Percent, TradeType } from '@uniswap/sdk-core' import { Currency, CurrencyAmount, Percent, TradeType } from '@uniswap/sdk-core'
import { Trade as V2Trade } from '@uniswap/v2-sdk' import { Trade as V2Trade } from '@uniswap/v2-sdk'
import { Trade as V3Trade } from '@uniswap/v3-sdk' import { Trade as V3Trade } from '@uniswap/v3-sdk'
...@@ -8,7 +8,7 @@ import { useBestV2Trade } from 'hooks/useBestV2Trade' ...@@ -8,7 +8,7 @@ import { useBestV2Trade } from 'hooks/useBestV2Trade'
import { useBestV3Trade } from 'hooks/useBestV3Trade' import { useBestV3Trade } from 'hooks/useBestV3Trade'
import JSBI from 'jsbi' import JSBI from 'jsbi'
import { ParsedQs } from 'qs' import { ParsedQs } from 'qs'
import { useCallback, useEffect, useMemo, useState } from 'react' import { ReactNode, useCallback, useEffect, useMemo, useState } from 'react'
import { useAppDispatch, useAppSelector } from 'state/hooks' import { useAppDispatch, useAppSelector } from 'state/hooks'
import { V3TradeState } from 'state/routing/types' import { V3TradeState } from 'state/routing/types'
import { isTradeBetter } from 'utils/isTradeBetter' import { isTradeBetter } from 'utils/isTradeBetter'
...@@ -121,7 +121,7 @@ export function useDerivedSwapInfo(toggledVersion: Version | undefined): { ...@@ -121,7 +121,7 @@ export function useDerivedSwapInfo(toggledVersion: Version | undefined): {
currencies: { [field in Field]?: Currency | null } currencies: { [field in Field]?: Currency | null }
currencyBalances: { [field in Field]?: CurrencyAmount<Currency> } currencyBalances: { [field in Field]?: CurrencyAmount<Currency> }
parsedAmount: CurrencyAmount<Currency> | undefined parsedAmount: CurrencyAmount<Currency> | undefined
inputError?: string inputError?: ReactNode
v2Trade: V2Trade<Currency, Currency, TradeType> | undefined v2Trade: V2Trade<Currency, Currency, TradeType> | undefined
v3Trade: { v3Trade: {
trade: V3Trade<Currency, Currency, TradeType> | null trade: V3Trade<Currency, Currency, TradeType> | null
...@@ -195,25 +195,25 @@ export function useDerivedSwapInfo(toggledVersion: Version | undefined): { ...@@ -195,25 +195,25 @@ export function useDerivedSwapInfo(toggledVersion: Version | undefined): {
[Field.OUTPUT]: outputCurrency, [Field.OUTPUT]: outputCurrency,
} }
let inputError: string | undefined let inputError: ReactNode | undefined
if (!account) { if (!account) {
inputError = t`Connect Wallet` inputError = <Trans>Connect Wallet</Trans>
} }
if (!parsedAmount) { if (!parsedAmount) {
inputError = inputError ?? t`Enter an amount` inputError = inputError ?? <Trans>Enter an amount</Trans>
} }
if (!currencies[Field.INPUT] || !currencies[Field.OUTPUT]) { if (!currencies[Field.INPUT] || !currencies[Field.OUTPUT]) {
inputError = inputError ?? t`Select a token` inputError = inputError ?? <Trans>Select a token</Trans>
} }
const formattedTo = isAddress(to) const formattedTo = isAddress(to)
if (!to || !formattedTo) { if (!to || !formattedTo) {
inputError = inputError ?? t`Enter a recipient` inputError = inputError ?? <Trans>Enter a recipient</Trans>
} else { } else {
if (BAD_RECIPIENT_ADDRESSES[formattedTo] || (v2Trade && involvesAddress(v2Trade, formattedTo))) { if (BAD_RECIPIENT_ADDRESSES[formattedTo] || (v2Trade && involvesAddress(v2Trade, formattedTo))) {
inputError = inputError ?? t`Invalid recipient` inputError = inputError ?? <Trans>Invalid recipient</Trans>
} }
} }
...@@ -223,7 +223,7 @@ export function useDerivedSwapInfo(toggledVersion: Version | undefined): { ...@@ -223,7 +223,7 @@ export function useDerivedSwapInfo(toggledVersion: Version | undefined): {
const [balanceIn, amountIn] = [currencyBalances[Field.INPUT], bestTrade?.maximumAmountIn(allowedSlippage)] const [balanceIn, amountIn] = [currencyBalances[Field.INPUT], bestTrade?.maximumAmountIn(allowedSlippage)]
if (balanceIn && amountIn && balanceIn.lessThan(amountIn)) { if (balanceIn && amountIn && balanceIn.lessThan(amountIn)) {
inputError = t`Insufficient ${amountIn.currency.symbol} balance` inputError = <Trans>Insufficient ${amountIn.currency.symbol} balance</Trans>
} }
return { return {
......
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