Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/cowprotocol/cowswap into de…
Browse files Browse the repository at this point in the history
…velop
  • Loading branch information
shoom3301 committed Oct 19, 2023
2 parents ce3e1b3 + 8a219e6 commit ea85d84
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [1.48.7](https://github.com/cowprotocol/cowswap/compare/v1.48.6...v1.48.7) (2023-10-19)


### Bug Fixes

* **swap:** periodically refresh unsupported tokens state ([#3252](https://github.com/cowprotocol/cowswap/issues/3252)) ([f5986a3](https://github.com/cowprotocol/cowswap/commit/f5986a30f850eead4eb633069967ac34947ab68e))

## [1.48.6](https://github.com/cowprotocol/cowswap/compare/v1.48.5...v1.48.6) (2023-10-18)


Expand Down
14 changes: 13 additions & 1 deletion apps/cowswap-frontend/src/common/updaters/FeesUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { OrderKind } from '@cowprotocol/cow-sdk'
import { useENSAddress } from '@cowprotocol/ens'
import { useWalletInfo } from '@cowprotocol/wallet'

import ms from 'ms.macro'

import { useRefetchQuoteCallback } from 'legacy/hooks/useRefetchPriceCallback'
import { useIsUnsupportedTokenGp } from 'legacy/state/lists/hooks'
import { useAllQuotes, useIsBestQuoteLoading, useSetQuoteError } from 'legacy/state/price/hooks'
Expand All @@ -29,6 +31,14 @@ 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 @@ -233,7 +243,9 @@ export function FeesUpdater(): null {
// Callback to re-fetch both the fee and the price
const refetchQuoteIfRequired = () => {
// if no token is unsupported and needs refetching
const hasToRefetch = !unsupportedToken && isRefetchQuoteRequired(isLoading, quoteParams, quoteInfo)
const hasToRefetch =
(!unsupportedToken || isUnsupportedTokenExpired(unsupportedToken)) &&
isRefetchQuoteRequired(isLoading, quoteParams, quoteInfo)

if (hasToRefetch) {
// Decide if this is a new quote, or just a refresh
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cowswap",
"version": "1.48.6",
"version": "1.48.7",
"description": "CoW Swap",
"main": "index.js",
"author": "",
Expand Down

0 comments on commit ea85d84

Please sign in to comment.