Merge branch 'master' into ppmm

pull/2826/head
Aniket 2 years ago committed by GitHub
commit 7200755262
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      apps/remix-ide/src/app/tabs/injected-provider.tsx
  2. 7
      apps/remix-ide/src/blockchain/execution-context.js

@ -18,7 +18,7 @@ export class InjectedProvider extends Plugin {
sendAsync (data: JsonDataRequest): Promise<any> { sendAsync (data: JsonDataRequest): Promise<any> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.sendAsyncInternal(data, resolve, reject) this.sendAsyncInternal(data, resolve, reject)
}) })
} }
@ -30,7 +30,7 @@ export class InjectedProvider extends Plugin {
return reject(new Error('no injected provider found.')) return reject(new Error('no injected provider found.'))
} }
try { try {
if ((window as any) && typeof (window as any).ethereum.enable === 'function') (window as any).ethereum.enable() if ((window as any) && typeof (window as any).ethereum.request === "function") (window as any).ethereum.request({ method: "eth_requestAccounts" });
if (!await (window as any).ethereum._metamask.isUnlocked()) this.call('notification', 'toast', 'Please make sure the injected provider is unlocked (e.g Metamask).') if (!await (window as any).ethereum._metamask.isUnlocked()) this.call('notification', 'toast', 'Please make sure the injected provider is unlocked (e.g Metamask).')
await addL2Network(this.chainName, this.chainId, this.rpcUrls) await addL2Network(this.chainName, this.chainId, this.rpcUrls)
const resultData = await this.provider.currentProvider.send(data.method, data.params) const resultData = await this.provider.currentProvider.send(data.method, data.params)
@ -61,7 +61,7 @@ export const addL2Network = async (chainName: string, chainId: string, rpcUrls:
}, },
], ],
}); });
await (window as any).ethereum.request({ await (window as any).ethereum.request({
method: 'wallet_switchEthereumChain', method: 'wallet_switchEthereumChain',
params: [{ chainId: chainId }], params: [{ chainId: chainId }],
@ -71,5 +71,5 @@ export const addL2Network = async (chainName: string, chainId: string, rpcUrls:
} }
} }
// handle other "switch" errors // handle other "switch" errors
} }
} }

@ -43,8 +43,7 @@ export class ExecutionContext {
} }
askPermission () { askPermission () {
// metamask if (ethereum && typeof ethereum.request === "function") ethereum.request({ method: "eth_requestAccounts" });
if (ethereum && typeof ethereum.enable === 'function') ethereum.enable()
} }
getProvider () { getProvider () {
@ -169,7 +168,7 @@ export class ExecutionContext {
if (this.customNetWorks[context]) { if (this.customNetWorks[context]) {
var network = this.customNetWorks[context] var network = this.customNetWorks[context]
if (!this.customNetWorks[context].isInjected) { if (!this.customNetWorks[context].isInjected) {
this.setProviderFromEndpoint(network.provider, { context: network.name }, (error) => { this.setProviderFromEndpoint(network.provider, { context: network.name }, (error) => {
if (error) infoCb(error) if (error) infoCb(error)
cb() cb()
@ -183,7 +182,7 @@ export class ExecutionContext {
this.event.trigger('contextChanged', [context]) this.event.trigger('contextChanged', [context])
return cb() return cb()
} }
} }
} }
currentblockGasLimit () { currentblockGasLimit () {

Loading…
Cancel
Save