diff options
author | Fabio Berger <me@fabioberger.com> | 2018-01-30 21:00:35 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-01-30 21:00:35 +0800 |
commit | 69151c06e42fd588506db3aa62b95df5b4399607 (patch) | |
tree | 878532483594627a5283f784ced0a2c0cfc68d59 /packages/testnet-faucets/src/ts/zrx_request_queue.ts | |
parent | 86cc011212088801a778d947ae925cc0b1ddadf8 (diff) | |
parent | 2e3c02887efc24de35ce82b3662d9c47a0056a8c (diff) | |
download | dexon-0x-contracts-69151c06e42fd588506db3aa62b95df5b4399607.tar dexon-0x-contracts-69151c06e42fd588506db3aa62b95df5b4399607.tar.gz dexon-0x-contracts-69151c06e42fd588506db3aa62b95df5b4399607.tar.bz2 dexon-0x-contracts-69151c06e42fd588506db3aa62b95df5b4399607.tar.lz dexon-0x-contracts-69151c06e42fd588506db3aa62b95df5b4399607.tar.xz dexon-0x-contracts-69151c06e42fd588506db3aa62b95df5b4399607.tar.zst dexon-0x-contracts-69151c06e42fd588506db3aa62b95df5b4399607.zip |
Merge branch 'development' into feature/portal-ledger-support
* development:
Publish
Add PR number
Add config file specifically in prettier command and fix files
Fix prettier
Fix prettier
Add shouldAddPersonalMessagePrefix param to signOrderHashAsync instead of trying to infer whether to add it or not from the nodeVersion
Publish
Move @0xproject/types to dependencies
Updated web3-typescript-typings changelog
Fixed getTransactionReceipt not returning null
Run prettier
Update changelog
Add Rinkeby addresses to artifacts
Fix bad merge on package.json
Respond to GH comments and add /info endpoint
Change package name to @0xproject/testnet-faucets
Implement testnet faucets for any testnet available via infura
Rename to testnet-faucets
Add to the Pull Request Template
Create an ISSUE TEMPLATE
Diffstat (limited to 'packages/testnet-faucets/src/ts/zrx_request_queue.ts')
-rw-r--r-- | packages/testnet-faucets/src/ts/zrx_request_queue.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/packages/testnet-faucets/src/ts/zrx_request_queue.ts b/packages/testnet-faucets/src/ts/zrx_request_queue.ts new file mode 100644 index 000000000..3d73f9dd2 --- /dev/null +++ b/packages/testnet-faucets/src/ts/zrx_request_queue.ts @@ -0,0 +1,46 @@ +import { ZeroEx } from '0x.js'; +import { BigNumber } from '@0xproject/utils'; +import * as _ from 'lodash'; + +import { configs } from './configs'; +import { errorReporter } from './error_reporter'; +import { RequestQueue } from './request_queue'; +import { utils } from './utils'; + +// HACK: web3 leaks XMLHttpRequest into the global scope and causes requests to hang +// because they are using the wrong XHR package. +// Filed issue: https://github.com/ethereum/web3.js/issues/844 +// tslint:disable-next-line:ordered-imports +import * as Web3 from 'web3'; + +const DISPENSE_AMOUNT_ZRX = new BigNumber(0.1); +const QUEUE_INTERVAL_MS = 5000; + +export class ZRXRequestQueue extends RequestQueue { + private _zeroEx: ZeroEx; + constructor(web3: Web3, networkId: number) { + super(web3); + this.queueIntervalMs = QUEUE_INTERVAL_MS; + const zeroExConfig = { + networkId, + }; + this._zeroEx = new ZeroEx(web3.currentProvider, zeroExConfig); + } + protected async processNextRequestFireAndForgetAsync(recipientAddress: string) { + utils.consoleLog(`Processing ZRX ${recipientAddress}`); + const baseUnitAmount = ZeroEx.toBaseUnitAmount(DISPENSE_AMOUNT_ZRX, 18); + try { + const zrxTokenAddress = this._zeroEx.exchange.getZRXTokenAddress(); + const txHash = await this._zeroEx.token.transferAsync( + zrxTokenAddress, + configs.DISPENSER_ADDRESS, + recipientAddress, + baseUnitAmount, + ); + utils.consoleLog(`Sent ${DISPENSE_AMOUNT_ZRX} ZRX to ${recipientAddress} tx: ${txHash}`); + } catch (err) { + utils.consoleLog(`Unexpected err: ${err} - ${JSON.stringify(err)}`); + await errorReporter.reportAsync(err); + } + } +} |