-
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: mf-4941 specify provider url (#10424)
* fix: mf-4941 specify provider url * refactor: code style (#10432) * fix: markdownlint --------- Co-authored-by: guanbinrui <52657989+guanbinrui@users.noreply.github.com> Co-authored-by: guanbinrui <guanbinrui@users.noreply.github.com>
- Loading branch information
1 parent
2bcf3d1
commit 1553075
Showing
9 changed files
with
70 additions
and
28 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,15 +1,20 @@ | ||
import { useMemo } from 'react' | ||
import { useSubscription } from 'use-subscription' | ||
import type { Web3Helper } from '@masknet/web3-helpers' | ||
import { EMPTY_STRING, type NetworkPluginID } from '@masknet/shared-base' | ||
import { useWeb3State } from './useWeb3State.js' | ||
import { useNetworks } from './useNetworks.js' | ||
|
||
export function useNetwork<T extends NetworkPluginID = NetworkPluginID>(pluginID?: T) { | ||
export function useNetwork<T extends NetworkPluginID = NetworkPluginID>( | ||
pluginID?: T, | ||
chainId?: Web3Helper.Definition[T]['ChainId'], | ||
) { | ||
const { Network } = useWeb3State(pluginID) | ||
const networks = useNetworks(pluginID) | ||
const networkID = useSubscription(Network?.networkID ?? EMPTY_STRING) | ||
|
||
return useMemo(() => { | ||
if (chainId) return networks.find((x) => x.chainId === chainId) | ||
return networks.find((x) => x.ID === networkID) | ||
}, [networks, networkID]) | ||
}, [chainId, networkID, networks]) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useMemo } from 'react' | ||
import { useSubscription } from 'use-subscription' | ||
import { EMPTY_STRING, type NetworkPluginID } from '@masknet/shared-base' | ||
import { useWeb3State } from './useWeb3State.js' | ||
import { useNetworks } from './useNetworks.js' | ||
import type { Web3Helper } from '@masknet/web3-helpers' | ||
|
||
export function useNetworkBy<T extends NetworkPluginID = NetworkPluginID>( | ||
pluginID?: T, | ||
chainId?: Web3Helper.ChainIdScope<void, T>, | ||
) { | ||
const { Network } = useWeb3State(pluginID) | ||
const networks = useNetworks(pluginID) | ||
const networkID = useSubscription(Network?.networkID ?? EMPTY_STRING) | ||
|
||
return useMemo(() => { | ||
if (chainId) return networks.find((x) => x.chainId === chainId) | ||
return networks.find((x) => x.ID === networkID) | ||
}, [networks, networkID, chainId]) | ||
} |
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