pull/3951/head
Oleksii Kosynskyi 2 years ago
parent 7177b10b2d
commit 36c72f54f2
No known key found for this signature in database
GPG Key ID: B4A8D3CCE22EA65E
  1. 12
      apps/remix-ide/src/blockchain/providers/injected.ts
  2. 19
      apps/remix-ide/src/blockchain/providers/vm.ts

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

@ -1,5 +1,5 @@
import Web3, { LegacySendAsyncProvider } from 'web3'
import { fromWei } from 'web3-utils'
import Web3, { FMT_BYTES, FMT_NUMBER, LegacySendAsyncProvider } from 'web3'
import { fromWei, toBigInt } from 'web3-utils'
import { privateToAddress, hashPersonalMessage } from '@ethereumjs/util'
import { extend, JSONRPCRequestPayload, JSONRPCResponseCallback } from '@remix-project/remix-simulator'
import { ExecutionContext } from '../execution-context'
@ -22,7 +22,12 @@ export class VMProvider {
}
getAccounts (cb) {
this.web3.eth.getAccounts().then(accounts => cb(null, accounts)).catch(err => cb('No accounts?'))
this.web3.eth.getAccounts()
.then(accounts => cb(null, accounts))
.catch(err => {
console.log('err',err)
cb('No accounts?')
})
}
async resetEnvironment () {
@ -41,6 +46,8 @@ export class VMProvider {
if (!msg.data.error) {
this.provider = {
sendAsync: (query, callback) => {
console.log('query',query)
console.log('callback',callback)
const stamp = Date.now() + incr
incr++
stamps[stamp] = callback
@ -81,12 +88,12 @@ export class VMProvider {
}
async getBalanceInEther (address) {
const balance = await this.web3.eth.getBalance(address)
return fromWei(balance.toString(10), 'ether')
const balance = await this.web3.eth.getBalance(address, undefined, { number: FMT_NUMBER.HEX, bytes: FMT_BYTES.HEX })
return fromWei(toBigInt(balance).toString(10), 'ether')
}
getGasPrice (cb) {
this.web3.eth.getGasPrice().then(res => cb(null, res)).catch(err => cb(err))
this.web3.eth.getGasPrice(cb)
}
signMessage (message, account, _passphrase, cb) {

Loading…
Cancel
Save