glidera new send and buy flow

This commit is contained in:
Gabriel Bazán 2016-12-02 09:48:56 -03:00
commit e44a305269
8 changed files with 184 additions and 75 deletions

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('amountController', function($scope, $filter, $timeout, $ionicScrollDelegate, $ionicHistory, $ionicPopover, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, bitpayCardService, popupService, bwcError, payproService, profileService, bitcore, amazonService) { angular.module('copayApp.controllers').controller('amountController', function($scope, $filter, $timeout, $ionicScrollDelegate, $ionicHistory, $ionicPopover, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, bitpayCardService, popupService, bwcError, payproService, profileService, bitcore, amazonService, glideraService) {
var unitToSatoshi; var unitToSatoshi;
var satToUnit; var satToUnit;
var unitDecimals; var unitDecimals;
@ -15,22 +15,31 @@ angular.module('copayApp.controllers').controller('amountController', function($
$scope.$on("$ionicView.beforeEnter", function(event, data) { $scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.isGiftCard = data.stateParams.isGiftCard; $scope.isGiftCard = data.stateParams.isGiftCard;
$scope.isGlidera = data.stateParams.isGlidera;
$scope.glideraAccessToken = data.stateParams.glideraAccessToken;
$scope.cardId = data.stateParams.cardId;
$scope.showMenu = $ionicHistory.backView().stateName == 'tabs.send'; $scope.showMenu = $ionicHistory.backView().stateName == 'tabs.send';
$scope.isWallet = data.stateParams.isWallet; $scope.isWallet = data.stateParams.isWallet;
$scope.cardId = data.stateParams.cardId;
$scope.toAddress = data.stateParams.toAddress; $scope.toAddress = data.stateParams.toAddress;
$scope.toName = data.stateParams.toName; $scope.toName = data.stateParams.toName;
$scope.toEmail = data.stateParams.toEmail; $scope.toEmail = data.stateParams.toEmail;
$scope.showAlternativeAmount = !!$scope.cardId || !!$scope.isGiftCard; $scope.showAlternativeAmount = !!$scope.cardId || !!$scope.isGiftCard || !!$scope.isGlidera;
$scope.toColor = data.stateParams.toColor; $scope.toColor = data.stateParams.toColor;
$scope.customAmount = data.stateParams.customAmount; $scope.customAmount = data.stateParams.customAmount;
if (!$scope.cardId && !$scope.isGiftCard && !data.stateParams.toAddress) { if (!$scope.cardId && !$scope.isGiftCard && !$scope.isGlidera && !data.stateParams.toAddress) {
$log.error('Bad params at amount') $log.error('Bad params at amount')
throw ('bad params'); throw ('bad params');
} }
glideraService.getLimits($scope.glideraAccessToken, function(err, limits) {
$scope.limits = limits;
$timeout(function() {
$scope.$apply();
});
});
var reNr = /^[1234567890\.]$/; var reNr = /^[1234567890\.]$/;
var reOp = /^[\*\+\-\/]$/; var reOp = /^[\*\+\-\/]$/;
@ -325,6 +334,12 @@ angular.module('copayApp.controllers').controller('amountController', function($
}, true); }, true);
}); });
}); });
} else if ($scope.isGlidera) {
$state.transitionTo('tabs.buyandsell.glidera.confirm', {
toAmount: (amount * unitToSatoshi).toFixed(0),
glideraBuy: true,
glideraAccessToken: $scope.glideraAccessToken
});
} else { } else {
var amount = $scope.showAlternativeAmount ? fromFiat(_amount) : _amount; var amount = $scope.showAlternativeAmount ? fromFiat(_amount) : _amount;
if ($scope.customAmount) { if ($scope.customAmount) {

View file

@ -9,65 +9,65 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
this.success = null; this.success = null;
$scope.network = glideraService.getEnvironment(); $scope.network = glideraService.getEnvironment();
$scope.$on('Wallet/Changed', function(event, w) { // $scope.$on('Wallet/Changed', function(event, w) {
if (lodash.isEmpty(w)) { // if (lodash.isEmpty(w)) {
$log.debug('No wallet provided'); // $log.debug('No wallet provided');
return; // return;
} // }
wallet = w; // wallet = w;
$log.debug('Wallet changed: ' + w.name); // $log.debug('Wallet changed: ' + w.name);
}); // });
//
$scope.update = function(opts) { // $scope.update = function(opts) {
if (!$scope.token || !$scope.permissions) return; // if (!$scope.token || !$scope.permissions) return;
$log.debug('Updating Glidera Account...'); // $log.debug('Updating Glidera Account...');
var accessToken = $scope.token; // var accessToken = $scope.token;
var permissions = $scope.permissions; // var permissions = $scope.permissions;
//
opts = opts || {}; // opts = opts || {};
//
glideraService.getStatus(accessToken, function(err, data) { // glideraService.getStatus(accessToken, function(err, data) {
$scope.status = data; // $scope.status = data;
}); // });
//
glideraService.getLimits(accessToken, function(err, limits) { // glideraService.getLimits(accessToken, function(err, limits) {
$scope.limits = limits; // $scope.limits = limits;
}); // });
//
if (permissions.transaction_history) { // if (permissions.transaction_history) {
glideraService.getTransactions(accessToken, function(err, data) { // glideraService.getTransactions(accessToken, function(err, data) {
$scope.txs = data; // $scope.txs = data;
}); // });
} // }
//
if (permissions.view_email_address && opts.fullUpdate) { // if (permissions.view_email_address && opts.fullUpdate) {
glideraService.getEmail(accessToken, function(err, data) { // glideraService.getEmail(accessToken, function(err, data) {
$scope.email = data.email; // $scope.email = data.email;
}); // });
} // }
if (permissions.personal_info && opts.fullUpdate) { // if (permissions.personal_info && opts.fullUpdate) {
glideraService.getPersonalInfo(accessToken, function(err, data) { // glideraService.getPersonalInfo(accessToken, function(err, data) {
$scope.personalInfo = data; // $scope.personalInfo = data;
}); // });
} // }
}; // };
//
this.getBuyPrice = function(token, price) { // this.getBuyPrice = function(token, price) {
var self = this; // var self = this;
if (!price || (price && !price.qty && !price.fiat)) { // if (!price || (price && !price.qty && !price.fiat)) {
this.buyPrice = null; // this.buyPrice = null;
return; // return;
} // }
this.gettingBuyPrice = true; // this.gettingBuyPrice = true;
glideraService.buyPrice(token, price, function(err, buyPrice) { // glideraService.buyPrice(token, price, function(err, buyPrice) {
self.gettingBuyPrice = false; // self.gettingBuyPrice = false;
if (err) { // if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not get exchange information. Please, try again')); // popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not get exchange information. Please, try again'));
return; // return;
} // }
self.buyPrice = buyPrice; // self.buyPrice = buyPrice;
}); // });
}; // };
this.get2faCode = function(token) { this.get2faCode = function(token) {
var self = this; var self = this;
@ -116,7 +116,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
}, 100); }, 100);
}; };
$scope.$on("$ionicView.enter", function(event, data){ $scope.$on("$ionicView.enter", function(event, data) {
$scope.token = null; $scope.token = null;
$scope.permissions = null; $scope.permissions = null;
$scope.email = null; $scope.email = null;
@ -134,7 +134,9 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
} }
$scope.token = glidera.token; $scope.token = glidera.token;
$scope.permissions = glidera.permissions; $scope.permissions = glidera.permissions;
$scope.update({fullUpdate: true}); $scope.update({
fullUpdate: true
});
}); });
$scope.wallets = profileService.getWallets({ $scope.wallets = profileService.getWallets({

View file

@ -21,6 +21,8 @@ angular.module('copayApp.controllers').controller('confirmController', function(
giftCardInvoiceTime = data.stateParams.giftCardInvoiceTime; giftCardInvoiceTime = data.stateParams.giftCardInvoiceTime;
giftCardUUID = data.stateParams.giftCardUUID; giftCardUUID = data.stateParams.giftCardUUID;
// Glidera parameters
toAmount = data.stateParams.toAmount; toAmount = data.stateParams.toAmount;
cachedSendMax = {}; cachedSendMax = {};
$scope.useSendMax = data.stateParams.useSendMax == 'true' ? true : false; $scope.useSendMax = data.stateParams.useSendMax == 'true' ? true : false;
@ -131,6 +133,23 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$scope.displayAmount = $scope.displayUnit = $scope.fee = $scope.alternativeAmountStr = $scope.insufficientFunds = $scope.noMatchingWallet = null; $scope.displayAmount = $scope.displayUnit = $scope.fee = $scope.alternativeAmountStr = $scope.insufficientFunds = $scope.noMatchingWallet = null;
}; };
$scope.getBuyPrice = function(token, price) {
if (!price || (price && !price.qty && !price.fiat)) {
$scope.buyPrice = null;
return;
}
$scope.gettingBuyPrice = true;
glideraService.buyPrice(token, price, function(err, buyPrice) {
$scope.gettingBuyPrice = false;
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not get exchange information. Please, try again'));
return;
}
$scope.buyPrice = buyPrice;
});
};
$scope.getSendMaxInfo = function() { $scope.getSendMaxInfo = function() {
resetValues(); resetValues();
@ -537,6 +556,24 @@ angular.module('copayApp.controllers').controller('confirmController', function(
} }
}; };
$scope.get2faCode = function(token, cb) {
ongoingProcess.set('Sending 2FA code...', true);
$timeout(function() {
glideraService.get2faCode(token, function(err, sent) {
ongoingProcess.set('Sending 2FA code...', false);
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not send confirmation code to your phone'));
return;
}
var title = gettextCatalog.getString("Please, enter the code below");
var message = gettextCatalog.getString("A SMS containing a confirmation code was sent to your phone.");
popupService.showPrompt(title, message, null, function(code) {
return cb(code);
});
});
}, 100);
};
function publishAndSign(wallet, txp, onSendStatusChange) { function publishAndSign(wallet, txp, onSendStatusChange) {
walletService.publishAndSign(wallet, txp, function(err, txp) { walletService.publishAndSign(wallet, txp, function(err, txp) {
if (err) return setSendError(err); if (err) return setSendError(err);

View file

@ -899,13 +899,40 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
} }
}) })
.state('tabs.buyandsell.glidera.sell', { .state('tabs.buyandsell.glidera.sell', {
url: '/sell', url: '/sell/:glideraSell/:glideraAccessToken',
views: { views: {
'tab-home@tabs': { 'tab-home@tabs': {
controller: 'sellGlideraController', controller: 'sellGlideraController',
controllerAs: 'sell', controllerAs: 'sell',
templateUrl: 'views/sellGlidera.html' templateUrl: 'views/sellGlidera.html'
} }
},
params: {
isGlidera: true
}
})
.state('tabs.buyandsell.glidera.amount', {
url: '/amount/:glideraBuy/:glideraAccessToken',
views: {
'tab-home@tabs': {
controller: 'amountController',
templateUrl: 'views/amount.html'
}
},
params: {
isGlidera: true
}
})
.state('tabs.buyandsell.glidera.confirm', {
url: '/confirm/:toAmount/:glideraBuy/:glideraAccessToken',
views: {
'tab-home@tabs': {
controller: 'confirmController',
templateUrl: 'views/confirm.html'
}
},
params: {
isGlidera: true
} }
}) })
.state('tabs.preferences.glidera', { .state('tabs.preferences.glidera', {

View file

@ -16,7 +16,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
* Development: 'testnet' * Development: 'testnet'
* Production: 'livenet' * Production: 'livenet'
*/ */
credentials.NETWORK = 'livenet'; credentials.NETWORK = 'testnet';
if (credentials.NETWORK == 'testnet') { if (credentials.NETWORK == 'testnet') {
credentials.HOST = glidera.sandbox.host; credentials.HOST = glidera.sandbox.host;

View file

@ -37,7 +37,7 @@
position: absolute; position: absolute;
top: 10px; top: 10px;
} }
.amount-pane-send { .amount-pane-recipient {
position: absolute; position: absolute;
top: 95px; top: 95px;
bottom: 0; bottom: 0;
@ -68,7 +68,7 @@
} }
} }
} }
.amount-pane-receive { .amount-pane-no-recipient {
position: absolute; position: absolute;
top: 0; top: 0;
bottom: 0; bottom: 0;
@ -84,6 +84,10 @@
padding-top: 10px; padding-top: 10px;
color: $dark-gray; color: $dark-gray;
font-weight: bold; font-weight: bold;
.limits {
margin-top: 20px;
color: $light-gray;
}
} }
} }
.amount { .amount {

View file

@ -14,14 +14,14 @@
<ion-content scroll="false"> <ion-content scroll="false">
<div ng-if="!customAmount"> <div ng-if="!customAmount && !isGlidera">
<div class="item item-no-bottom-border recipient-label" translate>Recipient</div> <div class="item item-no-bottom-border recipient-label" translate>Recipient</div>
<div class="item item-text-wrap item-icon-left bitcoin-address" ng-class="{'item-big-icon-left':cardId}"> <div class="item item-text-wrap item-icon-left bitcoin-address" ng-class="{'item-big-icon-left':cardId}">
<i class="icon big-icon-svg" ng-if="isWallet"> <i class="icon big-icon-svg" ng-if="isWallet">
<img src="img/icon-wallet.svg" ng-style="{'background-color': toColor}" class="bg"/> <img src="img/icon-wallet.svg" ng-style="{'background-color': toColor}" class="bg"/>
</i> </i>
<span ng-if="!isWallet && !isGiftCard"> <span ng-if="!isWallet && !isGiftCard && !isGlidera">
<gravatar ng-if="!cardId" class="send-gravatar" name="{{toName}}" height="30" width="30" email="{{toEmail}}"></gravatar> <gravatar ng-if="!cardId" class="send-gravatar" name="{{toName}}" height="30" width="30" email="{{toEmail}}"></gravatar>
<i ng-if="cardId" class="icon big-icon-svg"> <i ng-if="cardId" class="icon big-icon-svg">
<div class="bg icon-bitpay-card"></div> <div class="bg icon-bitpay-card"></div>
@ -36,12 +36,21 @@
</div> </div>
</div> </div>
<div ng-class="{'amount-pane-send': !customAmount, 'amount-pane-receive': customAmount}"> <div ng-class="{'amount-pane-recipient': !customAmount && !isGlidera, 'amount-pane-no-recipient': customAmount || isGlidera}">
<div class="amount-bar oh"> <div class="amount-bar oh">
<div class="title"> <div class="title">
<span translate>Amount</span> <span translate>Amount</span>
<span ng-show="isGiftCard" class="size-12">(Purchase Amount is limited to USD 500 per day)</span> <span ng-show="isGiftCard">(Purchase Amount is limited to USD 500 per day)</span>
<div ng-show="isGlidera" class="limits">
<span>Daily buy limit</span>:
{{limits.dailyBuy|currency:'':2}} {{limits.currency}}
(remaining {{limits.dailyBuyRemaining|currency:'':2}} {{limits.currency}})
<br>
<span>Monthly buy limit</span>:
{{limits.monthlyBuy|currency:'':2}} {{limits.currency}}
(remaining {{limits.monthlyBuyRemaining|currency:'':2}} {{limits.currency}})
</div>
</div> </div>
</div> </div>
@ -62,6 +71,7 @@
</div> </div>
</div> </div>
<div class="keypad"> <div class="keypad">
<div class="row"> <div class="row">
<div class="col col-25 col-offset-75 operator-send" <div class="col col-25 col-offset-75 operator-send"

View file

@ -75,18 +75,32 @@
ng-show="status && status.userCanTransact"> ng-show="status && status.userCanTransact">
<a ng-show="status.userCanBuy" <a ng-show="status.userCanBuy"
class="item item-icon-right" class="item item-icon-right"
href ui-sref="tabs.buyandsell.glidera.buy"> href ui-sref="tabs.buyandsell.glidera.amount({glideraBuy: true, glideraAccessToken: token})">
<img src="img/buy-bitcoin.svg" alt="buy bitcoin" width="45" class="item-img-buy"> <img src="img/buy-bitcoin.svg" alt="buy bitcoin" width="45" class="item-img-buy">
Buy Bitcoin Buy Bitcoin
<i class="icon bp-arrow-right"></i> <i class="icon bp-arrow-right"></i>
</a> </a>
<a class="item item-icon-right" <a class="item item-icon-right"
ng-show="status.userCanSell" ng-show="status.userCanSell"
href ui-sref="tabs.buyandsell.glidera.sell"> href ui-sref="tabs.buyandsell.glidera.amount({glideraSell: true, glideraAccessToken: token})">
<img src="img/sell-bitcoin.svg" alt="buy bitcoin" width="45" class="item-img-sell"> <img src="img/sell-bitcoin.svg" alt="buy bitcoin" width="45" class="item-img-sell">
Sell Bitcoin Sell Bitcoin
<i class="icon bp-arrow-right"></i> <i class="icon bp-arrow-right"></i>
</a> </a>
<a ng-show="status.userCanBuy"
class="item item-icon-right"
href ui-sref="tabs.buyandsell.glidera.buy">
<img src="img/buy-bitcoin.svg" alt="buy bitcoin" width="45" class="item-img-buy">
Buy Bitcoin OLD
<i class="icon bp-arrow-right"></i>
</a>
<a class="item item-icon-right"
ng-show="status.userCanSell"
href ui-sref="tabs.buyandsell.glidera.sell">
<img src="img/sell-bitcoin.svg" alt="buy bitcoin" width="45" class="item-img-sell">
Sell Bitcoin OLD
<i class="icon bp-arrow-right"></i>
</a>
</div> </div>
<div class="list card" ng-show="permissions && permissions.transaction_history && txs.length > 0"> <div class="list card" ng-show="permissions && permissions.transaction_history && txs.length > 0">