-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'GTM-migration' into GTM-migration-buildfix
- Loading branch information
Showing
43 changed files
with
414 additions
and
201 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
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
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
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
23 changes: 23 additions & 0 deletions
23
apps/cowswap-frontend/src/common/utils/assertProviderNetwork.ts
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { getChainIdImmediately } from '@cowprotocol/common-utils' | ||
import { SupportedChainId } from '@cowprotocol/cow-sdk' | ||
import { JsonRpcProvider, Provider } from '@ethersproject/providers' | ||
|
||
export async function assertProviderNetwork( | ||
chainId: SupportedChainId, | ||
provider: JsonRpcProvider | Provider, | ||
description: string, | ||
): Promise<SupportedChainId> { | ||
const ethereumProvider = (provider as unknown as { provider: typeof window.ethereum }).provider | ||
|
||
// Do assert only for Metamask | ||
if (!ethereumProvider || !ethereumProvider.isMetaMask || ethereumProvider.isRabby) return chainId | ||
|
||
const network = await getChainIdImmediately(provider) | ||
if (network !== chainId) { | ||
throw new Error( | ||
`Wallet chainId differs from app chainId. Wallet: ${network}, App: ${chainId}. Action: ${description}`, | ||
) | ||
} | ||
|
||
return network | ||
} |
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
Oops, something went wrong.