From 547cf4bef3f2c18a26fb9fada96bd92e7988687f Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 3 Jul 2018 23:11:49 +0200 Subject: Refactor testnet-faucet to use web3Wrapper instead of web3 directly --- packages/testnet-faucets/src/ts/dispense_asset_tasks.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'packages/testnet-faucets/src/ts/dispense_asset_tasks.ts') diff --git a/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts b/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts index 41b6c90cd..6e41ddae3 100644 --- a/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts +++ b/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts @@ -1,7 +1,7 @@ import { ZeroEx } from '0x.js'; import { BigNumber, logUtils, promisify } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; -import * as Web3 from 'web3'; import { configs } from './configs'; @@ -13,22 +13,21 @@ const DISPENSE_MAX_AMOUNT_ETHER = 2; type AsyncTask = () => Promise; export const dispenseAssetTasks = { - dispenseEtherTask(recipientAddress: string, web3: Web3): AsyncTask { + dispenseEtherTask(recipientAddress: string, web3Wrapper: Web3Wrapper): AsyncTask { return async () => { logUtils.log(`Processing ETH ${recipientAddress}`); - const userBalance = await promisify(web3.eth.getBalance)(recipientAddress); - const maxAmountInWei = new BigNumber(web3.toWei(DISPENSE_MAX_AMOUNT_ETHER, 'ether')); + const userBalance = await web3Wrapper.getBalanceInWeiAsync(recipientAddress); + const maxAmountInWei = Web3Wrapper.toWei(new BigNumber(DISPENSE_MAX_AMOUNT_ETHER)); if (userBalance.greaterThanOrEqualTo(maxAmountInWei)) { logUtils.log( `User exceeded ETH balance maximum (${maxAmountInWei}) ${recipientAddress} ${userBalance} `, ); return; } - const sendTransactionAsync = promisify(web3.eth.sendTransaction); - const txHash = await sendTransactionAsync({ + const txHash = await web3Wrapper.sendTransactionAsync({ from: configs.DISPENSER_ADDRESS, to: recipientAddress, - value: web3.toWei(DISPENSE_AMOUNT_ETHER, 'ether'), + value: Web3Wrapper.toWei(new BigNumber(DISPENSE_AMOUNT_ETHER)), }); logUtils.log(`Sent ${DISPENSE_AMOUNT_ETHER} ETH to ${recipientAddress} tx: ${txHash}`); }; -- cgit v1.2.3