Skip to content

Commit de96b52

Browse files
authored
Merge pull request #2038 from ethereum/fix-import
Reset selected account when account changes on injectedWeb3.
2 parents ef53d54 + 633291a commit de96b52

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

apps/remix-ide/src/blockchain/blockchain.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ export class Blockchain extends Plugin {
226226
return this.executionContext.getProvider()
227227
}
228228

229+
getInjectedWeb3Address () {
230+
return this.executionContext.getSelectedAddress()
231+
}
232+
229233
/**
230234
* return the fork name applied to the current envionment
231235
* @return {String} - fork name

apps/remix-ide/src/blockchain/execution-context.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export class ExecutionContext {
5050
return this.executionContext
5151
}
5252

53+
getSelectedAddress () {
54+
return injectedProvider ? injectedProvider.selectedAddress : null
55+
}
56+
5357
getCurrentFork () {
5458
return this.currentFork
5559
}

libs/remix-ui/run-tab/src/lib/actions/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ const fillAccountsList = async () => {
145145
})
146146
})
147147
}))
148+
const provider = plugin.blockchain.getProvider()
149+
150+
if (provider === 'injected') {
151+
const selectedAddress = plugin.blockchain.getInjectedWeb3Address()
152+
153+
if (!(Object.keys(loadedAccounts).includes(selectedAddress))) setAccount(null)
154+
}
148155
dispatch(fetchAccountsListSuccess(loadedAccounts))
149156
}).catch((e) => {
150157
dispatch(fetchAccountsListFailed(e.message))

libs/remix-ui/run-tab/src/lib/types/blockchain.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class Blockchain extends Plugin<any, any> {
3737
setProviderFromEndpoint(target: any, context: any, cb: any): void;
3838
detectNetwork(cb: any): void;
3939
getProvider(): any;
40+
getInjectedWeb3Address(): any;
4041
/**
4142
* return the fork name applied to the current envionment
4243
* @return {String} - fork name

0 commit comments

Comments
 (0)