-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(balances): always use network provider for multicalls (#3387)
* fix(balances): always use network provider for multicalls * chore: temporarily disable failing tests unrelated to current changes --------- Co-authored-by: Alfetopito <[email protected]>
- Loading branch information
1 parent
d76bcdb
commit 94728d4
Showing
3 changed files
with
36 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
import { useEffect } from 'react' | ||
|
||
import { useInterfaceMulticall, useBlockNumber } from '@cowprotocol/common-hooks' | ||
import { networkConnection } from '@cowprotocol/wallet' | ||
import { Web3Provider } from '@ethersproject/providers' | ||
import { createMulticall } from '@uniswap/redux-multicall' | ||
import { useWeb3React } from '@web3-react/core' | ||
|
||
// TODO: enable only for MevBlocker | ||
const shouldUseNetworkProvider = true | ||
|
||
export const multicall = createMulticall() | ||
|
||
export function MulticallUpdater() { | ||
const { chainId } = useWeb3React() | ||
const { chainId: currentChainId, connector } = useWeb3React() | ||
const latestBlockNumber = useBlockNumber() | ||
const contract = useInterfaceMulticall() | ||
|
||
return <multicall.Updater chainId={chainId} latestBlockNumber={latestBlockNumber} contract={contract} /> | ||
const customProvider = networkConnection.connector.customProvider as Web3Provider | undefined | ||
const contract = useInterfaceMulticall(shouldUseNetworkProvider ? customProvider : undefined) | ||
|
||
// Multicall uses the network connector because of Mevblocker issue | ||
// So, the networkConnection should be synced with the current provider | ||
useEffect(() => { | ||
if (!shouldUseNetworkProvider) return | ||
|
||
if (currentChainId && connector !== networkConnection.connector) { | ||
networkConnection.connector.activate(currentChainId) | ||
} | ||
}, [currentChainId, connector]) | ||
|
||
return <multicall.Updater chainId={currentChainId} latestBlockNumber={latestBlockNumber} contract={contract} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94728d4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
widget-configurator – ./
widget-configurator-cowswap.vercel.app
widget-configurator-seven.vercel.app
widget-configurator-git-main-cowswap.vercel.app
widget.cow.fi
94728d4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
cosmos – ./
cosmos-cowswap.vercel.app
cowswap-seven.vercel.app
cosmos.cow.fi
cosmos-git-main-cowswap.vercel.app