From 1c271a65a567a988cb96882b58a879b61c7c3600 Mon Sep 17 00:00:00 2001 From: Philip Welber Date: Wed, 11 Apr 2018 12:53:57 -0400 Subject: [PATCH] feat(Recurring Buy): move show logic to coinify service --- .../coinify/recurring-confirm.component.js | 6 +++--- .../coinify/coinifyCheckout.controller.js | 4 +--- assets/js/services/coinify.service.js | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/assets/js/components/coinify/recurring-confirm.component.js b/assets/js/components/coinify/recurring-confirm.component.js index 4e108c83b2..bb037d35a7 100644 --- a/assets/js/components/coinify/recurring-confirm.component.js +++ b/assets/js/components/coinify/recurring-confirm.component.js @@ -17,12 +17,12 @@ angular function CoinifyRecurringConfirmController (recurringTrade, coinify) { this.date = new Date(); this.recurringTiming = () => recurringTrade.getTimespan(this.date, this.frequency); - this.needsMoreTrades = coinify.trades.filter((t) => coinify.tradeStateIn(coinify.states.completed)(t) && !t.tradeSubscriptionId && t.medium === 'card').length < 3; + this.needsMoreTradesForRecurring = coinify.needsMoreTradesForRecurring; const determineState = () => { - if (this.needsKyc && this.needsMoreTrades) return 'NEEDS_KYC_AND_TRADES'; + if (this.needsKyc && this.needsMoreTradesForRecurring) return 'NEEDS_KYC_AND_TRADES'; if (this.needsKyc) return 'NEEDS_KYC'; - if (this.needsMoreTrades) return 'NEEDS_TRADES'; + if (this.needsMoreTradesForRecurring) return 'NEEDS_TRADES'; return 'PROCEED'; }; this.state = determineState(); diff --git a/assets/js/controllers/coinify/coinifyCheckout.controller.js b/assets/js/controllers/coinify/coinifyCheckout.controller.js index a1d498d63a..e4cb7863c7 100644 --- a/assets/js/controllers/coinify/coinifyCheckout.controller.js +++ b/assets/js/controllers/coinify/coinifyCheckout.controller.js @@ -62,9 +62,7 @@ function CoinifyCheckoutController ($scope, $rootScope, $stateParams, Env, Angul $state.params.selectedTab = this.selectedTab; } }; - $scope.showRecurringBuy = MyWallet.wallet.accountInfo.countryCodeGuess !== 'UK' && - env.partners.coinify.showRecurringBuy && - $scope.exchange.profile.email; + $scope.showRecurringBuy = coinify.showRecurringBuy(env); if (env.qaDebugger) { $scope.qaDebugger = env.qaDebugger; diff --git a/assets/js/services/coinify.service.js b/assets/js/services/coinify.service.js index af25b3c6f0..6c21575752 100644 --- a/assets/js/services/coinify.service.js +++ b/assets/js/services/coinify.service.js @@ -46,6 +46,9 @@ function coinify (Env, BrowserHelper, $timeout, $q, $state, $uibModal, $uibModal get userCanSell () { return service.balanceAboveMin && !service.remainingBelowMin; }, + get needsMoreTradesForRecurring () { + return service.trades.filter((t) => service.tradeStateIn(states.completed)(t) && !t.tradeSubscriptionId && t.medium === 'card').length < 3; + }, get buyReason () { let reason; let { profile, user } = service.exchange; @@ -235,5 +238,16 @@ function coinify (Env, BrowserHelper, $timeout, $q, $state, $uibModal, $uibModal return false; }; + service.showRecurringBuy = (env) => { + if (!service.exchange.profile.email) return false; + + const showFlag = env.partners.coinify.showRecurringBuy; + const allowedCountry = MyWallet.wallet.accountInfo.countryCodeGuess !== 'UK'; + const needsKYC = service.exchange.profile.level && +service.exchange.profile.level.name < 2; + + if (!needsKYC && !service.needsMoreTradesForRecurring && !service.exchange.profile.tradeSubscriptionsAllowed) return false; + return showFlag && allowedCountry; + }; + return service; }