Skip to content

Commit

Permalink
#20 code review
Browse files Browse the repository at this point in the history
  • Loading branch information
ceres3idoo committed Feb 25, 2019
1 parent 20a8bee commit e3b6226
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/cli/tws/get-balance.js
Original file line number Diff line number Diff line change
@@ -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)),
}
8 changes: 4 additions & 4 deletions src/commands/GetBalanceCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions src/commands/commandList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -70,7 +73,7 @@ module.exports = {
depositEthCommand,
getAddressCommand,
getAllowanceCommand,
getTradingWalletBalanceCommand,
getBalanceCommand,
signCommand,
withdrawCommand,
}
2 changes: 1 addition & 1 deletion src/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions tests/unit/commands/getTradingWalletBalanceCommand.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e3b6226

Please sign in to comment.