From c09f07338868654a89ba570987a8bc9bec59141c Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Fri, 13 Dec 2024 18:13:44 +0500 Subject: [PATCH 1/2] fix(twap): cache fb handler verification for 10min (#5200) --- .../twap/services/verifyExtensibleFallback.ts | 4 +++- .../FallbackHandlerVerificationUpdater.tsx | 14 +++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/cowswap-frontend/src/modules/twap/services/verifyExtensibleFallback.ts b/apps/cowswap-frontend/src/modules/twap/services/verifyExtensibleFallback.ts index 806353e7f6..706c224f38 100644 --- a/apps/cowswap-frontend/src/modules/twap/services/verifyExtensibleFallback.ts +++ b/apps/cowswap-frontend/src/modules/twap/services/verifyExtensibleFallback.ts @@ -25,12 +25,14 @@ export async function verifyExtensibleFallback( try { const domainVerifier = await signatureVerifierContract.callStatic.domainVerifiers(safeAddress, domainSeparator) + console.log('FALLBACK HANDLER CHECKED, domainVerifier: ', domainVerifier) if (domainVerifier.toLowerCase() === composableCowContractAddress.toLowerCase()) { return ExtensibleFallbackVerification.HAS_DOMAIN_VERIFIER } return ExtensibleFallbackVerification.HAS_EXTENSIBLE_FALLBACK - } catch { + } catch (e) { + console.log('FALLBACK HANDLER CHECKED, error: ', e) return ExtensibleFallbackVerification.HAS_NOTHING } } diff --git a/apps/cowswap-frontend/src/modules/twap/updaters/FallbackHandlerVerificationUpdater.tsx b/apps/cowswap-frontend/src/modules/twap/updaters/FallbackHandlerVerificationUpdater.tsx index 8ec9e6244d..5c43ed188e 100644 --- a/apps/cowswap-frontend/src/modules/twap/updaters/FallbackHandlerVerificationUpdater.tsx +++ b/apps/cowswap-frontend/src/modules/twap/updaters/FallbackHandlerVerificationUpdater.tsx @@ -3,6 +3,7 @@ import { useEffect } from 'react' import { useWalletInfo } from '@cowprotocol/wallet' +import ms from 'ms.macro' import { useAsyncMemo } from 'use-async-memo' import { useExtensibleFallbackContext } from '../hooks/useExtensibleFallbackContext' @@ -10,26 +11,33 @@ import { useFallbackHandlerVerification } from '../hooks/useFallbackHandlerVerif import { ExtensibleFallbackVerification, verifyExtensibleFallback } from '../services/verifyExtensibleFallback' import { updateFallbackHandlerVerificationAtom } from '../state/fallbackHandlerVerificationAtom' +const FB_CACHE_TIME = ms`10m` +const FB_UPDATE_TIME_KEY = 'fallbackHandlerUpdateTime' + export function FallbackHandlerVerificationUpdater() { const { account } = useWalletInfo() const update = useSetAtom(updateFallbackHandlerVerificationAtom) const verification = useFallbackHandlerVerification() const isFallbackHandlerRequired = verification !== ExtensibleFallbackVerification.HAS_DOMAIN_VERIFIER + const fallbackHandlerUpdateTime = localStorage.getItem(FB_UPDATE_TIME_KEY) + const isCacheOutdated = !fallbackHandlerUpdateTime || Date.now() - +fallbackHandlerUpdateTime > FB_CACHE_TIME + const extensibleFallbackContext = useExtensibleFallbackContext() const fallbackHandlerVerification = useAsyncMemo( () => - extensibleFallbackContext && isFallbackHandlerRequired + extensibleFallbackContext && (isFallbackHandlerRequired || isCacheOutdated) ? verifyExtensibleFallback(extensibleFallbackContext) : null, - [isFallbackHandlerRequired, extensibleFallbackContext], - null + [isFallbackHandlerRequired, isCacheOutdated, extensibleFallbackContext], + null, ) useEffect(() => { if (!account || fallbackHandlerVerification === null) return update({ [account]: fallbackHandlerVerification }) + localStorage.setItem(FB_UPDATE_TIME_KEY, Date.now().toString()) }, [fallbackHandlerVerification, update, account]) return null From db89e12d23213a5cfa20c31dc4b1e2bd6ac02816 Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Fri, 13 Dec 2024 19:41:26 +0500 Subject: [PATCH 2/2] chore: release main (#5201) --- .release-please-manifest.json | 2 +- apps/cowswap-frontend/CHANGELOG.md | 7 +++++++ apps/cowswap-frontend/package.json | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index e34618b6bd..53ce0c45af 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,5 +1,5 @@ { - "apps/cowswap-frontend": "1.93.1", + "apps/cowswap-frontend": "1.93.2", "apps/explorer": "2.38.0", "libs/permit-utils": "0.5.0", "libs/widget-lib": "0.18.0", diff --git a/apps/cowswap-frontend/CHANGELOG.md b/apps/cowswap-frontend/CHANGELOG.md index cc512e274e..c754fa057c 100644 --- a/apps/cowswap-frontend/CHANGELOG.md +++ b/apps/cowswap-frontend/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [1.93.2](https://github.com/cowprotocol/cowswap/compare/cowswap-v1.93.1...cowswap-v1.93.2) (2024-12-13) + + +### Bug Fixes + +* **twap:** cache fb handler verification for 10min ([#5200](https://github.com/cowprotocol/cowswap/issues/5200)) ([c09f073](https://github.com/cowprotocol/cowswap/commit/c09f07338868654a89ba570987a8bc9bec59141c)) + ## [1.93.1](https://github.com/cowprotocol/cowswap/compare/cowswap-v1.93.0...cowswap-v1.93.1) (2024-12-12) diff --git a/apps/cowswap-frontend/package.json b/apps/cowswap-frontend/package.json index b69f0b35eb..90ff2afa12 100644 --- a/apps/cowswap-frontend/package.json +++ b/apps/cowswap-frontend/package.json @@ -1,6 +1,6 @@ { "name": "@cowprotocol/cowswap", - "version": "1.93.1", + "version": "1.93.2", "description": "CoW Swap", "main": "index.js", "author": "",