From f63ed94377de4d41c653a2f99ee6bc12f114a80a Mon Sep 17 00:00:00 2001 From: guanbinrui Date: Tue, 26 Nov 2024 22:21:43 +0800 Subject: [PATCH] fix: getter --- packages/web3-providers/src/Manager/index.ts | 23 +++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/web3-providers/src/Manager/index.ts b/packages/web3-providers/src/Manager/index.ts index 2ac2e5820f8e..fcb48dc19cb3 100644 --- a/packages/web3-providers/src/Manager/index.ts +++ b/packages/web3-providers/src/Manager/index.ts @@ -3,10 +3,17 @@ import type { Web3Helper } from '@masknet/web3-helpers' import { evm, solana } from './registry.js' export { initWallet } from './io.js' -const all = { - [NetworkPluginID.PLUGIN_EVM]: evm, - [NetworkPluginID.PLUGIN_SOLANA]: solana, -} as const + +function getRegistry(ID: NetworkPluginID) { + switch (ID) { + case NetworkPluginID.PLUGIN_EVM: + return evm + case NetworkPluginID.PLUGIN_SOLANA: + return solana + default: + throw new Error('Not supported network') + } +} /** * Get Web3 providers, for example, WalletConnect, MetaMask, etc. * @param ID Network name @@ -17,7 +24,7 @@ export function getRegisteredWeb3Providers( export function getRegisteredWeb3Providers( ID: NetworkPluginID, ): ReadonlyArray> { - return all[ID].provider + return getRegistry(ID).provider } /** @@ -30,13 +37,13 @@ export function getRegisteredWeb3Networks( export function getRegisteredWeb3Networks( ID: NetworkPluginID, ): ReadonlyArray> { - return all[ID].network + return getRegistry(ID).network } export function getRegisteredWeb3Chains( ID: T, ): ReadonlyArray> { - return all[ID].chain + return getRegistry(ID).chain } export function getAllPluginsWeb3State(): { [key in NetworkPluginID]: Web3Helper.Web3State @@ -49,5 +56,5 @@ export function getAllPluginsWeb3State(): { export function getActivatedPluginWeb3State(pluginID: T): Web3Helper.Web3State export function getActivatedPluginWeb3State(pluginID: NetworkPluginID): Web3Helper.Web3State { - return all[pluginID].state! + return getRegistry(pluginID).state! }