WA-230 adding getBalanceInEtherOf in wallet/getWeb3 instance
This commit is contained in:
parent
e33077b752
commit
e643fcd033
|
@ -1,4 +1,5 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
import { BigNumber } from 'bignumber.js'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import type { ProviderProps } from '~/wallets/store/model/provider'
|
import type { ProviderProps } from '~/wallets/store/model/provider'
|
||||||
import { promisify } from '~/utils/promisify'
|
import { promisify } from '~/utils/promisify'
|
||||||
|
@ -42,16 +43,11 @@ export const getProviderInfo: Function = async (): Promise<ProviderProps> => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ensureOnce = (fn: Function): Function => {
|
export const getBalanceInEtherOf = async (safeAddress: string): Promise<string> => {
|
||||||
let executed = false
|
const funds: BigNumber = await promisify(cb => web3.eth.getBalance(safeAddress, cb))
|
||||||
let response
|
if (!funds) {
|
||||||
|
return '0'
|
||||||
return (...args) => {
|
|
||||||
if (executed) { return response }
|
|
||||||
|
|
||||||
executed = true
|
|
||||||
response = fn(args)
|
|
||||||
|
|
||||||
return response
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return web3.fromWei(funds.toNumber(), 'ether').toString()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue