Skip to content

Commit

Permalink
fix compliance errors
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmh committed Mar 28, 2018
1 parent 271c8bb commit f4db30d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
53 changes: 32 additions & 21 deletions lib/brain.js
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ Brain.prototype.isBlocked = function isBlocked (customer) {
*/
Brain.prototype.showBlockedCustomer = function showBlockedCustomer (customer) {
// Current transaction's fiat not including current bill
const insertedBills = this.tx.fiat.gt(BN(0))
const insertedBills = this.tx.fiat.gt(0)
if (!insertedBills) {
return this._transitionState('blockedCustomer', {insertedBills})
}
Expand Down Expand Up @@ -1207,17 +1207,6 @@ Brain.prototype.isTierCompliant = function isTierCompliant (tier) {
}
}

Brain.prototype.nonCompliantTiers = function nonCompliantTiers (amount) {
const tx = this.tx
const requiredTiers = complianceTiers.requiredTiers(this.trader, amount)
const rawNonCompliant = _.filter(tier => !this.isTierCompliant(tier), requiredTiers)
const smsOnly = _.isEmpty(rawNonCompliant) &&
this.exceedsZeroConf(tx) &&
!tx.phone

return smsOnly ? ['sms'] : rawNonCompliant
}

Brain.prototype.smsFlowHandleReturnState = function smsFlowHandleReturnState () {
const amount = this.getUsersDailyVolume().add(this.lastRejectedBillFiat)
const nonCompliant = this.nonCompliantTiers(amount)
Expand All @@ -1231,20 +1220,37 @@ Brain.prototype.smsFlowHandleReturnState = function smsFlowHandleReturnState ()
this.complianceReturnState()
}

Brain.prototype.minimumFiat = function minimumFiat () {
return _.head(this.trader.cassettes).denomination
}

Brain.prototype.complianceReturnState = function complianceReturnState () {
const returnState = this.returnState
const tx = this.tx
const amount = this.getUsersDailyVolume().add(this.lastRejectedBillFiat)
const notCompliant = !_.isEmpty(this.nonCompliantTiers(amount))
const minimumTx = tx.direction === 'cashIn'
? _.defaultTo(BN(0), tx.minimumTx)
: this.minimumFiat()

const amount = this.getUsersDailyVolume()
.add(this.lastRejectedBillFiat)
.add(minimumTx)

const nonCompliantTiers = this.nonCompliantTiers(amount)
const isCompliant = _.isEmpty(nonCompliantTiers)

if (this.redeem) {
return this._dispenseUpdate(tx)
}

if (!returnState) {
if (tx.direction && !notCompliant) {
if (tx.direction && isCompliant) {
return this.startScreen()
}

if (_.includes('hardLimit', nonCompliantTiers)) {
return this._timedState('hardLimitReached')
}

return this._idle()
}

Expand All @@ -1254,12 +1260,12 @@ Brain.prototype.complianceReturnState = function complianceReturnState () {
* Otherwise if sms registration was successfull,
* redirect user to insert the first bill (see below on transition)
*/
if (returnState === 'acceptingFirstBill' && notCompliant) {
if (returnState === 'acceptingFirstBill' && !isCompliant) {
return this._idle()
}

if (returnState === 'chooseFiat') {
if (notCompliant) {
if (!isCompliant) {
return this._idle()
}

Expand Down Expand Up @@ -1428,10 +1434,13 @@ Brain.prototype.isLowBalance = function isLowBalance () {
return highestBill.lt(0)
}

Brain.prototype.isCompliant = function isCompliant (amount) {
Brain.prototype.nonCompliantTiers = function nonCompliantTiers (amount) {
const requiredTiers = complianceTiers.requiredTiers(this.trader, amount)
const rawNonCompliant = _.filter(tier => !this.isTierCompliant(tier), requiredTiers)
return _.isEmpty(rawNonCompliant)
return _.filter(tier => !this.isTierCompliant(tier), requiredTiers)
}

Brain.prototype.isCompliant = function isCompliant (amount) {
return _.isEmpty(this.nonCompliantTiers(amount))
}

Brain.prototype._start = function _start () {
Expand Down Expand Up @@ -1742,6 +1751,7 @@ Brain.prototype.getUsersDailyVolume = function getUsersDailyVolume () {

// The total value user has transacted including the current transaction
const usersTotalDailyVolume = usersDailyVolumeBeforeTx.add(fiatBeforeBill)

return usersTotalDailyVolume
}

Expand Down Expand Up @@ -2242,7 +2252,8 @@ Brain.prototype._getFiatButtonResponse = function _getFiatButtonResponse () {
}

Brain.prototype._chooseFiat = function _chooseFiat () {
const amount = this.getUsersDailyVolume()
const minimumNote = this.minimumFiat()
const amount = this.getUsersDailyVolume().add(minimumNote)
const isCompliant = this.isCompliant(amount)

if (!isCompliant) {
Expand Down
2 changes: 1 addition & 1 deletion lib/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function computeCashOut (tx, cassettes, virtualCassettes, txLimit) {
const denominationIsAvailable = denom =>
!!BillMath.makeChange(cassettes, tx.fiat.add(denom))

const denominationUnderLimit = denom => tx.fiat.add(denom).lte(txLimit)
const denominationUnderLimit = denom => tx.fiat.add(denom).lt(txLimit)

const denominationIsActive = _.overEvery([denominationUnderLimit, denominationIsAvailable])
const denoms = _.union(virtualCassettes, _.map(_.get('denomination'), cassettes))
Expand Down
1 change: 1 addition & 0 deletions ui/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ $(document).ready(function () {
setupButton('id-verification-error-ok', 'idVerificationErrorOk')

setupButton('limit-reached-ok', 'idle')
setupButton('hard-limit-reached-ok', 'idle')
setupButton('deposit-timeout-sent-yes', 'depositTimeout')
setupButton('deposit-timeout-sent-no', 'depositTimeoutNotSent')
setupButton('out-of-cash-ok', 'idle')
Expand Down
15 changes: 15 additions & 0 deletions ui/start.html
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,21 @@ <h1 class="js-i18n">We're all out of coins!</h1>
</section>
</section>

<section class="viewport hard_limit_reached_state info" data-tr-section="hard-limit-reached">
<section class="main">
<section class="top">
<section class="content">
<h1 class="js-i18n">Temporary limit reached</h1>
<p><strong class="js-i18n">You've been busy! Let us cool off for a couple of days and try again.</strong></p>
<div class="actions">
<span id="hard-limit-reached-ok" display="inline-block" class="button ok js-i18n">OK</span>
</div>
</section>
</section>
<section class="bottom"></section>
</section>
</section>

<section class="viewport high_bill_state info" data-tr-section="high-bill">
<section class="main">
<section class="top">
Expand Down

0 comments on commit f4db30d

Please sign in to comment.