refactor confirm view

This commit is contained in:
Gabriel Bazán 2016-12-02 14:48:39 -03:00
commit 090b05984b
7 changed files with 164 additions and 104 deletions

View file

@ -340,6 +340,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
});
});
} else if ($scope.isGlidera) {
var amount = $scope.showAlternativeAmount ? fromFiat(_amount) : _amount;
$state.transitionTo('tabs.buyandsell.glidera.confirm', {
toAmount: (amount * unitToSatoshi).toFixed(0),
glideraBuy: $scope.glideraBuy,

View file

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

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, profileService, bitcore, gettext, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, amazonService) {
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, profileService, bitcore, gettext, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, amazonService, glideraService, bwcError) {
var cachedTxp = {};
var toAmount;
var isChromeApp = platformInfo.isChromeApp;
@ -24,6 +24,8 @@ angular.module('copayApp.controllers').controller('confirmController', function(
// Glidera parameters
$scope.isGlidera = data.stateParams.isGlidera;
$scope.glideraAccessToken = data.stateParams.glideraAccessToken;
$scope.glideraBuy = data.stateParams.glideraBuy;
$scope.glideraSell = data.stateParams.glideraSell;
toAmount = data.stateParams.toAmount;
cachedSendMax = {};
@ -46,7 +48,8 @@ angular.module('copayApp.controllers').controller('confirmController', function(
var config = configService.getSync().wallet;
$scope.feeLevel = config.settings && config.settings.feeLevel ? config.settings.feeLevel : 'normal';
$scope.network = (new bitcore.Address($scope.toAddress)).network.name;
if ($scope.isGlidera) $scope.network = glideraService.getEnvironment();
else $scope.network = (new bitcore.Address($scope.toAddress)).network.name;
resetValues();
setwallets();
});
@ -129,29 +132,13 @@ angular.module('copayApp.controllers').controller('confirmController', function(
txFormatService.formatAlternativeStr(toAmount, function(v) {
$scope.alternativeAmountStr = v;
});
if ($scope.isGlidera && $scope.glideraBuy) $scope.getBuyPrice();
};
function resetValues() {
$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() {
resetValues();
@ -330,6 +317,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$scope.wallet = wallet;
$scope.fee = $scope.txp = null;
if ($scope.isGlidera) return;
if (stop) {
$timeout.cancel(stop);
stop = null;
@ -445,6 +433,32 @@ angular.module('copayApp.controllers').controller('confirmController', function(
return;
}
if ($scope.isGlidera) {
$scope.get2faCode(function(err, sent) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not send confirmation code to your phone'));
return;
}
if (sent) {
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(twoFaCode) {
$scope.sendRequest(twoFaCode, function(err, data) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
return;
}
$scope.success = data;
$timeout(function() {
$scope.$digest();
});
})
});
}
});
return;
}
var wallet = $scope.wallet;
if (!wallet) {
return setSendError(gettextCatalog.getString('No wallet selected'));
@ -558,24 +572,53 @@ angular.module('copayApp.controllers').controller('confirmController', function(
}
};
$scope.get2faCode = function(token, cb) {
$scope.get2faCode = function(cb) {
ongoingProcess.set('Sending 2FA code...', true);
$timeout(function() {
glideraService.get2faCode(token, function(err, sent) {
glideraService.get2faCode($scope.glideraAccessToken, function(err, sent) {
ongoingProcess.set('Sending 2FA code...', false);
return cb(err, sent);
});
}, 100);
};
$scope.sendRequest = function(twoFaCode, cb) {
ongoingProcess.set('Buying Bitcoin...', true);
$timeout(function() {
walletService.getAddress($scope.wallet, false, function(err, walletAddr) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not send confirmation code to your phone'));
ongoingProcess.set('Buying Bitcoin...', false);
popupService.showAlert(gettextCatalog.getString('Error'), bwcError.cb(err, 'Could not create address'));
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);
var data = {
destinationAddress: walletAddr,
qty: $scope.buyPrice.qty,
priceUuid: $scope.buyPrice.priceUuid,
useCurrentPrice: false,
ip: null
};
glideraService.buy($scope.glideraAccessToken, twoFaCode, data, function(err, data) {
ongoingProcess.set('Buying Bitcoin...', false);
return cb(err, data)
});
});
}, 100);
};
$scope.getBuyPrice = function() {
var satToBtc = 1 / 100000000;
var price = {};
price.qty = (toAmount * satToBtc).toFixed(8);
glideraService.buyPrice($scope.glideraAccessToken, price, function(err, buyPrice) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not get exchange information. Please, try again'));
return;
}
$scope.buyPrice = buyPrice;
});
};
function publishAndSign(wallet, txp, onSendStatusChange) {
walletService.publishAndSign(wallet, txp, function(err, txp) {
if (err) return setSendError(err);

View file

@ -924,7 +924,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
})
.state('tabs.buyandsell.glidera.confirm', {
url: '/confirm/:toAmount/:glideraBuy/:glideraAccessToken',
url: '/confirm/:toAmount/:glideraBuy/:glideraSell/:glideraAccessToken',
views: {
'tab-home@tabs': {
controller: 'confirmController',

View file

@ -192,8 +192,13 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
};
root.get2faCode = function(token, cb) {
if (!token) return cb('Invalid Token');
if (!token) {
$log.error('Glidera Sent 2FA code by SMS: ERROR Invalid Token');
return cb('Invalid Token');
}
$http(_get('/authentication/get2faCode', token)).then(function(data) {
$log.info('Glidera Sent 2FA code by SMS: SUCCESS');
return cb(null, data.status == 200 ? true : false);
}, function(data) {

View file

@ -47,6 +47,11 @@
color: #9B9B9B;
}
}
.buy-price {
bottom: 20px;
position: absolute;
color: $light-gray;
}
}
.item {
border-color: $item-border-color;

View file

@ -19,6 +19,11 @@
<div class="amount">{{displayAmount || '...'}} <span class="unit">{{displayUnit}}</span></div>
<div class="alternative">{{alternativeAmountStr || '...'}}</div>
</div>
<div ng-show="isGlidera" class="buy-price">
<div ng-show="buyPrice.qty">
Buy {{buyPrice.subtotal|currency:'':2}} {{buyPrice.currency}} in Bitcoin at {{buyPrice.price}} {{buyPrice.currency}}/BTC
</div>
</div>
</div>
<div class="info">
<div class="item single-line" ng-if="paypro">
@ -29,11 +34,12 @@
<div class="item">
<span class="label" translate>To</span>
<span class="payment-proposal-to">
<img ng-if="!cardId && !isGiftCard" src="img/icon-bitcoin-small.svg">
<img ng-if="!cardId && !isGiftCard && !isGlidera" src="img/icon-bitcoin-small.svg">
<img ng-if="cardId" src="img/icon-card.svg" width="34">
<i ng-if="isGiftCard" class="icon big-icon-svg">
<div class="bg icon-amazon"></div>
</i>
<img ng-if="isGlidera" src="img/glidera-logo.png" width="90"/>
<div copy-to-clipboard="toAddress" ng-if="!paypro" class="ellipsis">
<contact ng-if="!toName" address="{{toAddress}}"></contact>
@ -67,7 +73,7 @@
</span>
<i class="icon bp-arrow-right"></i>
</a>
<div class="item single-line" ng-if="!insufficientFunds && !noMatchingWallet">
<div class="item single-line" ng-if="!insufficientFunds && !noMatchingWallet && !isGlidera">
<span class="label" translate>Fee: {{feeLevel}}</span>
<span class="item-note">
{{fee || '...'}}