Skip to content

Commit

Permalink
fix: take permit amount into account when caching
Browse files Browse the repository at this point in the history
  • Loading branch information
shoom3301 committed Dec 25, 2024
1 parent 7d412c5 commit 70b26a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const storePermitCacheAtom = atom(null, (get, set, params: StorePermitCac
const dataToCache: CachedPermitData = {
hookData: params.hookData,
nonce: params.nonce,
amount: params.amount?.toString(),
}

set(atomToUpdate, (permitCache) => ({ ...permitCache, [key]: JSON.stringify(dataToCache) }))
Expand All @@ -61,7 +62,7 @@ export const getPermitCacheAtom = atom(null, (get, set, params: GetPermitCachePa
}

try {
const { hookData, nonce: storedNonce }: CachedPermitData = JSON.parse(cachedData)
const { hookData, nonce: storedNonce, amount }: CachedPermitData = JSON.parse(cachedData)

if (params.account !== undefined) {
// User type permit cache, check the nonce
Expand All @@ -76,6 +77,10 @@ export const getPermitCacheAtom = atom(null, (get, set, params: GetPermitCachePa

return undefined
}

if (params.amount) {
return params.amount.toString() === amount
}
}

// Cache hit for both static and user permit types
Expand Down
1 change: 1 addition & 0 deletions apps/cowswap-frontend/src/modules/permit/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type PermitCache = Record<string, string>
export type CachedPermitData = {
hookData: PermitHookData
nonce: number | undefined
amount: string | undefined
}

export type PermitCacheKeyParams = {
Expand Down

0 comments on commit 70b26a8

Please sign in to comment.