From f5986a30f850eead4eb633069967ac34947ab68e Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Thu, 19 Oct 2023 18:56:00 +0600 Subject: [PATCH 1/2] fix(swap): periodically refresh unsupported tokens state (#3252) --- .../src/common/updaters/FeesUpdater.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/cowswap-frontend/src/common/updaters/FeesUpdater.ts b/apps/cowswap-frontend/src/common/updaters/FeesUpdater.ts index dfaf831e1b..d8deca92cd 100644 --- a/apps/cowswap-frontend/src/common/updaters/FeesUpdater.ts +++ b/apps/cowswap-frontend/src/common/updaters/FeesUpdater.ts @@ -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' @@ -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 @@ -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 From 8a219e6aa74ec11ea8adbe9a3ca9cc7a1026c77c Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Thu, 19 Oct 2023 18:57:53 +0600 Subject: [PATCH 2/2] chore(main): release 1.48.7 (#3253) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 175b3d7320..916058d8ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/package.json b/package.json index 5225372f6f..1a35988f55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cowswap", - "version": "1.48.6", + "version": "1.48.7", "description": "CoW Swap", "main": "index.js", "author": "",