Skip to content

Commit

Permalink
chore: add more logging to permit utils creation
Browse files Browse the repository at this point in the history
  • Loading branch information
alfetopito committed Oct 13, 2023
1 parent 94eefc8 commit c010d4f
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const CHAIN_UTILS_CACHE = new Map<number, Eip2612PermitUtils>()
/**
* Cache by provider. Here we cache per provider as each account should have its own instance
*/
const PROVIDER_UTILS_CACHE = new Map<Web3Provider, Eip2612PermitUtils>()
const PROVIDER_UTILS_CACHE = new Map<string, Eip2612PermitUtils>()

export function getPermitUtilsInstance(
chainId: SupportedChainId,
Expand All @@ -24,21 +24,29 @@ export function getPermitUtilsInstance(
const chainCache = CHAIN_UTILS_CACHE.get(chainId)

if (!account && chainCache) {
console.log(`[getPermitUtilsInstance] Using cached chain utils for chain ${chainId}`, chainCache)
return chainCache
}
const providerCache = PROVIDER_UTILS_CACHE.get(provider)
const providerCacheKey = `${chainId}-${account}`
const providerCache = PROVIDER_UTILS_CACHE.get(providerCacheKey)

if (providerCache) {
console.log(`[getPermitUtilsInstance] Using cached provider utils for chain ${chainId}-${account}`, providerCache)
return providerCache
}

const web3ProviderConnector = new PermitProviderConnector(provider, account ? undefined : PERMIT_SIGNER)
const eip2612PermitUtils = new Eip2612PermitUtils(web3ProviderConnector)

if (!account) {
console.log(`[getPermitUtilsInstance] Set cached chain utils for chain ${chainId}`, eip2612PermitUtils)
CHAIN_UTILS_CACHE.set(chainId, eip2612PermitUtils)
} else {
PROVIDER_UTILS_CACHE.set(provider, eip2612PermitUtils)
console.log(
`[getPermitUtilsInstance] Set cached provider utils for chain ${chainId}-${account}`,
eip2612PermitUtils
)
PROVIDER_UTILS_CACHE.set(providerCacheKey, eip2612PermitUtils)
}

return eip2612PermitUtils
Expand Down

0 comments on commit c010d4f

Please sign in to comment.