-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: useProviderDescriptor * fix: build error
- Loading branch information
1 parent
eecaa21
commit 71afec7
Showing
6 changed files
with
28 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
import { useMemo } from 'react' | ||
import { getPluginDefine } from '@masknet/plugin-infra' | ||
import type { NetworkPluginID } from '@masknet/shared-base' | ||
import type { Web3Helper } from '@masknet/web3-helpers' | ||
import { useChainContext, useNetworkContext } from './useContext.js' | ||
|
||
/** | ||
* Get built in declared provider descriptor | ||
* @param expectedPluginID | ||
* @param expectedProviderTypeOrID | ||
* @returns | ||
*/ | ||
export function useProviderDescriptor<S extends 'all' | void = void, T extends NetworkPluginID = NetworkPluginID>( | ||
expectedPluginID?: T, | ||
expectedProviderTypeOrID?: string, | ||
): Web3Helper.ProviderDescriptorScope<S, T> { | ||
): Web3Helper.ProviderDescriptorScope<S, T> | undefined { | ||
const { pluginID } = useNetworkContext(expectedPluginID) | ||
const { providerType } = useChainContext() | ||
|
||
const typeOrId = expectedProviderTypeOrID ?? providerType ?? '' | ||
return useMemo(() => { | ||
return getPluginDefine(pluginID)?.declareWeb3Providers?.find((x) => | ||
[x.type, x.ID].includes(typeOrId), | ||
) as Web3Helper.ProviderDescriptorScope<S, T> | ||
}, [pluginID, typeOrId]) | ||
return getPluginDefine(pluginID)?.declareWeb3Providers?.find((x) => | ||
[x.type, x.ID].includes(expectedProviderTypeOrID ?? providerType ?? ''), | ||
) as Web3Helper.ProviderDescriptorScope<S, T> | undefined | ||
} |