Skip to content

Commit

Permalink
fix: getter
Browse files Browse the repository at this point in the history
  • Loading branch information
guanbinrui committed Nov 26, 2024
1 parent f741a30 commit f63ed94
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions packages/web3-providers/src/Manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,7 +24,7 @@ export function getRegisteredWeb3Providers<T extends NetworkPluginID>(
export function getRegisteredWeb3Providers(
ID: NetworkPluginID,
): ReadonlyArray<Web3Helper.Web3ProviderDescriptor<NetworkPluginID>> {
return all[ID].provider
return getRegistry(ID).provider
}

/**
Expand All @@ -30,13 +37,13 @@ export function getRegisteredWeb3Networks<T extends NetworkPluginID>(
export function getRegisteredWeb3Networks(
ID: NetworkPluginID,
): ReadonlyArray<Web3Helper.Web3NetworkDescriptor<NetworkPluginID>> {
return all[ID].network
return getRegistry(ID).network
}

export function getRegisteredWeb3Chains<T extends NetworkPluginID>(
ID: T,
): ReadonlyArray<Web3Helper.ChainDescriptorScope<void, T>> {
return all[ID].chain
return getRegistry(ID).chain
}
export function getAllPluginsWeb3State(): {
[key in NetworkPluginID]: Web3Helper.Web3State<key>
Expand All @@ -49,5 +56,5 @@ export function getAllPluginsWeb3State(): {

export function getActivatedPluginWeb3State<T extends NetworkPluginID>(pluginID: T): Web3Helper.Web3State<T>
export function getActivatedPluginWeb3State(pluginID: NetworkPluginID): Web3Helper.Web3State<NetworkPluginID> {
return all[pluginID].state!
return getRegistry(pluginID).state!
}

0 comments on commit f63ed94

Please sign in to comment.