Commit 91157b7a authored by Vignesh Mohankumar's avatar Vignesh Mohankumar Committed by GitHub

chore: remove unused hooks, utils, components (#5524)

parent d5e676ef
import { Trans } from '@lingui/macro'
import { Currency, CurrencyAmount, Token, TradeType } from '@uniswap/sdk-core'
import { RowBetween } from 'components/Row'
import { MouseoverTooltipContent } from 'components/Tooltip'
import { Info } from 'react-feather'
import { InterfaceTrade } from 'state/routing/types'
import styled from 'styled-components/macro'
import { ThemedText } from 'theme'
import { ResponsiveTooltipContainer } from './styleds'
const Wrapper = styled.div`
background-color: ${({ theme }) => theme.deprecated_bg1};
border-bottom-left-radius: 20px;
border-bottom-right-radius: 20px;
padding: 14px;
margin-top: -20px;
padding-top: 32px;
`
const StyledInfoIcon = styled(Info)`
stroke: ${({ theme }) => theme.deprecated_text3};
`
/**
* @returns Dropdown card for showing edge case warnings outside of button
*/
export default function SwapWarningDropdown({
fiatValueInput,
trade,
}: {
fiatValueInput: CurrencyAmount<Token> | null
trade: InterfaceTrade<Currency, Currency, TradeType> | undefined
}) {
// gas cost estimate is more than half of input value
const showNetworkFeeWarning = Boolean(
fiatValueInput &&
trade?.gasUseEstimateUSD &&
parseFloat(trade.gasUseEstimateUSD.toSignificant(6)) > parseFloat(fiatValueInput.toFixed(6)) / 2
)
if (!showNetworkFeeWarning) {
return null
}
return (
<Wrapper>
{showNetworkFeeWarning ? (
<RowBetween>
<ThemedText.DeprecatedMain fontSize="14px" color="text3">
<Trans>Network fees exceed 50% of the swap amount!</Trans>
</ThemedText.DeprecatedMain>
<MouseoverTooltipContent
wrap={false}
content={
<ResponsiveTooltipContainer origin="top right" style={{ padding: '12px' }}>
<ThemedText.DeprecatedMain fontSize="12px" color="text3" maxWidth="200px">
<Trans>
The cost of sending this transaction is more than half of the value of the input amount.
</Trans>
</ThemedText.DeprecatedMain>
<ThemedText.DeprecatedMain fontSize="12px" color="text3" maxWidth="200px" mt="8px">
<Trans>You might consider waiting until the network fees go down to complete this transaction.</Trans>
</ThemedText.DeprecatedMain>
</ResponsiveTooltipContainer>
}
placement="bottom"
>
<StyledInfoIcon size={16} />
</MouseoverTooltipContent>
</RowBetween>
) : null}
</Wrapper>
)
}
...@@ -10,7 +10,7 @@ import { CUSD_CELO, DAI_OPTIMISM, USDC_ARBITRUM, USDC_MAINNET, USDC_POLYGON } fr ...@@ -10,7 +10,7 @@ import { CUSD_CELO, DAI_OPTIMISM, USDC_ARBITRUM, USDC_MAINNET, USDC_POLYGON } fr
// Stablecoin amounts used when calculating spot price for a given currency. // Stablecoin amounts used when calculating spot price for a given currency.
// The amount is large enough to filter low liquidity pairs. // The amount is large enough to filter low liquidity pairs.
export const STABLECOIN_AMOUNT_OUT: { [chainId: number]: CurrencyAmount<Token> } = { const STABLECOIN_AMOUNT_OUT: { [chainId: number]: CurrencyAmount<Token> } = {
[SupportedChainId.MAINNET]: CurrencyAmount.fromRawAmount(USDC_MAINNET, 100_000e6), [SupportedChainId.MAINNET]: CurrencyAmount.fromRawAmount(USDC_MAINNET, 100_000e6),
[SupportedChainId.ARBITRUM_ONE]: CurrencyAmount.fromRawAmount(USDC_ARBITRUM, 10_000e6), [SupportedChainId.ARBITRUM_ONE]: CurrencyAmount.fromRawAmount(USDC_ARBITRUM, 10_000e6),
[SupportedChainId.OPTIMISM]: CurrencyAmount.fromRawAmount(DAI_OPTIMISM, 10_000e18), [SupportedChainId.OPTIMISM]: CurrencyAmount.fromRawAmount(DAI_OPTIMISM, 10_000e18),
......
import { SupportedChainId } from 'constants/chains'
import { isAddress } from 'ethers/lib/utils'
import { useEffect, useState } from 'react'
// mock data relies on this wip reference:
// https://www.notion.so/uniswaplabs/GraphQL-Schema-eebbd70635ae4acc851e2542cb5de575
enum Currency {
USD,
}
enum TimePeriod {
hour = 'hour',
day = 'day',
week = 'week',
month = 'month',
year = 'year',
max = 'max',
}
interface HistoricalPrice {
id: string
currency: Currency
priceInCurrency: number
timestamp: string
}
type TokenDetailPageQueryResult = {
priceHistory: Partial<Record<SupportedChainId, HistoricalPrice[]>>
links: {
name: string
url: string
displayable_name: string
}[]
marketCap: number
volume: {
[TimePeriod.day]: number
}
}
interface UseTokenDetailPageQueryResult {
data: TokenDetailPageQueryResult | null
error: string | null
loading: boolean
}
const FAKE_TOKEN_DETAIL_PAGE_QUERY_RESULT: TokenDetailPageQueryResult = {
priceHistory: {
[SupportedChainId.MAINNET]: [
{
id: 'string',
currency: Currency.USD,
priceInCurrency: 1000,
timestamp: 'Sat Jul 23 2022 08:35:30 GMT-0000',
},
{
id: 'string',
currency: Currency.USD,
priceInCurrency: 1100,
timestamp: 'Sat Jul 23 2022 09:35:30 GMT-0000',
},
{
id: 'string',
currency: Currency.USD,
priceInCurrency: 900,
timestamp: 'Sat Jul 23 2022 10:35:30 GMT-0000',
},
],
},
links: [
{
name: 'github',
url: 'https://github.com/JFrankfurt',
displayable_name: 'Github',
},
{
name: 'twitter',
url: 'https://twitter.com/JordanFrankfurt',
displayable_name: 'Twitter',
},
],
marketCap: 1_000_000_000,
volume: {
[TimePeriod.day]: 1_000_000,
},
}
const useTokenDetailPageQuery = (tokenAddress: string | undefined): UseTokenDetailPageQueryResult => {
const [data, setData] = useState<TokenDetailPageQueryResult | null>(null)
const [error, setError] = useState<string | null>(null)
const [loading, setLoading] = useState(false)
const fetchTokenDetails = async (addresses: string): Promise<TokenDetailPageQueryResult | void> => {
const waitRandom = (min: number, max: number): Promise<void> =>
new Promise((resolve) => setTimeout(resolve, min + Math.round(Math.random() * Math.max(0, max - min))))
try {
setLoading(true)
setError(null)
await waitRandom(250, 2000)
if (Math.random() < 0.05) {
throw new Error('fake error')
}
console.log('fetchTokenDetails', addresses)
return FAKE_TOKEN_DETAIL_PAGE_QUERY_RESULT
} catch (e) {
setError('something went wrong')
} finally {
setLoading(false)
}
}
useEffect(() => {
if (tokenAddress && isAddress(tokenAddress)) {
setLoading(true)
setError(null)
fetchTokenDetails(tokenAddress)
.then((data) => {
if (data) setData(data)
})
.catch((e) => setError(e))
.finally(() => setLoading(false))
}
}, [tokenAddress])
return { data, error, loading }
}
export default useTokenDetailPageQuery
import { useEffect, useState } from 'react'
enum TimePeriod {
hour = 'hour',
day = 'day',
week = 'week',
month = 'month',
year = 'year',
}
type Dictionary<K extends keyof any, T> = Partial<Record<K, T>>
type TokenData = {
[address: string]: {
price: number
delta: Dictionary<TimePeriod, number>
}
}
interface UseTokenPriceResult {
data: TokenData | null
error: string | null
loading: boolean
}
const FAKE_TOKEN_PRICE_RESULT = {
'0x03ab458634910aad20ef5f1c8ee96f1d6ac54919': {
price: 3.05,
delta: {
[TimePeriod.hour]: 25_000,
[TimePeriod.day]: 619_000,
[TimePeriod.week]: 16_800_000,
[TimePeriod.month]: 58_920_000,
},
},
'0x0cec1a9154ff802e7934fc916ed7ca50bde6844e': {
price: 0.66543,
delta: {
[TimePeriod.hour]: 5_000,
[TimePeriod.day]: 100_000,
[TimePeriod.week]: 800_000,
[TimePeriod.month]: 4_920_000,
},
},
}
const useTokenPrice = (tokenAddresses: Set<string>): UseTokenPriceResult => {
const [data, setData] = useState<TokenData | null>(null)
const [error, setError] = useState<string | null>(null)
const [loading, setLoading] = useState(false)
const fetchTokenPrices = async (addresses: Set<string>): Promise<TokenData | void> => {
const waitRandom = (min: number, max: number): Promise<void> =>
new Promise((resolve) => setTimeout(resolve, min + Math.round(Math.random() * Math.max(0, max - min))))
try {
setLoading(true)
setError(null)
await waitRandom(250, 2000)
if (Math.random() < 0.05) {
throw new Error('fake error')
}
console.log('fetchTokenPrices', addresses)
return FAKE_TOKEN_PRICE_RESULT
} catch (e) {
setError('something went wrong')
} finally {
setLoading(false)
}
}
useEffect(() => {
setLoading(true)
setError(null)
fetchTokenPrices(tokenAddresses)
.then((data) => {
if (data) setData(data)
})
.catch((e) => setError(e))
.finally(() => setLoading(false))
}, [tokenAddresses])
return { data, error, loading }
}
export default useTokenPrice
import { useEffect, useState } from 'react'
interface RelevantResource {
name: string
url: string
displayName: string
}
interface RelevantResourcesMap {
[address: string]: RelevantResource[]
}
interface useTokenRelevantResourcesResult {
data: RelevantResourcesMap | null
error: string | null
loading: boolean
}
const FAKE_TOKEN_RELEVANT_RESOURCES = {
'0x03ab458634910aad20ef5f1c8ee96f1d6ac54919': [
{
name: 'github',
url: 'https://github.com/reflexer-labs/',
displayName: 'Github',
},
{
name: 'website',
url: 'https://reflexer.finance/',
displayName: 'reflexer.finance',
},
],
'0x0cec1a9154ff802e7934fc916ed7ca50bde6844e': [
{
name: 'github',
url: 'https://github.com/pooltogether/',
displayName: 'Github',
},
{
name: 'website',
url: 'https://pooltogether.com/',
displayName: 'pooltogether.com',
},
],
}
const useTokenRelevantResources = (addresses: Set<string>): useTokenRelevantResourcesResult => {
const [data, setData] = useState<RelevantResourcesMap | null>(null)
const [error, setError] = useState<string | null>(null)
const [loading, setLoading] = useState(false)
const fetchRelevantResources = async (addresses: Set<string>): Promise<RelevantResourcesMap | void> => {
const waitRandom = (min: number, max: number): Promise<void> =>
new Promise((resolve) => setTimeout(resolve, min + Math.round(Math.random() * Math.max(0, max - min))))
try {
setLoading(true)
setError(null)
console.log('useTokenRelevantResources.fetchRelevantResources', addresses)
await waitRandom(250, 2000)
if (Math.random() < 0.05) {
throw new Error('fake error')
}
return FAKE_TOKEN_RELEVANT_RESOURCES
} catch (e) {
setError('something went wrong')
} finally {
setLoading(false)
}
}
useEffect(() => {
setLoading(true)
setError(null)
fetchRelevantResources(addresses)
.then((data) => {
if (data) setData(data)
})
.catch((e) => setError(e))
.finally(() => setLoading(false))
}, [addresses])
return { data, error, loading }
}
export default useTokenRelevantResources
...@@ -38,7 +38,7 @@ export function getNativeLogoURI(chainId: SupportedChainId = SupportedChainId.MA ...@@ -38,7 +38,7 @@ export function getNativeLogoURI(chainId: SupportedChainId = SupportedChainId.MA
} }
} }
export function getTokenLogoURI(address: string, chainId: SupportedChainId = SupportedChainId.MAINNET): string | void { function getTokenLogoURI(address: string, chainId: SupportedChainId = SupportedChainId.MAINNET): string | void {
const networkName = chainIdToNetworkName(chainId) const networkName = chainIdToNetworkName(chainId)
const networksWithUrls = [SupportedChainId.ARBITRUM_ONE, SupportedChainId.MAINNET, SupportedChainId.OPTIMISM] const networksWithUrls = [SupportedChainId.ARBITRUM_ONE, SupportedChainId.MAINNET, SupportedChainId.OPTIMISM]
if (networksWithUrls.includes(chainId)) { if (networksWithUrls.includes(chainId)) {
......
...@@ -10,7 +10,7 @@ const oldestBlockMapAtom = atomWithImmer<{ [chainId: number]: number }>({}) ...@@ -10,7 +10,7 @@ const oldestBlockMapAtom = atomWithImmer<{ [chainId: number]: number }>({})
const DEFAULT_MAX_BLOCK_AGE = 10 const DEFAULT_MAX_BLOCK_AGE = 10
export function useGetIsValidBlock(maxBlockAge = DEFAULT_MAX_BLOCK_AGE): (block: number) => boolean { function useGetIsValidBlock(maxBlockAge = DEFAULT_MAX_BLOCK_AGE): (block: number) => boolean {
const { chainId } = useWeb3React() const { chainId } = useWeb3React()
const currentBlock = useBlockNumber() const currentBlock = useBlockNumber()
const oldestBlockMap = useAtomValue(oldestBlockMapAtom) const oldestBlockMap = useAtomValue(oldestBlockMapAtom)
......
...@@ -4,11 +4,8 @@ import { SupportedChainId } from 'constants/chains' ...@@ -4,11 +4,8 @@ import { SupportedChainId } from 'constants/chains'
import { useInterfaceMulticall } from 'hooks/useContract' import { useInterfaceMulticall } from 'hooks/useContract'
import useBlockNumber from 'lib/hooks/useBlockNumber' import useBlockNumber from 'lib/hooks/useBlockNumber'
import { useMemo } from 'react' import { useMemo } from 'react'
import { combineReducers, createStore } from 'redux'
const multicall = createMulticall() const multicall = createMulticall()
const reducer = combineReducers({ [multicall.reducerPath]: multicall.reducer })
export const store = createStore(reducer)
export default multicall export default multicall
......
export const backgrounds = ['#5DCCB9', '#9AFBCF', '#D1F8E7', '#73F54B', '#D3FB51', '#FCF958']
/**
* Format number in human-readable way
* @example
* ```js
* nFormat(134_256) // => 134K
* ```
* @param num number to format
* @param digits digits after decimal point
* @returns formatted number string
*/
export function nFormat(num: number, digits = 0): string {
const lookup = [
{ value: 1, symbol: '' },
//{ value: 1e3, symbol: 'K' },
{ value: 1e6, symbol: 'M' },
{ value: 1e9, symbol: 'B' },
{ value: 1e12, symbol: 'T' },
{ value: 1e15, symbol: 'Qa' },
{ value: 1e18, symbol: 'Qi' },
]
const rx = /\.0+$|(\.[0-9]*[1-9])0+$/
const item = lookup
.slice()
.reverse()
.find((item) => num >= item.value)
return item ? (num / item.value).toFixed(digits).replace(rx, '$1') + item.symbol : '0'
}
...@@ -62,12 +62,6 @@ export type OrderPayload = { ...@@ -62,12 +62,6 @@ export type OrderPayload = {
isCollection: boolean isCollection: boolean
} }
export type OrderResp = {
success: boolean
code: number
error?: string
}
const randomSalt = () => { const randomSalt = () => {
const randomHex = BigNumber.from(randomBytes(16)).toHexString() const randomHex = BigNumber.from(randomBytes(16)).toHexString()
return hexZeroPad(randomHex, 64) return hexZeroPad(randomHex, 64)
......
import { createSlice } from '@reduxjs/toolkit' import { createSlice } from '@reduxjs/toolkit'
import { ConnectionType } from 'connection' import { ConnectionType } from 'connection'
export interface ConnectionState { interface ConnectionState {
errorByConnectionType: Record<ConnectionType, string | undefined> errorByConnectionType: Record<ConnectionType, string | undefined>
} }
export const initialState: ConnectionState = { const initialState: ConnectionState = {
errorByConnectionType: { errorByConnectionType: {
[ConnectionType.INJECTED]: undefined, [ConnectionType.INJECTED]: undefined,
[ConnectionType.WALLET_CONNECT]: undefined, [ConnectionType.WALLET_CONNECT]: undefined,
......
...@@ -52,7 +52,7 @@ function useGovernanceBravoContract(): Contract | null { ...@@ -52,7 +52,7 @@ function useGovernanceBravoContract(): Contract | null {
const useLatestGovernanceContract = useGovernanceBravoContract const useLatestGovernanceContract = useGovernanceBravoContract
export function useUniContract() { function useUniContract() {
const { chainId } = useWeb3React() const { chainId } = useWeb3React()
const uniAddress = useMemo(() => (chainId ? UNI[chainId]?.address : undefined), [chainId]) const uniAddress = useMemo(() => (chainId ? UNI[chainId]?.address : undefined), [chainId])
return useContract(uniAddress, UNI_ABI, true) return useContract(uniAddress, UNI_ABI, true)
......
...@@ -22,7 +22,7 @@ export function useAllLists(): AppState['lists']['byUrl'] { ...@@ -22,7 +22,7 @@ export function useAllLists(): AppState['lists']['byUrl'] {
* @param map1 the base token map * @param map1 the base token map
* @param map2 the map of additioanl tokens to add to the base map * @param map2 the map of additioanl tokens to add to the base map
*/ */
export function combineMaps(map1: TokenAddressMap, map2: TokenAddressMap): TokenAddressMap { function combineMaps(map1: TokenAddressMap, map2: TokenAddressMap): TokenAddressMap {
const chainIds = Object.keys( const chainIds = Object.keys(
Object.keys(map1) Object.keys(map1)
.concat(Object.keys(map2)) .concat(Object.keys(map2))
......
...@@ -7,7 +7,7 @@ import { useAppDispatch, useAppSelector } from '../hooks' ...@@ -7,7 +7,7 @@ import { useAppDispatch, useAppSelector } from '../hooks'
import { addListener, removeListener } from './slice' import { addListener, removeListener } from './slice'
import { filterToKey, isHistoricalLog, Log } from './utils' import { filterToKey, isHistoricalLog, Log } from './utils'
export enum LogsState { enum LogsState {
// The filter is invalid // The filter is invalid
INVALID, INVALID,
// The logs are being loaded // The logs are being loaded
...@@ -20,7 +20,7 @@ export enum LogsState { ...@@ -20,7 +20,7 @@ export enum LogsState {
SYNCED, SYNCED,
} }
export interface UseLogsResult { interface UseLogsResult {
logs: Log[] | undefined logs: Log[] | undefined
state: LogsState state: LogsState
} }
......
...@@ -3,7 +3,7 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit' ...@@ -3,7 +3,7 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import { filterToKey, Log } from './utils' import { filterToKey, Log } from './utils'
export interface LogsState { interface LogsState {
[chainId: number]: { [chainId: number]: {
[filterKey: string]: { [filterKey: string]: {
listeners: number listeners: number
......
...@@ -10,7 +10,7 @@ import { ...@@ -10,7 +10,7 @@ import {
typeStartPriceInput, typeStartPriceInput,
} from './actions' } from './actions'
export type FullRange = true type FullRange = true
interface MintState { interface MintState {
readonly independentField: Field readonly independentField: Field
......
...@@ -37,7 +37,7 @@ export enum TransactionType { ...@@ -37,7 +37,7 @@ export enum TransactionType {
EXECUTE, EXECUTE,
} }
export interface BaseTransactionInfo { interface BaseTransactionInfo {
type: TransactionType type: TransactionType
} }
......
...@@ -53,8 +53,6 @@ export interface UserState { ...@@ -53,8 +53,6 @@ export interface UserState {
// undefined means has not gone through A/B split yet // undefined means has not gone through A/B split yet
showSurveyPopup: boolean | undefined showSurveyPopup: boolean | undefined
showDonationLink: boolean
hideNFTWelcomeModal: boolean hideNFTWelcomeModal: boolean
} }
...@@ -79,7 +77,6 @@ export const initialState: UserState = { ...@@ -79,7 +77,6 @@ export const initialState: UserState = {
URLWarningVisible: true, URLWarningVisible: true,
hideNFTPromoBanner: false, hideNFTPromoBanner: false,
showSurveyPopup: undefined, showSurveyPopup: undefined,
showDonationLink: true,
hideNFTWelcomeModal: false, hideNFTWelcomeModal: false,
} }
...@@ -123,9 +120,6 @@ const userSlice = createSlice({ ...@@ -123,9 +120,6 @@ const userSlice = createSlice({
updateShowSurveyPopup(state, action) { updateShowSurveyPopup(state, action) {
state.showSurveyPopup = action.payload.showSurveyPopup state.showSurveyPopup = action.payload.showSurveyPopup
}, },
updateShowDonationLink(state, action) {
state.showDonationLink = action.payload.showDonationLink
},
updateHideNFTWelcomeModal(state, action) { updateHideNFTWelcomeModal(state, action) {
state.hideNFTWelcomeModal = action.payload.hideNFTWelcomeModal state.hideNFTWelcomeModal = action.payload.hideNFTWelcomeModal
}, },
...@@ -213,7 +207,6 @@ export const { ...@@ -213,7 +207,6 @@ export const {
removeSerializedToken, removeSerializedToken,
updateHideClosedPositions, updateHideClosedPositions,
updateMatchesDarkMode, updateMatchesDarkMode,
updateShowDonationLink,
updateShowSurveyPopup, updateShowSurveyPopup,
updateUserClientSideRouter, updateUserClientSideRouter,
updateHideNFTWelcomeModal, updateHideNFTWelcomeModal,
......
...@@ -5,11 +5,11 @@ import { Wallet } from './types' ...@@ -5,11 +5,11 @@ import { Wallet } from './types'
/* Used to track wallets that have been connected by the user in current session, and remove them when deliberately disconnected. /* Used to track wallets that have been connected by the user in current session, and remove them when deliberately disconnected.
Used to compute is_reconnect event property for analytics */ Used to compute is_reconnect event property for analytics */
export interface WalletState { interface WalletState {
connectedWallets: Wallet[] connectedWallets: Wallet[]
} }
export const initialState: WalletState = { const initialState: WalletState = {
connectedWallets: [], connectedWallets: [],
} }
......
...@@ -95,7 +95,7 @@ export const colors = { ...@@ -95,7 +95,7 @@ export const colors = {
networkEthereumSoft: 'rgba(98, 126, 234, 0.16)', networkEthereumSoft: 'rgba(98, 126, 234, 0.16)',
} }
export type Theme = typeof darkTheme type Theme = typeof darkTheme
const commonTheme = { const commonTheme = {
white: colors.white, white: colors.white,
......
...@@ -7,8 +7,4 @@ export type TupleSplit<T, N extends number, O extends readonly any[] = readonly ...@@ -7,8 +7,4 @@ export type TupleSplit<T, N extends number, O extends readonly any[] = readonly
? TupleSplit<readonly [...R], N, readonly [...O, F]> ? TupleSplit<readonly [...R], N, readonly [...O, F]>
: [O, T] : [O, T]
export type TakeFirst<T extends readonly any[], N extends number> = TupleSplit<T, N>[0]
export type SkipFirst<T extends readonly any[], N extends number> = TupleSplit<T, N>[1] export type SkipFirst<T extends readonly any[], N extends number> = TupleSplit<T, N>[1]
export type NonNullable<T> = T extends null | undefined ? never : T
import { Version } from '@uniswap/token-lists'
export default function listVersionLabel(version: Version): string {
return `v${version.major}.${version.minor}.${version.patch}`
}
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