diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-05-11 23:38:51 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-05-14 16:35:13 +0800 |
commit | b74957acdfc8d67d154bcb4698acd7575db7cc47 (patch) | |
tree | 3f33c2faac3b55e52098ab0b5b9883a9b62f5aee /packages/testnet-faucets/src | |
parent | 6aed4fb1ae27dabed027c855f2cbdc0bfb4f3b6b (diff) | |
download | dexon-0x-contracts-b74957acdfc8d67d154bcb4698acd7575db7cc47.tar dexon-0x-contracts-b74957acdfc8d67d154bcb4698acd7575db7cc47.tar.gz dexon-0x-contracts-b74957acdfc8d67d154bcb4698acd7575db7cc47.tar.bz2 dexon-0x-contracts-b74957acdfc8d67d154bcb4698acd7575db7cc47.tar.lz dexon-0x-contracts-b74957acdfc8d67d154bcb4698acd7575db7cc47.tar.xz dexon-0x-contracts-b74957acdfc8d67d154bcb4698acd7575db7cc47.tar.zst dexon-0x-contracts-b74957acdfc8d67d154bcb4698acd7575db7cc47.zip |
Add missing type definitions
Diffstat (limited to 'packages/testnet-faucets/src')
6 files changed, 30 insertions, 19 deletions
diff --git a/packages/testnet-faucets/src/ts/dispatch_queue.ts b/packages/testnet-faucets/src/ts/dispatch_queue.ts index 2dbeeba7a..b1996a0c2 100644 --- a/packages/testnet-faucets/src/ts/dispatch_queue.ts +++ b/packages/testnet-faucets/src/ts/dispatch_queue.ts @@ -28,12 +28,12 @@ export class DispatchQueue { public isFull(): boolean { return this.size() >= MAX_QUEUE_SIZE; } - public stop() { + public stop(): void { if (!_.isUndefined(this._queueIntervalIdIfExists)) { intervalUtils.clearAsyncExcludingInterval(this._queueIntervalIdIfExists); } } - private _start() { + private _start(): void { this._queueIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval( async () => { const taskAsync = this._queue.shift(); diff --git a/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts b/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts index 99f1bad36..39ba4bc14 100644 --- a/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts +++ b/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts @@ -11,8 +11,10 @@ const DISPENSE_AMOUNT_TOKEN = 0.1; const DISPENSE_MAX_AMOUNT_TOKEN = 2; const DISPENSE_MAX_AMOUNT_ETHER = 2; +type AsyncTask = () => Promise<void>; + export const dispenseAssetTasks = { - dispenseEtherTask(recipientAddress: string, web3: Web3) { + dispenseEtherTask(recipientAddress: string, web3: Web3): AsyncTask { return async () => { logUtils.log(`Processing ETH ${recipientAddress}`); const userBalance = await promisify<BigNumber>(web3.eth.getBalance)(recipientAddress); @@ -32,7 +34,7 @@ export const dispenseAssetTasks = { logUtils.log(`Sent ${DISPENSE_AMOUNT_ETHER} ETH to ${recipientAddress} tx: ${txHash}`); }; }, - dispenseTokenTask(recipientAddress: string, tokenSymbol: string, zeroEx: ZeroEx) { + dispenseTokenTask(recipientAddress: string, tokenSymbol: string, zeroEx: ZeroEx): AsyncTask { return async () => { logUtils.log(`Processing ${tokenSymbol} ${recipientAddress}`); const amountToDispense = new BigNumber(DISPENSE_AMOUNT_TOKEN); diff --git a/packages/testnet-faucets/src/ts/error_reporter.ts b/packages/testnet-faucets/src/ts/error_reporter.ts index f0f3ca679..a0abcc07b 100644 --- a/packages/testnet-faucets/src/ts/error_reporter.ts +++ b/packages/testnet-faucets/src/ts/error_reporter.ts @@ -5,7 +5,7 @@ import rollbar = require('rollbar'); import { configs } from './configs'; export const errorReporter = { - setup() { + setup(): void { rollbar.init(configs.ROLLBAR_ACCESS_KEY, { environment: configs.ENVIRONMENT, }); @@ -31,7 +31,7 @@ export const errorReporter = { }); }); }, - errorHandler() { + errorHandler(): any { return rollbar.errorHandler(configs.ROLLBAR_ACCESS_KEY); }, }; diff --git a/packages/testnet-faucets/src/ts/handler.ts b/packages/testnet-faucets/src/ts/handler.ts index a6e786552..3858b5339 100644 --- a/packages/testnet-faucets/src/ts/handler.ts +++ b/packages/testnet-faucets/src/ts/handler.ts @@ -1,4 +1,5 @@ import { Order, SignedOrder, ZeroEx } from '0x.js'; +import { Provider } from '@0xproject/types'; import { BigNumber, logUtils } from '@0xproject/utils'; import * as express from 'express'; import * as _ from 'lodash'; @@ -38,7 +39,7 @@ const FIVE_DAYS_IN_MS = 4.32e8; // TODO: make this configurable export class Handler { private _networkConfigByNetworkId: ItemByNetworkId<NetworkConfig> = {}; - private static _createProviderEngine(rpcUrl: string) { + private static _createProviderEngine(rpcUrl: string): Provider { if (_.isUndefined(configs.DISPENSER_PRIVATE_KEY)) { throw new Error('Dispenser Private key not found'); } @@ -69,7 +70,7 @@ export class Handler { }; }); } - public getQueueInfo(req: express.Request, res: express.Response) { + public getQueueInfo(req: express.Request, res: express.Response): void { res.setHeader('Content-Type', 'application/json'); const queueInfo = _.mapValues(rpcUrls, (rpcUrl: string, networkId: string) => { const dispatchQueue = this._networkConfigByNetworkId[networkId].dispatchQueue; @@ -81,19 +82,23 @@ export class Handler { const payload = JSON.stringify(queueInfo); res.status(200).send(payload); } - public dispenseEther(req: express.Request, res: express.Response) { + public dispenseEther(req: express.Request, res: express.Response): void { this._dispenseAsset(req, res, RequestedAssetType.ETH); } - public dispenseZRX(req: express.Request, res: express.Response) { + public dispenseZRX(req: express.Request, res: express.Response): void { this._dispenseAsset(req, res, RequestedAssetType.ZRX); } - public async dispenseWETHOrder(req: express.Request, res: express.Response) { - await this._dispenseOrder(req, res, RequestedAssetType.WETH); + public async dispenseWETHOrderAsync(req: express.Request, res: express.Response): Promise<void> { + await this._dispenseOrderAsync(req, res, RequestedAssetType.WETH); } - public async dispenseZRXOrder(req: express.Request, res: express.Response, next: express.NextFunction) { - await this._dispenseOrder(req, res, RequestedAssetType.ZRX); + public async dispenseZRXOrderAsync( + req: express.Request, + res: express.Response, + next: express.NextFunction, + ): Promise<void> { + await this._dispenseOrderAsync(req, res, RequestedAssetType.ZRX); } - private _dispenseAsset(req: express.Request, res: express.Response, requestedAssetType: RequestedAssetType) { + private _dispenseAsset(req: express.Request, res: express.Response, requestedAssetType: RequestedAssetType): void { const networkId = req.params.networkId; const recipient = req.params.recipient; const networkConfig = this._networkConfigByNetworkId[networkId]; @@ -121,7 +126,11 @@ export class Handler { logUtils.log(`Added ${recipient} to queue: ${requestedAssetType} networkId: ${networkId}`); res.status(200).end(); } - private async _dispenseOrder(req: express.Request, res: express.Response, requestedAssetType: RequestedAssetType) { + private async _dispenseOrderAsync( + req: express.Request, + res: express.Response, + requestedAssetType: RequestedAssetType, + ): Promise<void> { const networkConfig = _.get(this._networkConfigByNetworkId, req.params.networkId); if (_.isUndefined(networkConfig)) { res.status(400).send('UNSUPPORTED_NETWORK_ID'); diff --git a/packages/testnet-faucets/src/ts/parameter_transformer.ts b/packages/testnet-faucets/src/ts/parameter_transformer.ts index 2630a5e0b..58bf154dc 100644 --- a/packages/testnet-faucets/src/ts/parameter_transformer.ts +++ b/packages/testnet-faucets/src/ts/parameter_transformer.ts @@ -8,7 +8,7 @@ import { rpcUrls } from './rpc_urls'; const DEFAULT_NETWORK_ID = 42; // kovan export const parameterTransformer = { - transform(req: Request, res: Response, next: NextFunction) { + transform(req: Request, res: Response, next: NextFunction): void { const recipientAddress = req.params.recipient; if (_.isUndefined(recipientAddress) || !addressUtils.isAddress(recipientAddress)) { res.status(400).send('INVALID_RECIPIENT_ADDRESS'); diff --git a/packages/testnet-faucets/src/ts/server.ts b/packages/testnet-faucets/src/ts/server.ts index be1077756..198a5fdc9 100644 --- a/packages/testnet-faucets/src/ts/server.ts +++ b/packages/testnet-faucets/src/ts/server.ts @@ -23,8 +23,8 @@ app.get('/ping', (req: express.Request, res: express.Response) => { app.get('/info', handler.getQueueInfo.bind(handler)); app.get('/ether/:recipient', parameterTransformer.transform, handler.dispenseEther.bind(handler)); app.get('/zrx/:recipient', parameterTransformer.transform, handler.dispenseZRX.bind(handler)); -app.get('/order/weth/:recipient', parameterTransformer.transform, handler.dispenseWETHOrder.bind(handler)); -app.get('/order/zrx/:recipient', parameterTransformer.transform, handler.dispenseZRXOrder.bind(handler)); +app.get('/order/weth/:recipient', parameterTransformer.transform, handler.dispenseWETHOrderAsync.bind(handler)); +app.get('/order/zrx/:recipient', parameterTransformer.transform, handler.dispenseZRXOrderAsync.bind(handler)); // Log to rollbar any errors unhandled by handlers app.use(errorReporter.errorHandler()); |