diff --git a/apps/debugger/src/app/debugger-api.ts b/apps/debugger/src/app/debugger-api.ts index 2b5a149d16..ae75599bec 100644 --- a/apps/debugger/src/app/debugger-api.ts +++ b/apps/debugger/src/app/debugger-api.ts @@ -62,6 +62,10 @@ export const DebuggerApiMixin = (Base) => class extends Base { this.onEditorContentChangedListener = listener } + onEnvChanged (listener) { + this.onEnvChangedListener = listener + } + onDebugRequested (listener) { this.onDebugRequestedListener = listener } @@ -126,6 +130,7 @@ export const DebuggerApiMixin = (Base) => class extends Base { this.on('editor', 'breakpointCleared', (fileName, row) => { if (this.onBreakpointClearedListener) this.onBreakpointClearedListener(fileName, row) }) this.on('editor', 'breakpointAdded', (fileName, row) => { if (this.onBreakpointAddedListener) this.onBreakpointAddedListener(fileName, row) }) this.on('editor', 'contentChanged', () => { if (this.onEditorContentChangedListener) this.onEditorContentChangedListener() }) + this.on('network', 'providerChanged', (provider) => { if (this.onEnvChangedListener) this.onEnvChangedListener(provider) }) } onDeactivation () { diff --git a/apps/debugger/src/app/debugger.ts b/apps/debugger/src/app/debugger.ts index 95712fb2ac..6255a52205 100644 --- a/apps/debugger/src/app/debugger.ts +++ b/apps/debugger/src/app/debugger.ts @@ -1,7 +1,7 @@ import { PluginClient } from "@remixproject/plugin"; import { createClient } from "@remixproject/plugin-webview"; import { IDebuggerApi, RawLocation, Sources, Asts, LineColumnLocation, - onBreakpointClearedListener, onBreakpointAddedListener, onEditorContentChanged, TransactionReceipt } from '@remix-ui/debugger-ui' + onBreakpointClearedListener, onBreakpointAddedListener, onEditorContentChanged, onEnvChangedListener, TransactionReceipt } from '@remix-ui/debugger-ui' import { DebuggerApiMixin, CompilerAbstract} from './debugger-api' export class DebuggerClientApi extends DebuggerApiMixin(PluginClient) { @@ -18,6 +18,7 @@ export class DebuggerClientApi extends DebuggerApiMixin(PluginClient) { onBreakpointCleared: (listener: onBreakpointClearedListener) => void onBreakpointAdded: (listener: onBreakpointAddedListener) => void onEditorContentChanged: (listener: onEditorContentChanged) => void + onEnvChanged: (listener: onEnvChangedListener) => void discardHighlight: () => Promise highlight: (lineColumnPos: LineColumnLocation, path: string) => Promise fetchContractAndCompile: (address: string, currentReceipt: TransactionReceipt) => Promise diff --git a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx index 0def604fdc..e79ad8910c 100644 --- a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx @@ -31,7 +31,8 @@ export const DebuggerUI = (props: DebuggerUIProps) => { }, toastMessage: '', validationError: '', - txNumberIsEmpty: true + txNumberIsEmpty: true, + isLocalNodeUsed: false }) useEffect(() => { @@ -62,6 +63,17 @@ export const DebuggerUI = (props: DebuggerUIProps) => { } setEditor() + + const providerChanged = () => { + debuggerModule.onEnvChanged((provider) => { + setState(prevState => { + const isLocalNodeUsed = provider !== 'vm' && provider !== 'injected' + return { ...prevState, isLocalNodeUsed: isLocalNodeUsed } + }) + }) + } + + providerChanged() }, [state.debugger]) const listenToEvents = (debuggerInstance, currentReceipt) => { @@ -289,7 +301,7 @@ export const DebuggerUI = (props: DebuggerUIProps) => { }} type="checkbox" title="Debug with generated sources" /> -
+ { state.isLocalNodeUsed &&
{ setState(prevState => { return { ...prevState, opt: { ...prevState.opt, debugWithLocalNode: checked } } @@ -297,6 +309,7 @@ export const DebuggerUI = (props: DebuggerUIProps) => { }} type="checkbox" title="Force the debugger to use the current local node" />
+ } { state.validationError && {state.validationError} }
diff --git a/libs/remix-ui/debugger-ui/src/lib/idebugger-api.ts b/libs/remix-ui/debugger-ui/src/lib/idebugger-api.ts index 4e31ce7360..2e57aff5a6 100644 --- a/libs/remix-ui/debugger-ui/src/lib/idebugger-api.ts +++ b/libs/remix-ui/debugger-ui/src/lib/idebugger-api.ts @@ -46,6 +46,7 @@ export type onBreakpointClearedListener = (params: string, row: number) => void export type onBreakpointAddedListener = (params: string, row: number) => void export type onEditorContentChanged = () => void export type onDebugRequested = (hash: string) => void +export type onEnvChangedListener = (provider: string) => void export interface IDebuggerApi { offsetToLineColumnConverter: { offsetToLineColumn: (sourceLocation: RawLocation, file: number, contents: Sources, asts: Asts) => Promise } @@ -57,6 +58,7 @@ export interface IDebuggerApi { onBreakpointCleared: (listener: onBreakpointClearedListener) => void onBreakpointAdded: (listener: onBreakpointAddedListener) => void onEditorContentChanged: (listener: onEditorContentChanged) => void + onEnvChanged: (listener: onEnvChangedListener) => void discardHighlight: () => Promise highlight: (lineColumnPos: LineColumnLocation, path: string) => Promise fetchContractAndCompile: (address: string, currentReceipt: TransactionReceipt) => Promise