Skip to content

Commit 67281db

Browse files
committed
chainId is now hex string, not number
1 parent 0baf766 commit 67281db

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

app/core/RPCMethods/RPCMethodMiddleware.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
PermissionController,
1919
permissionRpcMethods,
2020
} from '@metamask/permission-controller';
21+
import type { Hex } from '@metamask/utils';
2122
import Networks, {
2223
blockTagParamIndex,
2324
getAllNetworks,
@@ -105,7 +106,7 @@ export const checkActiveAccountAndChainId = async ({
105106
isWalletConnect,
106107
}: {
107108
address?: string;
108-
chainId?: number;
109+
chainId?: Hex;
109110
channelId?: string;
110111
hostname: string;
111112
isWalletConnect: boolean;
@@ -218,7 +219,7 @@ const generateRawSignature = async ({
218219
title: { current: string };
219220
icon: { current: string | undefined };
220221
analytics: { [key: string]: string | boolean };
221-
chainId: number;
222+
chainId: Hex;
222223
isMMSDK: boolean;
223224
channelId?: string;
224225
getSource: () => string;
@@ -561,7 +562,7 @@ export const getRpcMethodMiddleware = ({
561562
chainId,
562563
}: {
563564
from?: string;
564-
chainId?: number;
565+
chainId?: Hex;
565566
}) => {
566567
await checkActiveAccountAndChainId({
567568
hostname,

app/core/WalletConnect/WalletConnectV2.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import Logger from '../../util/Logger';
1010
import { WalletDevice } from '@metamask/transaction-controller';
1111

1212
import { PermissionController } from '@metamask/permission-controller';
13+
import { isStrictHexString } from '@metamask/utils';
14+
import type { Hex } from '@metamask/utils';
1315
import { NavigationContainerRef } from '@react-navigation/native';
1416
import { Core } from '@walletconnect/core';
1517
import { ErrorResponse } from '@walletconnect/jsonrpc-types';
@@ -296,7 +298,7 @@ class WalletConnect2Session {
296298
chainId,
297299
accounts,
298300
}: {
299-
chainId: number;
301+
chainId: Hex;
300302
accounts: string[];
301303
}) => {
302304
try {
@@ -326,20 +328,20 @@ class WalletConnect2Session {
326328
return;
327329
}
328330
}
329-
if (chainId === 0) {
331+
if (!isStrictHexString(chainId) || chainId.toLowerCase() === '0x0') {
330332
DevLogger.log(
331333
`WC2::updateSession invalid chainId --- skip ${typeof chainId} chainId=${chainId} accounts=${accounts})`,
332334
);
333335
// overwrite chainId with actual value.
334-
const selectedChainId = parseInt(selectChainId(store.getState()));
336+
const selectedChainId = selectChainId(store.getState());
335337
DevLogger.log(
336338
`WC2::updateSession overwrite invalid chain Id with selectedChainId=${selectedChainId}`,
337339
);
338340
chainId = selectedChainId;
339341
}
340342
await this.web3Wallet.updateSession({
341343
topic: this.session.topic,
342-
chainId,
344+
chainId: parseInt(chainId, 16),
343345
accounts,
344346
});
345347
} catch (err) {
@@ -566,13 +568,12 @@ export class WC2Manager {
566568
DevLogger.log(`WC2::init approvedAccounts`, approvedAccounts);
567569
}
568570

569-
const nChainId = parseInt(chainId, 16);
570571
DevLogger.log(
571-
`WC2::init updateSession session=${sessionKey} chainId=${chainId} nChainId=${nChainId} selectedAddress=${selectedAddress}`,
572+
`WC2::init updateSession session=${sessionKey} chainId=${chainId} selectedAddress=${selectedAddress}`,
572573
approvedAccounts,
573574
);
574575
await this.sessions[sessionKey].updateSession({
575-
chainId: nChainId,
576+
chainId,
576577
accounts: approvedAccounts,
577578
});
578579
} catch (err) {

0 commit comments

Comments
 (0)