Skip to content

Commit

Permalink
🐺 More extensive check for provider object in renderWeb3Hook (#830)
Browse files Browse the repository at this point in the history
  • Loading branch information
rzadp authored Jun 20, 2022
1 parent 0600742 commit 55a28a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-fans-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@usedapp/core": patch
---

🐺 More extensive check for provider object in `renderWeb3Hook`
15 changes: 12 additions & 3 deletions packages/core/src/testing/renderWeb3Hook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React from 'react'
import { deployMulticall, getWaitUtils, IdentityWrapper, mineBlock } from './utils'
import { BlockNumbersProvider } from '../providers/blockNumber/blockNumbers'
import { ReadonlyNetworksProvider } from '../providers/network'
import { providers as ethersProviders } from 'ethers'

export interface renderWeb3HookOptions<Tprops> {
mockProvider?: MockProvider | Record<number /* ChainId */, MockProvider>
Expand Down Expand Up @@ -55,9 +56,17 @@ export const renderWeb3Hook = async <Tprops, TResult>(
}

const providerObject = options?.mockProvider || new MockProvider()
if (providerObject instanceof MockProvider) {
defaultProvider = providerObject
await addSingleProvider(providerObject)
if (
providerObject instanceof MockProvider ||
/**
* We still expect this to be a MockProvider,
* but this is an override in case a different instance of the provider package is used
* and the TS types are not matching.
*/
ethersProviders.Web3Provider.isProvider(providerObject)
) {
defaultProvider = providerObject as MockProvider
await addSingleProvider(providerObject as MockProvider)
} else {
for (const chainIdString in providerObject) {
const chainId = Number(chainIdString)
Expand Down

3 comments on commit 55a28a2

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.