-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle switch ethereum chain (#2676)
* feat: handle switch ethereum chain * Update packages/shared/src/lib/auxiliary/wallet-connect/handlers/wallet_switchEthereumChain.handler.ts Co-authored-by: Mark Nardi <[email protected]> --------- Co-authored-by: Mark Nardi <[email protected]>
- Loading branch information
1 parent
425fbd2
commit a22001e
Showing
5 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...s/shared/src/lib/auxiliary/wallet-connect/constants/general-supported-methods.constant.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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { RpcMethod } from '../enums' | ||
|
||
export const GENERAL_SUPPORTED_METHODS = [RpcMethod.WalletWatchAsset] | ||
export const GENERAL_SUPPORTED_METHODS = [RpcMethod.WalletWatchAsset, RpcMethod.WalletSwitchEthereumChain] |
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
29 changes: 29 additions & 0 deletions
29
...es/shared/src/lib/auxiliary/wallet-connect/handlers/wallet_switchEthereumChain.handler.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,29 @@ | ||
import { WCRequestInfo } from '@auxiliary/wallet-connect/types' | ||
import { getEvmNetworks } from '@core/network' | ||
import { Converter } from '@core/utils' | ||
import { getSdkError } from '@walletconnect/utils' | ||
|
||
type WalletSwitchEthereumChain = [ | ||
{ | ||
chainId: `0x${string}` | ||
}, | ||
] | ||
|
||
export function handleWalletSwitchEthereumChain(params: WalletSwitchEthereumChain, requestInfo: WCRequestInfo): void { | ||
const { responseCallback } = requestInfo | ||
|
||
const hexChainId = params[0]?.chainId | ||
if (!hexChainId) { | ||
responseCallback({ error: getSdkError('INVALID_METHOD') }) | ||
return | ||
} | ||
|
||
const chainId = Converter.hexToDecimal(hexChainId) | ||
|
||
const isSupportedEvmChain = getEvmNetworks().some((network) => Number(network.chainId) === chainId) | ||
if (isSupportedEvmChain) { | ||
responseCallback({ result: chainId }) | ||
} else { | ||
responseCallback({ error: getSdkError('UNSUPPORTED_CHAINS') }) | ||
} | ||
} |