Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7] fix(tokens): fix tokens list loading state #3201

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
840af3f
fix: fix tokens list loading state
shoom3301 Oct 10, 2023
d1f8851
fix: fix token store updating inconsistency
shoom3301 Oct 10, 2023
70b87f9
chore: move DEFAULT_FAVOURITE_TOKENS to separate file
shoom3301 Oct 10, 2023
58b890f
refactor: refactor useSearchToken() hook
shoom3301 Oct 10, 2023
614feea
chore: fix tokens lib exports
shoom3301 Oct 10, 2023
b5c1508
chore: refactor TokensListsUpdater
shoom3301 Oct 10, 2023
c3cc4a8
fix: remove duplicates from token search results
shoom3301 Oct 10, 2023
e1626e7
fix(tokens): fix lists toggling
shoom3301 Oct 10, 2023
16ef0a0
fix(tokens): fix list importing
shoom3301 Oct 10, 2023
2a8d3d7
refactor(tokens): refactor tokens state
shoom3301 Oct 11, 2023
d8e4330
Merge branch 'refactor/tokens-remove-legacy' of https://github.com/co…
shoom3301 Oct 11, 2023
7287a63
feat(tokens): lists analytics events
shoom3301 Oct 11, 2023
e7573de
refactor: group and rename entities
shoom3301 Oct 11, 2023
e6be7d3
chore: fix imports
shoom3301 Oct 11, 2023
c684d98
chore: fix cosmos fixtures
shoom3301 Oct 11, 2023
822d170
chore: remove unused code
shoom3301 Oct 11, 2023
9701d07
Merge branch 'refactor/tokens-remove-legacy' of https://github.com/co…
shoom3301 Oct 11, 2023
2592593
chore: fix import
shoom3301 Oct 11, 2023
db8105f
chore: fix typo
shoom3301 Oct 11, 2023
4a28d8c
chore: trim input value
shoom3301 Oct 11, 2023
caeeeb7
chore: fix list removing
shoom3301 Oct 11, 2023
c1ac055
chore: diagrams
shoom3301 Oct 11, 2023
6837b14
refactor: simplify unsupported token hooks
shoom3301 Oct 12, 2023
cc53a88
refactor: simplify useSearchToken
shoom3301 Oct 12, 2023
3127c0e
refactor: rename isTokenAlreadyFoundByAddress
shoom3301 Oct 12, 2023
7370a0b
refactor: use lastUpdateTimeAtom instead of localStorage
shoom3301 Oct 12, 2023
4ab7dbd
chore: remove TOKENS_LISTS_UPDATER_INTERVAL duplicate
shoom3301 Oct 12, 2023
7400345
refactor: use TokenWithLogo.fromToken
shoom3301 Oct 12, 2023
9fc64a1
fix: fix FavouriteTokensList mobile view
shoom3301 Oct 16, 2023
437ca57
fix: fix mobile appearance
shoom3301 Oct 16, 2023
e02d368
fix: select token after import
shoom3301 Oct 16, 2023
45feae5
fix: search token by symbol for autoimporting
shoom3301 Oct 16, 2023
5552b69
feat: add trust as a fallback to logo urls
shoom3301 Oct 16, 2023
734c5f4
refactor: simplify TokenSearchResponse
shoom3301 Oct 16, 2023
20af0e7
chore: docs for complex entities
shoom3301 Oct 16, 2023
c11ac54
chore: cache inputLowerCase
shoom3301 Oct 16, 2023
e1bae58
chore: rename tokenMapToListWithLogo
shoom3301 Oct 16, 2023
cbeaa9b
chore: remove unused files
shoom3301 Oct 17, 2023
010dcb2
feat: reset unsupported tokens periodically
shoom3301 Oct 17, 2023
f07e036
chore: remove excessive files
shoom3301 Oct 17, 2023
34e06de
fix: use token with logo in orders state
shoom3301 Oct 17, 2023
bf7490c
Merge branch 'refactor/tokens-remove-legacy' of https://github.com/co…
shoom3301 Oct 17, 2023
b12a429
refactor: simplify token lists state
shoom3301 Oct 17, 2023
2243394
fix: remove local logos for tokens
shoom3301 Oct 17, 2023
3a8ffc4
chore: fix test
shoom3301 Oct 17, 2023
19e7d6d
chore: change refreshInterval for native balance
shoom3301 Oct 17, 2023
b3cc7ca
refactor: fix press enter handler
shoom3301 Oct 17, 2023
c4cc71e
chore: fix build
shoom3301 Oct 17, 2023
55d2528
chore: fix test
shoom3301 Oct 17, 2023
b2dd6b3
chore: fix text
shoom3301 Oct 17, 2023
099c3bc
chore: fix OrderLogPopupMixData
shoom3301 Oct 17, 2023
2903c28
chore: merge develop
shoom3301 Oct 23, 2023
40c0d9d
chore: fix build
shoom3301 Oct 23, 2023
78dc458
chore: fix build
shoom3301 Oct 23, 2023
b3192bd
chore: fix getTokenLogoFallbacks
shoom3301 Oct 23, 2023
3d28e21
chore: fix lists overriding and search input
shoom3301 Oct 23, 2023
6a7a227
feat: loader for list search
shoom3301 Oct 23, 2023
8602757
chore: fix token logo rounding
shoom3301 Oct 24, 2023
f4af72b
chore: fix tokens sorting
shoom3301 Oct 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/cowswap-frontend/src/common/hooks/useNativeBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ms from 'ms.macro'
import useSWR, { SWRConfiguration, SWRResponse } from 'swr'

