|
1 | | -import { cloneDeep } from "@toruslabs/base-controllers"; |
| 1 | +import { CHAIN_NAMESPACES, cloneDeep } from "@toruslabs/base-controllers"; |
2 | 2 | import { SIGNER_MAP } from "@toruslabs/constants"; |
3 | 3 | import { get } from "@toruslabs/http-helpers"; |
| 4 | +import { type Chain } from "viem"; |
4 | 5 |
|
| 6 | +import { CustomChainConfig } from "./chain/IChainInterface"; |
5 | 7 | import { WEB3AUTH_NETWORK, type WEB3AUTH_NETWORK_TYPE } from "./connector"; |
6 | 8 | import type { ProjectConfig, WalletRegistry } from "./interfaces"; |
7 | 9 |
|
@@ -50,4 +52,22 @@ export const normalizeWalletName = (name: string) => { |
50 | 52 | return normalizedName; |
51 | 53 | }; |
52 | 54 |
|
| 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 | + |
53 | 73 | export { cloneDeep }; |
0 commit comments