diff --git a/apps/remix-ide/src/blockchain/blockchain.js b/apps/remix-ide/src/blockchain/blockchain.js index a747ba0f31..d3bc4e60ce 100644 --- a/apps/remix-ide/src/blockchain/blockchain.js +++ b/apps/remix-ide/src/blockchain/blockchain.js @@ -226,6 +226,10 @@ export class Blockchain extends Plugin { return this.executionContext.getProvider() } + getInjectedWeb3Address () { + return this.executionContext.getSelectedAddress() + } + /** * return the fork name applied to the current envionment * @return {String} - fork name diff --git a/apps/remix-ide/src/blockchain/execution-context.js b/apps/remix-ide/src/blockchain/execution-context.js index 67a3f1f28c..54e738b245 100644 --- a/apps/remix-ide/src/blockchain/execution-context.js +++ b/apps/remix-ide/src/blockchain/execution-context.js @@ -50,6 +50,10 @@ export class ExecutionContext { return this.executionContext } + getSelectedAddress () { + return injectedProvider ? injectedProvider.selectedAddress : null + } + getCurrentFork () { return this.currentFork } diff --git a/libs/remix-ui/run-tab/src/lib/actions/index.ts b/libs/remix-ui/run-tab/src/lib/actions/index.ts index 25bbb89d93..49c0bbedbc 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/index.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/index.ts @@ -145,6 +145,13 @@ const fillAccountsList = async () => { }) }) })) + const provider = plugin.blockchain.getProvider() + + if (provider === 'injected') { + const selectedAddress = plugin.blockchain.getInjectedWeb3Address() + + if (!(Object.keys(loadedAccounts).includes(selectedAddress))) setAccount(null) + } dispatch(fetchAccountsListSuccess(loadedAccounts)) }).catch((e) => { dispatch(fetchAccountsListFailed(e.message)) diff --git a/libs/remix-ui/run-tab/src/lib/types/blockchain.d.ts b/libs/remix-ui/run-tab/src/lib/types/blockchain.d.ts index 406459b1a0..1b2f7d442d 100644 --- a/libs/remix-ui/run-tab/src/lib/types/blockchain.d.ts +++ b/libs/remix-ui/run-tab/src/lib/types/blockchain.d.ts @@ -37,6 +37,7 @@ export class Blockchain extends Plugin { setProviderFromEndpoint(target: any, context: any, cb: any): void; detectNetwork(cb: any): void; getProvider(): any; + getInjectedWeb3Address(): any; /** * return the fork name applied to the current envionment * @return {String} - fork name