const swrOptions: SWRConfiguration = {
refreshInterval: ms`1m`,
refreshInterval: ms`30s`,
revalidateOnFocus: false,
}

Expand Down
20 changes: 4 additions & 16 deletions apps/cowswap-frontend/src/common/updaters/FeesUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { useENSAddress } from '@cowprotocol/ens'
import { useIsUnsupportedToken } from '@cowprotocol/tokens'
import { useWalletInfo } from '@cowprotocol/wallet'

import ms from 'ms.macro'

import { useRefetchQuoteCallback } from 'legacy/hooks/useRefetchPriceCallback'
import { useAllQuotes, useIsBestQuoteLoading, useSetQuoteError } from 'legacy/state/price/hooks'
import { QuoteInformationObject } from 'legacy/state/price/reducer'
Expand All @@ -31,14 +29,6 @@ export const TYPED_VALUE_DEBOUNCE_TIME = 350
const REFETCH_CHECK_INTERVAL = 10000 // Every 10s
const RENEW_FEE_QUOTES_BEFORE_EXPIRATION_TIME = 30000 // Will renew the quote if there's less than 30 seconds left for the quote to expire
const WAITING_TIME_BETWEEN_EQUAL_REQUESTS = 5000 // Prevents from sending the same request to often (max, every 5s)
const UNSUPPORTED_TOKEN_TTL = ms`1h`

/**
* Since a token might become supported, we should periodically (once in 1h) refresh its state
*/
const isUnsupportedTokenExpired = ({ dateAdded }: { dateAdded: number }) => {
return dateAdded + UNSUPPORTED_TOKEN_TTL < Date.now()
}

type FeeQuoteParams = Omit<LegacyFeeQuoteParams, 'validTo'>

Expand Down Expand Up @@ -158,7 +148,7 @@ export function FeesUpdater(): null {
const isLoading = useIsBestQuoteLoading()
const isEthFlow = useIsEoaEthFlow()

const isUnsupportedTokenGp = useIsUnsupportedToken()
const isUnsupportedToken = useIsUnsupportedToken()

const appData = useAppData()

Expand Down Expand Up @@ -238,14 +228,12 @@ export function FeesUpdater(): null {
}
}

const unsupportedToken = isUnsupportedTokenGp(sellCurrencyId) || isUnsupportedTokenGp(buyCurrencyId)
const unsupportedToken = isUnsupportedToken(sellCurrencyId) || isUnsupportedToken(buyCurrencyId)

