use await for getBalance()

pull/5370/head
yann300 2 years ago
parent cb320747fb
commit bfc1ee1b9a
  1. 4
      apps/remix-ide/src/blockchain/blockchain.js
  2. 10
      apps/remix-ide/src/blockchain/providers/injected.js
  3. 10
      apps/remix-ide/src/blockchain/providers/node.js
  4. 10
      apps/remix-ide/src/blockchain/providers/vm.js
  5. 30
      libs/remix-ui/run-tab/src/lib/actions/account.ts
  6. 16
      libs/remix-ui/run-tab/src/lib/actions/deploy.ts
  7. 2
      libs/remix-ui/run-tab/src/lib/types/blockchain.d.ts
  8. 2
      libs/remix-ui/run-tab/src/lib/types/injected.d.ts
  9. 2
      libs/remix-ui/run-tab/src/lib/types/node.d.ts
  10. 2
      libs/remix-ui/run-tab/src/lib/types/vm.d.ts

@ -567,8 +567,8 @@ export class Blockchain extends Plugin {
}
/** Get the balance of an address, and convert wei to ether */
getBalanceInEther (address, cb) {
this.getCurrentProvider().getBalanceInEther(address, cb)
getBalanceInEther (address) {
return this.getCurrentProvider().getBalanceInEther(address)
}
pendingTransactionsCount () {

@ -20,13 +20,9 @@ class InjectedProvider {
/* Do nothing. */
}
getBalanceInEther (address, cb) {
this.executionContext.web3().eth.getBalance(address, (err, res) => {
if (err) {
return cb(err)
}
cb(null, Web3.utils.fromWei(res.toString(10), 'ether'))
})
async getBalanceInEther (address) {
const balance = await this.executionContext.web3().eth.getBalance(address)
return Web3.utils.fromWei(balance.toString(10), 'ether')
}
getGasPrice (cb) {

@ -28,13 +28,9 @@ class NodeProvider {
/* Do nothing. */
}
getBalanceInEther (address, cb) {
this.executionContext.web3().eth.getBalance(address, (err, res) => {
if (err) {
return cb(err)
}
cb(null, Web3.utils.fromWei(res.toString(10), 'ether'))
})
async getBalanceInEther (address) {
const balance = await this.executionContext.web3().eth.getBalance(address)
return Web3.utils.fromWei(balance.toString(10), 'ether')
}
getGasPrice (cb) {

@ -68,13 +68,9 @@ class VMProvider {
this.RemixSimulatorProvider.Accounts.newAccount(cb)
}
getBalanceInEther (address, cb) {
this.web3.eth.getBalance(address, (err, res) => {
if (err) {
return cb(err)
}
cb(null, Web3.utils.fromWei(new BN(res).toString(10), 'ether'))
})
async getBalanceInEther (address) {
const balance = await this.web3.eth.getBalance(address)
return Web3.utils.fromWei(new BN(balance).toString(10), 'ether')
}
getGasPrice (cb) {

@ -3,17 +3,14 @@ import { RunTab } from "../types/run-tab"
import { clearInstances, setAccount, setExecEnv } from "./actions"
import { displayNotification, displayPopUp, fetchAccountsListFailed, fetchAccountsListRequest, fetchAccountsListSuccess, setExternalEndpoint, setMatchPassphrase, setPassphrase } from "./payload"
export const updateAccountBalances = (plugin: RunTab, dispatch: React.Dispatch<any>) => {
export const updateAccountBalances = async (plugin: RunTab, dispatch: React.Dispatch<any>) => {
const accounts = plugin.REACT_API.accounts.loadedAccounts
Object.keys(accounts).map((value) => {
plugin.blockchain.getBalanceInEther(value, (err, balance) => {
if (err) return
const updated = shortenAddress(value, balance)
accounts[value] = updated
})
})
for (const account of Object.keys(accounts)) {
const balance = await plugin.blockchain.getBalanceInEther(account)
const updated = shortenAddress(account, balance)
accounts[account] = updated
}
dispatch(fetchAccountsListSuccess(accounts))
}
@ -31,17 +28,10 @@ export const fillAccountsList = async (plugin: RunTab, dispatch: React.Dispatch<
// - all the promises resolve
// - at least one reject
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
await (Promise as any).all(accounts.map((account) => {
return new Promise((resolve, reject) => {
plugin.blockchain.getBalanceInEther(account, (err, balance) => {
if (err) return reject(err)
const updated = shortenAddress(account, balance)
loadedAccounts[account] = updated
resolve(account)
})
})
}))
for (const account of accounts) {
const balance = await plugin.blockchain.getBalanceInEther(account)
loadedAccounts[account] = shortenAddress(account, balance)
}
const provider = plugin.blockchain.getProvider()
if (provider === 'injected') {

@ -6,7 +6,7 @@ import { SolcInput, SolcOutput } from "@openzeppelin/upgrades-core"
// Used direct path to UpgradeableContract class to fix cyclic dependency error from @openzeppelin/upgrades-core library
import { UpgradeableContract } from '../../../../../../node_modules/@openzeppelin/upgrades-core/dist/standalone'
import { DeployMode, MainnetPrompt } from "../types"
import { displayNotification, displayPopUp, fetchProxyDeploymentsSuccess, setDecodedResponse } from "./payload"
import { displayNotification, displayPopUp, fetchProxyDeploymentsSuccess, setDecodedResponse, updateInstancesBalance } from "./payload"
import { addInstance } from "./actions"
import { addressToString, logBuilder } from "@remix-ui/helper"
import Web3 from "web3"
@ -318,15 +318,15 @@ export const getFuncABIInputs = (plugin: RunTab, funcABI: FuncABI) => {
return plugin.blockchain.getInputs(funcABI)
}
export const updateInstanceBalance = (plugin: RunTab) => {
export const updateInstanceBalance = async (plugin: RunTab, dispatch: React.Dispatch<any>) => {
if (plugin.REACT_API?.instances?.instanceList?.length) {
for (const instance of plugin.REACT_API.instances.instanceList) {
plugin.blockchain.getBalanceInEther(instance.address, (err, balInEth) => {
console.log('balance of ',instance.address, balInEth)
if (!err) instance.balance = balInEth
})
const instances = plugin.REACT_API?.instances?.instanceList
for (const instance of instances) {
const balInEth = await plugin.blockchain.getBalanceInEther(instance.address)
instance.balance = balInEth
}
}
dispatch(updateInstanceBalance(instances, dispatch))
}
}
export const isValidContractAddress = async (plugin: RunTab, address: string) => {

@ -71,7 +71,7 @@ export class Blockchain extends Plugin<any, any> {
}): any;
newAccount(_password: any, passwordPromptCb: any, cb: any): any;
/** Get the balance of an address, and convert wei to ether */
getBalanceInEther(address: any, cb: any): void;
getBalanceInEther(address: any): Promise<string>;
pendingTransactionsCount(): number;
/**
* This function send a tx only to Remix VM or testnet, will return an error for the mainnet

@ -5,7 +5,7 @@ declare class InjectedProvider {
getAccounts(cb: any): any;
newAccount(passwordPromptCb: any, cb: any): void;
resetEnvironment(): Promise<void>;
getBalanceInEther(address: any, cb: any): void;
getBalanceInEther(address: any): Promise<string>;
getGasPrice(cb: any): void;
signMessage(message: any, account: any, _passphrase: any, cb: any): void;
getProvider(): string;

@ -6,7 +6,7 @@ declare class NodeProvider {
getAccounts(cb: any): any;
newAccount(passwordPromptCb: any, cb: any): any;
resetEnvironment(): Promise<void>;
getBalanceInEther(address: any, cb: any): void;
getBalanceInEther(address: any): Promise<string>;
getGasPrice(cb: any): void;
signMessage(message: any, account: any, passphrase: any, cb: any): void;
getProvider(): any;

@ -9,7 +9,7 @@ declare class VMProvider {
web3: any;
createVMAccount(newAccount: any): string;
newAccount(_passwordPromptCb: any, cb: any): void;
getBalanceInEther(address: any, cb: any): void;
getBalanceInEther(address: any): Promise<string>;
getGasPrice(cb: any): void;
signMessage(message: any, account: any, _passphrase: any, cb: any): void;
getProvider(): string;

Loading…
Cancel
Save