Skip to content

Commit

Permalink
fix: skip partial permits in widgets besides swap
Browse files Browse the repository at this point in the history
  • Loading branch information
shoom3301 committed Dec 25, 2024
1 parent 0fcb1f8 commit ba8e237
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions apps/cowswap-frontend/src/modules/permit/state/permitCacheAtom.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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]

Expand All @@ -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
}
Expand Down

0 comments on commit ba8e237

Please sign in to comment.