// Callback to re-fetch both the fee and the price
const refetchQuoteIfRequired = () => {
// if no token is unsupported and needs refetching
const hasToRefetch =
(!unsupportedToken || isUnsupportedTokenExpired(unsupportedToken)) &&
isRefetchQuoteRequired(isLoading, quoteParams, quoteInfo)
const hasToRefetch = !unsupportedToken && isRefetchQuoteRequired(isLoading, quoteParams, quoteInfo)

if (hasToRefetch) {
// Decide if this is a new quote, or just a refresh
Expand Down Expand Up @@ -286,7 +274,7 @@ export function FeesUpdater(): null {
buyCurrency,
quoteInfo,
refetchQuote,
isUnsupportedTokenGp,
isUnsupportedToken,
isLoading,
setQuoteError,
account,
Expand Down
4 changes: 3 additions & 1 deletion apps/cowswap-frontend/src/common/updaters/orders/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { stringToCurrency } from 'legacy/state/swap/extension'
import { getOrder } from 'api/gnosisProtocol'
import { getIsComposableCowChildOrder } from 'utils/orderUtils/getIsComposableCowChildOrder'

export type OrderLogPopupMixData = OrderFulfillmentData | string
type OrderID = string

export type OrderLogPopupMixData = OrderFulfillmentData | OrderID

export function computeOrderSummary({
orderFromStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { getDefaultTradeRawState } from 'modules/trade/types/TradeRawState'
import { Routes } from 'common/constants/routes'
import { useCategorizeRecentActivity } from 'common/hooks/useCategorizeRecentActivity'
import { useIsProviderNetworkUnsupported } from 'common/hooks/useIsProviderNetworkUnsupported'
import { useNativeBalance } from 'common/hooks/useNativeBalance'

import { AccountElement } from './AccountElement'
import MobileMenuIcon from './MobileMenuIcon'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React, { ReactNode, useMemo } from 'react'

import alertImage from '@cowprotocol/assets/cow-swap/alert-circle.svg'
import checkImage from '@cowprotocol/assets/cow-swap/check.svg'
import { getChainCurrencySymbols } from '@cowprotocol/common-const'
import { NATIVE_CURRENCY_BUY_TOKEN, WRAPPED_NATIVE_CURRENCY } from '@cowprotocol/common-const'
import { shortenAddress } from '@cowprotocol/common-utils'
import { SupportedChainId } from '@cowprotocol/cow-sdk'
import { ExternalLink } from '@cowprotocol/ui'
import {
getWeb3ReactConnection,
Expand Down Expand Up @@ -47,7 +48,11 @@ enum WalletType {
}

export function getOperationMessage(operationType: ConfirmOperationType, chainId: number): string {
const { native, wrapped } = getChainCurrencySymbols(chainId)
const nativeToken = NATIVE_CURRENCY_BUY_TOKEN[chainId as SupportedChainId]
const wrappedToken = WRAPPED_NATIVE_CURRENCY[chainId as SupportedChainId]

const native = nativeToken.symbol
const wrapped = wrappedToken.symbol

switch (operationType) {
case ConfirmOperationType.WRAP_ETHER:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ConfirmOperationType } from 'legacy/state/types'
import { LegacyConfirmationPendingContent } from './LegacyConfirmationPendingContent'

import { cowSwapStore } from '../../state'
import { SerializedToken } from '../../state/user/types'

const txHash = '0xe87e1d02b052daa9605abe018e8172feffd1bc38ed2284e6hhhhhh' + Date.now()

Expand Down Expand Up @@ -46,8 +47,8 @@ cowSwapStore.dispatch(
id: txHash,
chainId: 5,
order: {
inputToken: COW[SupportedChainId.MAINNET],
outputToken: GNO[SupportedChainId.MAINNET],
inputToken: COW[SupportedChainId.MAINNET] as SerializedToken,
outputToken: GNO[SupportedChainId.MAINNET] as SerializedToken,
sellToken: COW[SupportedChainId.MAINNET].address,
buyToken: GNO[SupportedChainId.MAINNET].address,
sellAmount: '1000',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,17 @@ export function useRefetchQuoteCallback() {
description: GpQuoteErrorDetails.ZeroPrice,
})

const previouslyUnsupportedToken = getIsUnsupportedToken(sellToken) || getIsUnsupportedToken(buyToken)
const previouslyUnsupportedToken = getIsUnsupportedToken(sellToken)
? sellToken
: getIsUnsupportedToken(buyToken)
? buyToken
: null
// can be a previously unsupported token which is now valid
// so we check against map and remove it
if (previouslyUnsupportedToken) {
console.debug('[useRefetchPriceCallback]::Previously unsupported token now supported - re-enabling.')

removeGpUnsupportedToken(previouslyUnsupportedToken.address)
removeGpUnsupportedToken(previouslyUnsupportedToken)
}

// Update quote
Expand Down
189 changes: 0 additions & 189 deletions apps/cowswap-frontend/src/legacy/hooks/useTokenLazy.ts

This file was deleted.

8 changes: 7 additions & 1 deletion apps/cowswap-frontend/src/legacy/state/orders/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback, useMemo } from 'react'

import { TokenWithLogo } from '@cowprotocol/common-const'
import { isTruthy } from '@cowprotocol/common-utils'
import { OrderClass, SupportedChainId } from '@cowprotocol/cow-sdk'

Expand Down Expand Up @@ -42,7 +43,8 @@ import {
import { isOrderExpired, partialOrderUpdate } from './utils'

import { AppDispatch, AppState } from '../index'
import { deserializeToken, serializeToken } from '../user/hooks'
import { serializeToken } from '../user/hooks'
import { SerializedToken } from '../user/types'

type OrderID = string

Expand Down Expand Up @@ -110,6 +112,10 @@ function _isV3Order(orderObject: any): orderObject is OrderObject {
return orderObject?.order?.inputToken !== undefined || orderObject?.order?.outputToken !== undefined
}

function deserializeToken(serializedToken: SerializedToken): TokenWithLogo {
return TokenWithLogo.fromToken(serializedToken, serializedToken.logoURI)
}

function _deserializeOrder(orderObject: OrderObject | V2OrderObject | undefined) {
let order: Order | undefined
// we need to make sure the incoming order is a valid
Expand Down
2 changes: 1 addition & 1 deletion apps/cowswap-frontend/src/legacy/state/orders/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ export function partialOrderUpdate({ chainId, order }: UpdateOrderParams, dispat
...order,
...(order.inputToken && { inputToken: serializeToken(order.inputToken) }),
...(order.outputToken && { outputToken: serializeToken(order.outputToken) }),
},
} as UpdateOrderParamsAction['order'],
}
dispatch(updateOrder(params))
}
Loading
Loading