diff --git a/src/hooks/index.ts b/src/hooks/index.ts index dad2829559..207904c8c3 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -132,15 +132,18 @@ const wrapProvider = (provider: Web3Provider, blackjackData: BlackjackCheck): We return target[prop as keyof Web3Provider] }, }) -const cache = new Map() +const cacheProvider = new WeakMap() const useWrappedProvider = () => { const { provider, account } = useWeb3ReactCore() const { data: blackjackData } = useCheckBlackjackQuery(account ?? '', { skip: !account }) if (!provider) return undefined if (!blackjackData) return undefined - const wrappedProvider = cache.get(provider) || wrapProvider(provider, blackjackData) - cache.set(provider, wrappedProvider) + let wrappedProvider = cacheProvider.get(provider) + if (!wrappedProvider) { + wrappedProvider = wrapProvider(provider, blackjackData) + cacheProvider.set(provider, wrappedProvider) + } return wrappedProvider }