From ba8e2378dd5850489a7a746666df79048203e3e1 Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Wed, 25 Dec 2024 18:22:13 +0500 Subject: [PATCH] fix: skip partial permits in widgets besides swap --- .../src/modules/permit/state/permitCacheAtom.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/apps/cowswap-frontend/src/modules/permit/state/permitCacheAtom.ts b/apps/cowswap-frontend/src/modules/permit/state/permitCacheAtom.ts index 5e3954ada3..b0d06691e3 100644 --- a/apps/cowswap-frontend/src/modules/permit/state/permitCacheAtom.ts +++ b/apps/cowswap-frontend/src/modules/permit/state/permitCacheAtom.ts @@ -1,6 +1,12 @@ import { atom } from 'jotai' import { atomWithStorage } from 'jotai/utils' +import { MaxUint256 } from '@ethersproject/constants' + +import { TradeType, tradeTypeAtom } from 'modules/trade' + +import { Routes } from 'common/constants/routes' + import { CachedPermitData, GetPermitCacheParams, @@ -54,6 +60,10 @@ export const getPermitCacheAtom = atom(null, (get, set, params: GetPermitCachePa const atomToUpdate = params.account ? userPermitCacheAtom : staticPermitCacheAtom const permitCache = get(atomToUpdate) + const tradeType = get(tradeTypeAtom) + + const isSwap = tradeType?.tradeType === TradeType.SWAP && tradeType.route === Routes.SWAP + const key = buildKey(params) const cachedData = permitCache[key] @@ -78,6 +88,12 @@ export const getPermitCacheAtom = atom(null, (get, set, params: GetPermitCachePa return undefined } + // Only Swap might create partial amount permits + // Because of that, we skip cached permits with partial amount in other widgets + if (!isSwap && amount && amount !== MaxUint256.toString()) { + return false + } + if (params.amount) { return params.amount.toString() === amount }