From 1782af6b3472b7f999a45f23ca9cead77dfb05e1 Mon Sep 17 00:00:00 2001 From: guanbinrui Date: Wed, 13 Jul 2022 23:36:01 +0800 Subject: [PATCH 1/2] refactor: add pluginID into context --- packages/plugin-infra/src/web3/Context.tsx | 10 +++- .../SNSAdaptor/components/ConsoleContent.tsx | 50 ++++++++++++++++++- .../SNSAdaptor/components/ConsoleDialog.tsx | 13 ++++- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/packages/plugin-infra/src/web3/Context.tsx b/packages/plugin-infra/src/web3/Context.tsx index b12bf58f86bf..cf63c8e9b04b 100644 --- a/packages/plugin-infra/src/web3/Context.tsx +++ b/packages/plugin-infra/src/web3/Context.tsx @@ -16,10 +16,16 @@ const PluginWeb3Context = createContext>(EMPTY_OBJE const PluginsWeb3Context = createContext>>(null!) +export function PluginIDContextProvider({ value, children }: React.ProviderProps) { + return {children} +} + export function PluginWeb3ContextProvider({ pluginID, + value, + children, }: { pluginID: T } & React.ProviderProps>) { - return + return } export function PluginsWeb3ContextProvider({ @@ -30,7 +36,7 @@ export function PluginsWeb3ContextProvider({ return ( - {children} + ) diff --git a/packages/plugins/Debugger/src/SNSAdaptor/components/ConsoleContent.tsx b/packages/plugins/Debugger/src/SNSAdaptor/components/ConsoleContent.tsx index 39fc5a22876d..4e6942c1aec4 100644 --- a/packages/plugins/Debugger/src/SNSAdaptor/components/ConsoleContent.tsx +++ b/packages/plugins/Debugger/src/SNSAdaptor/components/ConsoleContent.tsx @@ -5,7 +5,10 @@ import { useBlockNumber, useBlockTimestamp, useChainId, + useCurrentWeb3NetworkChainId, useCurrentWeb3NetworkPluginID, + useNetworkType, + useProviderType, useWeb3Connection, useWeb3Hub, useWeb3State, @@ -49,7 +52,6 @@ const useStyles = makeStyles()({ }) export function ConsoleContent(props: ConsoleContentProps) { - const { onClose } = props const { classes } = useStyles() const { NATIVE_TOKEN_ADDRESS } = useTokenConstants() const pluginID = useCurrentWeb3NetworkPluginID() @@ -58,6 +60,9 @@ export function ConsoleContent(props: ConsoleContentProps) { const hub = useWeb3Hub() const account = useAccount() const chainId = useChainId() + const networkType = useNetworkType() + const providerType = useProviderType() + const chainIdContext = useCurrentWeb3NetworkChainId() const { value: balance = '0' } = useBalance() const { value: blockNumber = 0 } = useBlockNumber() const { value: blockTimestamp = 0 } = useBlockTimestamp() @@ -70,6 +75,9 @@ export function ConsoleContent(props: ConsoleContentProps) { ) }, [connection]) + console.log('DEBUG: context') + console.log(chainIdContext) + const onSignMessage = useCallback( async (type?: string) => { const message = 'Hello World' @@ -156,6 +164,46 @@ export function ConsoleContent(props: ConsoleContentProps) {
+ + + + ChainId + + + + {chainId} + + + + + + PluginID + + + + {pluginID} + + + + + + Network Type + + + + {networkType} + + + + + + Provider Type + + + + {providerType} + + diff --git a/packages/plugins/Debugger/src/SNSAdaptor/components/ConsoleDialog.tsx b/packages/plugins/Debugger/src/SNSAdaptor/components/ConsoleDialog.tsx index d6019d2d64d2..03e0cc89eb37 100644 --- a/packages/plugins/Debugger/src/SNSAdaptor/components/ConsoleDialog.tsx +++ b/packages/plugins/Debugger/src/SNSAdaptor/components/ConsoleDialog.tsx @@ -1,5 +1,8 @@ import { InjectedDialog } from '@masknet/shared' import { DialogContent } from '@mui/material' +import { ChainId } from '@masknet/web3-shared-evm' +import { NetworkPluginID } from '@masknet/web3-shared-base' +import { PluginIDContextProvider, PluginWeb3ContextProvider } from '@masknet/plugin-infra/web3' import { ConsoleContent } from './ConsoleContent' import { useRemoteControlledDialog } from '../../../../../shared-base-ui/src/hooks' import { PluginDebuggerMessages } from '../../messages' @@ -11,7 +14,15 @@ export function ConsoleDialog(props: ConsoleDialogProps) { return ( - + + + + + ) From 0773b09cfe380ef39fa62886da504b8de1ca70d6 Mon Sep 17 00:00:00 2001 From: guanbinrui <52657989+guanbinrui@users.noreply.github.com> Date: Thu, 14 Jul 2022 00:31:09 +0800 Subject: [PATCH 2/2] refactor: remove logs --- .../Debugger/src/SNSAdaptor/components/ConsoleContent.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/plugins/Debugger/src/SNSAdaptor/components/ConsoleContent.tsx b/packages/plugins/Debugger/src/SNSAdaptor/components/ConsoleContent.tsx index 4e6942c1aec4..c29ac763f68a 100644 --- a/packages/plugins/Debugger/src/SNSAdaptor/components/ConsoleContent.tsx +++ b/packages/plugins/Debugger/src/SNSAdaptor/components/ConsoleContent.tsx @@ -75,9 +75,6 @@ export function ConsoleContent(props: ConsoleContentProps) { ) }, [connection]) - console.log('DEBUG: context') - console.log(chainIdContext) - const onSignMessage = useCallback( async (type?: string) => { const message = 'Hello World'