Skip to content

Commit 6676465

Browse files
add from viem chain method
1 parent 827d490 commit 6676465

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

packages/no-modal/src/base/utils.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { cloneDeep } from "@toruslabs/base-controllers";
1+
import { CHAIN_NAMESPACES, cloneDeep } from "@toruslabs/base-controllers";
22
import { SIGNER_MAP } from "@toruslabs/constants";
33
import { get } from "@toruslabs/http-helpers";
4+
import { type Chain } from "viem";
45

6+
import { CustomChainConfig } from "./chain/IChainInterface";
57
import { WEB3AUTH_NETWORK, type WEB3AUTH_NETWORK_TYPE } from "./connector";
68
import type { ProjectConfig, WalletRegistry } from "./interfaces";
79

@@ -50,4 +52,22 @@ export const normalizeWalletName = (name: string) => {
5052
return normalizedName;
5153
};
5254

55+
export const fromWagmiChain = (chain: Chain): CustomChainConfig => {
56+
return {
57+
chainNamespace: CHAIN_NAMESPACES.EIP155,
58+
chainId: `0x${chain.id.toString(16)}`,
59+
rpcTarget: chain.rpcUrls.default.http[0],
60+
displayName: chain.name,
61+
blockExplorerUrl: chain.blockExplorers?.default.url || "",
62+
ticker: chain.nativeCurrency.symbol,
63+
tickerName: chain.nativeCurrency.name,
64+
logo: "",
65+
decimals: chain.nativeCurrency.decimals,
66+
isTestnet: chain.testnet,
67+
wsTarget: chain.rpcUrls.default.webSocket?.[0],
68+
};
69+
};
70+
71+
export const fromViemChain = fromWagmiChain;
72+
5373
export { cloneDeep };

0 commit comments

Comments
 (0)