From e3b6226a1df927cd93ed64b333d08adff17ad440 Mon Sep 17 00:00:00 2001 From: acerasino Date: Mon, 25 Feb 2019 10:54:00 +0100 Subject: [PATCH] #20 code review --- src/cli/tws/get-balance.js | 8 ++++---- src/commands/GetBalanceCommand.js | 8 ++++---- src/commands/commandList.js | 11 +++++++---- src/commands/index.js | 2 +- ...mandValidator.js => GetBalanceCommandValidator.js} | 4 ++-- .../commands/getTradingWalletBalanceCommand.test.js | 10 +++++----- 6 files changed, 23 insertions(+), 20 deletions(-) rename src/validators/{GetTradingWalletBalanceCommandValidator.js => GetBalanceCommandValidator.js} (82%) diff --git a/src/cli/tws/get-balance.js b/src/cli/tws/get-balance.js index ff1531b..b703aee 100644 --- a/src/cli/tws/get-balance.js +++ b/src/cli/tws/get-balance.js @@ -1,9 +1,9 @@ const logger = require('../../logger') -const { getTradingWalletBalanceCommand } = require('../../commands/commandList') +const { getBalanceCommand } = require('../../commands/commandList') module.exports = { - describe: getTradingWalletBalanceCommand.constructor.description, - builder: getTradingWalletBalanceCommand.getBuilderArgsDetails(), - handler: async argv => logger.show(await getTradingWalletBalanceCommand.executeAsync(argv)), + describe: getBalanceCommand.constructor.description, + builder: getBalanceCommand.getBuilderArgsDetails(), + handler: async argv => logger.show(await getBalanceCommand.executeAsync(argv)), } diff --git a/src/commands/GetBalanceCommand.js b/src/commands/GetBalanceCommand.js index cc06c2a..b1c735e 100644 --- a/src/commands/GetBalanceCommand.js +++ b/src/commands/GetBalanceCommand.js @@ -96,11 +96,11 @@ class GetBalanceCommand extends ABaseCommand { * It executes the command after the validation step. * * @param {Object} params - * @param {String} params.from The personal wallet address (EOA). - * @param {String} params.to The trading wallet address. - * @param {String} params.token The token wallet address. + * @param {String} params.from The personal wallet address (EOA). + * @param {String} params.to The trading wallet address. + * @param {String} params.token The token wallet address. * @param {String} params.privateKeyFilePath The EOA private key. - * @param {String} params.draft The draft. If set to true it shows the TransactionObjectDraft. + * @param {String} params.draft The draft. If set to true it shows the TransactionObjectDraft. */ async doExecuteAsync({ from, to, token, privateKeyFilePath, draft }) { let personalWalletAddressRetrived = _.cloneDeep(from) diff --git a/src/commands/commandList.js b/src/commands/commandList.js index bcf0b33..782e742 100644 --- a/src/commands/commandList.js +++ b/src/commands/commandList.js @@ -8,8 +8,8 @@ const GetAddressCommandValidator = require('../validators/GetAddressCommandValid const GetAllowanceCommand = require('../commands/GetAllowanceCommand') const GetAllowanceCommandValidator = require('../validators/GetAllowanceCommandValidator') -const GetTradingWalletBalanceCommand = require('../commands/GetBalanceCommand') -const GetTradingWalletBalanceCommandValidator = require('../validators/GetTradingWalletBalanceCommandValidator') +const GetBalanceCommand = require('../commands/GetBalanceCommand') +const GetBalanceCommandValidator = require('../validators/GetBalanceCommandValidator') const logger = require('../logger') const OrderSignCommand = require('../commands/OrderSignCommand') @@ -29,7 +29,7 @@ const depositEthCommandValidator = new DepositEthCommandValidator(logger) const getAddressCommandValidator = new GetAddressCommandValidator(logger) const getAllowanceCommandValidator = new GetAllowanceCommandValidator(logger) -const getTradingWalletBalanceCommandValidator = new GetTradingWalletBalanceCommandValidator(logger) +const getBalanceCommandValidator = new GetBalanceCommandValidator(logger) const orderSignCommandValidator = new OrderSignCommandValidator(logger) const withdrawCommandValidator = new WithdrawCommandValidator(logger) @@ -46,6 +46,9 @@ const getAddressCommand = new GetAddressCommand(logger, tradingWalletService, const getAllowanceCommand = new GetAllowanceCommand(logger, getAllowanceCommandValidator, privateKeyService, privateKeyValidator) +const getBalanceCommand = new GetBalanceCommand(logger, tradingWalletService, + getBalanceCommandValidator, privateKeyService, privateKeyValidator) + const createWalletCommand = new CreateWalletCommand(logger, getAllowanceCommandValidator, createWalletCommandValidator, privateKeyService, privateKeyValidator) @@ -70,7 +73,7 @@ module.exports = { depositEthCommand, getAddressCommand, getAllowanceCommand, - getTradingWalletBalanceCommand, + getBalanceCommand, signCommand, withdrawCommand, } diff --git a/src/commands/index.js b/src/commands/index.js index 1505431..59431bd 100644 --- a/src/commands/index.js +++ b/src/commands/index.js @@ -4,7 +4,7 @@ const commandList = require('./commandList') const CreateWalletCommand = require('./CreateWalletCommand') const DepositEthCommand = require('./DepositEthCommand') const GetAddressCommand = require('./GetAddressCommand') -const GetTradingWalletBalanceCommand = require('./GetTradingWalletBalanceCommand') +const GetTradingWalletBalanceCommand = require('./GetBalanceCommand') const OrderSignCommand = require('./OrderSignCommand') module.exports = { diff --git a/src/validators/GetTradingWalletBalanceCommandValidator.js b/src/validators/GetBalanceCommandValidator.js similarity index 82% rename from src/validators/GetTradingWalletBalanceCommandValidator.js rename to src/validators/GetBalanceCommandValidator.js index 436e66c..b106793 100644 --- a/src/validators/GetTradingWalletBalanceCommandValidator.js +++ b/src/validators/GetBalanceCommandValidator.js @@ -10,10 +10,10 @@ const withdrawSchema = customJoiValidator.object() draft: customJoiValidator.boolean(), }) -class GetTradingWalletBalanceCommandValidator extends BaseValidator { +class GetBalanceCommandValidator extends BaseValidator { getBalance(getBalanceData) { return this.constructor.validate(getBalanceData, withdrawSchema) } } -module.exports = GetTradingWalletBalanceCommandValidator +module.exports = GetBalanceCommandValidator diff --git a/tests/unit/commands/getTradingWalletBalanceCommand.test.js b/tests/unit/commands/getTradingWalletBalanceCommand.test.js index a8ea958..9f9d00e 100644 --- a/tests/unit/commands/getTradingWalletBalanceCommand.test.js +++ b/tests/unit/commands/getTradingWalletBalanceCommand.test.js @@ -7,18 +7,18 @@ const logger = require('../../../src/logger') const TradingWalletServiceBuilder = require('../../../src/factories/TradingWalletServiceBuilder') const PrivateKeyValidator = require('../../../src/validators/PrivateKeyValidator') -const GetTradingWalletBalanceCommandValidator = require('../../../src/validators/GetTradingWalletBalanceCommandValidator') -const GetTradingWalletBalanceCommand = require('../../../src/commands/GetBalanceCommand') +const GetBalanceCommandValidator = require('../../../src/validators/GetBalanceCommandValidator') +const GetBalanceCommand = require('../../../src/commands/GetBalanceCommand') -const getTradingWalletBalanceCommandValidator = new GetTradingWalletBalanceCommandValidator(logger) +const getBalanceCommandValidator = new GetBalanceCommandValidator(logger) const tradingWalletService = TradingWalletServiceBuilder.build() const privateKeyValidator = new PrivateKeyValidator(logger) const privateKeyService = new PrivateKeyService(logger) -const getTradingWalletBalanceCommand = new GetTradingWalletBalanceCommand(logger, tradingWalletService, - getTradingWalletBalanceCommandValidator, privateKeyService, privateKeyValidator) +const getTradingWalletBalanceCommand = new GetBalanceCommand(logger, tradingWalletService, + getBalanceCommandValidator, privateKeyService, privateKeyValidator) afterEach(() => { sandbox.restore()