-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bridge-ui): Chain id check (#13451)
- Loading branch information
1 parent
31ad254
commit 7285947
Showing
4 changed files
with
53 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { ethers } from 'ethers'; | ||
import { chains } from '../chain/chains'; | ||
import { tokenVaults } from '../vault/tokenVaults'; | ||
|
||
export async function isOnCorrectChain( | ||
signer: ethers.Signer, | ||
wantChain: number, | ||
) { | ||
const signerChain = await signer.getChainId(); | ||
if (signerChain !== wantChain) { | ||
return false; | ||
} | ||
|
||
const bridgeAddress = chains[wantChain].bridgeAddress; | ||
const tokenVaultAddress = tokenVaults[wantChain]; | ||
|
||
const bridgeAddressCode = await signer.provider.getCode(bridgeAddress); | ||
|
||
const tokenVaultAddressCode = await signer.provider.getCode( | ||
tokenVaultAddress, | ||
); | ||
|
||
if (bridgeAddressCode === '0x' || tokenVaultAddressCode === '0x') { | ||
return false; | ||
} | ||
|
||
return true; | ||
} |