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. 14
      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 */ /** Get the balance of an address, and convert wei to ether */
getBalanceInEther (address, cb) { getBalanceInEther (address) {
this.getCurrentProvider().getBalanceInEther(address, cb) return this.getCurrentProvider().getBalanceInEther(address)
} }
pendingTransactionsCount () { pendingTransactionsCount () {

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

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

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

@ -3,17 +3,14 @@ import { RunTab } from "../types/run-tab"
import { clearInstances, setAccount, setExecEnv } from "./actions" import { clearInstances, setAccount, setExecEnv } from "./actions"
import { displayNotification, displayPopUp, fetchAccountsListFailed, fetchAccountsListRequest, fetchAccountsListSuccess, setExternalEndpoint, setMatchPassphrase, setPassphrase } from "./payload" 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 const accounts = plugin.REACT_API.accounts.loadedAccounts
Object.keys(accounts).map((value) => { for (const account of Object.keys(accounts)) {
plugin.blockchain.getBalanceInEther(value, (err, balance) => { const balance = await plugin.blockchain.getBalanceInEther(account)
if (err) return const updated = shortenAddress(account, balance)
const updated = shortenAddress(value, balance) accounts[account] = updated
}
accounts[value] = updated
})
})
dispatch(fetchAccountsListSuccess(accounts)) dispatch(fetchAccountsListSuccess(accounts))
} }
@ -31,17 +28,10 @@ export const fillAccountsList = async (plugin: RunTab, dispatch: React.Dispatch<
// - all the promises resolve // - all the promises resolve
// - at least one reject // - at least one reject
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
await (Promise as any).all(accounts.map((account) => { for (const account of accounts) {
return new Promise((resolve, reject) => { const balance = await plugin.blockchain.getBalanceInEther(account)
plugin.blockchain.getBalanceInEther(account, (err, balance) => { loadedAccounts[account] = shortenAddress(account, balance)
if (err) return reject(err) }
const updated = shortenAddress(account, balance)
loadedAccounts[account] = updated
resolve(account)
})
})
}))
const provider = plugin.blockchain.getProvider() const provider = plugin.blockchain.getProvider()
if (provider === 'injected') { 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 // 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 { UpgradeableContract } from '../../../../../../node_modules/@openzeppelin/upgrades-core/dist/standalone'
import { DeployMode, MainnetPrompt } from "../types" 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 { addInstance } from "./actions"
import { addressToString, logBuilder } from "@remix-ui/helper" import { addressToString, logBuilder } from "@remix-ui/helper"
import Web3 from "web3" import Web3 from "web3"
@ -318,14 +318,14 @@ export const getFuncABIInputs = (plugin: RunTab, funcABI: FuncABI) => {
return plugin.blockchain.getInputs(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) { if (plugin.REACT_API?.instances?.instanceList?.length) {
for (const instance of plugin.REACT_API.instances.instanceList) { const instances = plugin.REACT_API?.instances?.instanceList
plugin.blockchain.getBalanceInEther(instance.address, (err, balInEth) => { for (const instance of instances) {
console.log('balance of ',instance.address, balInEth) const balInEth = await plugin.blockchain.getBalanceInEther(instance.address)
if (!err) instance.balance = balInEth instance.balance = balInEth
})
} }
dispatch(updateInstanceBalance(instances, dispatch))
} }
} }

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

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

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

Loading…
Cancel
Save