Add validation to balance constructor

feature/default_network_editable
Dan Finlay 7 years ago
parent 7032edf32b
commit ea79eca8eb
  1. 10
      app/scripts/controllers/balance.js

@ -5,7 +5,9 @@ const BN = require('ethereumjs-util').BN
class BalanceController { class BalanceController {
constructor (opts = {}) { constructor (opts = {}) {
this._validateParams(opts)
const { address, accountTracker, txController, blockTracker } = opts const { address, accountTracker, txController, blockTracker } = opts
this.address = address this.address = address
this.accountTracker = accountTracker this.accountTracker = accountTracker
this.txController = txController this.txController = txController
@ -65,6 +67,14 @@ class BalanceController {
return pending return pending
} }
_validateParams (opts) {
const { address, accountTracker, txController, blockTracker } = opts
if (!address || !accountTracker || !txController || !blockTracker) {
const error = 'Cannot construct a balance checker without address, accountTracker, txController, and blockTracker.'
throw new Error(error)
}
}
} }
module.exports = BalanceController module.exports = BalanceController

Loading…
Cancel
Save