fix use await/promise for all the web3 call

pull/3654/head^2
yann300 1 year ago committed by Aniket
parent a4c630b2aa
commit 7072363364
  1. 12
      apps/remix-ide/src/blockchain/execution-context.js
  2. 14
      apps/remix-ide/src/blockchain/providers/injected.ts
  3. 2
      apps/remix-ide/src/blockchain/providers/vm.ts

@ -86,20 +86,16 @@ export class ExecutionContext {
else if (id === 11155111) name = 'Sepolia'
else name = 'Custom'
if (id === '1') {
web3.eth.getBlock(0, (error, block) => {
if (error) console.log('cant query first block')
if (id === 1) {
web3.eth.getBlock(0).then((block) => {
if (block && block.hash !== this.mainNetGenesisHash) name = 'Custom'
callback(err, { id, name, lastBlock: this.lastBlock, currentFork: this.currentFork })
})
}).catch((error) => callback(error))
} else {
callback(err, { id, name, lastBlock: this.lastBlock, currentFork: this.currentFork })
}
}
const res = web3.eth.net.getId(cb)
if(res && typeof res.then ==='function'){
res.then(id=>cb(null,id)).catch(err=>cb(err))
}
web3.eth.net.getId().then(id=>cb(null,parseInt(id))).catch(err=>cb(err))
}
}

@ -10,12 +10,16 @@ export class InjectedProvider {
}
getAccounts (cb) {
return this.executionContext.web3().eth.getAccounts(cb)
return this.executionContext.web3().eth.getAccounts()
.then(accounts => cb(null, accounts))
.catch(err => {
cb(err.message)
})
}
newAccount (passwordPromptCb, cb) {
passwordPromptCb((passphrase) => {
this.executionContext.web3().eth.personal.newAccount(passphrase, cb)
this.executionContext.web3().eth.personal.newAccount(passphrase).then((result) => cb(null, result)).catch(error => cb(error))
})
}
@ -29,16 +33,16 @@ export class InjectedProvider {
}
getGasPrice (cb) {
this.executionContext.web3().eth.getGasPrice(cb)
this.executionContext.web3().eth.getGasPrice().then((result => cb(null, result)))
}
signMessage (message, account, _passphrase, cb) {
const messageHash = hashPersonalMessage(Buffer.from(message))
try {
message = isHexString(message) ? message : Web3.utils.utf8ToHex(message)
this.executionContext.web3().eth.personal.sign(message, account, (error, signedData) => {
this.executionContext.web3().eth.personal.sign(message, account).then((error, signedData) => {
cb(error, '0x' + messageHash.toString('hex'), signedData)
})
}).catch((error => cb(error)))
} catch (e) {
cb(e.message)
}

@ -100,7 +100,7 @@ export class VMProvider {
}
getGasPrice (cb) {
this.web3.eth.getGasPrice(cb)
this.web3.eth.getGasPrice().then((result => cb(null, result))).catch((error) => cb(error))
}
signMessage (message, account, _passphrase, cb) {

Loading…
Cancel
Save