Skip to content
This repository has been archived by the owner on Oct 8, 2019. It is now read-only.

Commit

Permalink
feat(Recurring Buy): move show logic to coinify service
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Welber committed Apr 11, 2018
1 parent 4f4300b commit 1c271a6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
6 changes: 3 additions & 3 deletions assets/js/components/coinify/recurring-confirm.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 1 addition & 3 deletions assets/js/controllers/coinify/coinifyCheckout.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions assets/js/services/coinify.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

0 comments on commit 1c271a6

Please sign in to comment.