refactor confirm view
This commit is contained in:
parent
ff4b93acbe
commit
090b05984b
7 changed files with 164 additions and 104 deletions
|
|
@ -340,6 +340,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else if ($scope.isGlidera) {
|
} else if ($scope.isGlidera) {
|
||||||
|
var amount = $scope.showAlternativeAmount ? fromFiat(_amount) : _amount;
|
||||||
$state.transitionTo('tabs.buyandsell.glidera.confirm', {
|
$state.transitionTo('tabs.buyandsell.glidera.confirm', {
|
||||||
toAmount: (amount * unitToSatoshi).toFixed(0),
|
toAmount: (amount * unitToSatoshi).toFixed(0),
|
||||||
glideraBuy: $scope.glideraBuy,
|
glideraBuy: $scope.glideraBuy,
|
||||||
|
|
|
||||||
|
|
@ -9,80 +9,80 @@ 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) {
|
|
||||||
// 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) {
|
$scope.update = function(opts) {
|
||||||
// var self = this;
|
if (!$scope.token || !$scope.permissions) return;
|
||||||
// ongoingProcess.set('Sending 2FA code...', true);
|
$log.debug('Updating Glidera Account...');
|
||||||
// $timeout(function() {
|
var accessToken = $scope.token;
|
||||||
// glideraService.get2faCode(token, function(err, sent) {
|
var permissions = $scope.permissions;
|
||||||
// ongoingProcess.set('Sending 2FA code...', false);
|
|
||||||
// if (err) {
|
opts = opts || {};
|
||||||
// popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not send confirmation code to your phone'));
|
|
||||||
// return;
|
glideraService.getStatus(accessToken, function(err, data) {
|
||||||
// }
|
$scope.status = data;
|
||||||
// self.show2faCodeInput = sent;
|
});
|
||||||
// });
|
|
||||||
// }, 100);
|
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) {
|
this.sendRequest = function(token, permissions, twoFaCode) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'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 cachedTxp = {};
|
||||||
var toAmount;
|
var toAmount;
|
||||||
var isChromeApp = platformInfo.isChromeApp;
|
var isChromeApp = platformInfo.isChromeApp;
|
||||||
|
|
@ -24,6 +24,8 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
// Glidera parameters
|
// Glidera parameters
|
||||||
$scope.isGlidera = data.stateParams.isGlidera;
|
$scope.isGlidera = data.stateParams.isGlidera;
|
||||||
$scope.glideraAccessToken = data.stateParams.glideraAccessToken;
|
$scope.glideraAccessToken = data.stateParams.glideraAccessToken;
|
||||||
|
$scope.glideraBuy = data.stateParams.glideraBuy;
|
||||||
|
$scope.glideraSell = data.stateParams.glideraSell;
|
||||||
|
|
||||||
toAmount = data.stateParams.toAmount;
|
toAmount = data.stateParams.toAmount;
|
||||||
cachedSendMax = {};
|
cachedSendMax = {};
|
||||||
|
|
@ -46,7 +48,8 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
|
|
||||||
var config = configService.getSync().wallet;
|
var config = configService.getSync().wallet;
|
||||||
$scope.feeLevel = config.settings && config.settings.feeLevel ? config.settings.feeLevel : 'normal';
|
$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();
|
resetValues();
|
||||||
setwallets();
|
setwallets();
|
||||||
});
|
});
|
||||||
|
|
@ -129,29 +132,13 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
txFormatService.formatAlternativeStr(toAmount, function(v) {
|
txFormatService.formatAlternativeStr(toAmount, function(v) {
|
||||||
$scope.alternativeAmountStr = v;
|
$scope.alternativeAmountStr = v;
|
||||||
});
|
});
|
||||||
|
if ($scope.isGlidera && $scope.glideraBuy) $scope.getBuyPrice();
|
||||||
};
|
};
|
||||||
|
|
||||||
function resetValues() {
|
function resetValues() {
|
||||||
$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();
|
||||||
|
|
||||||
|
|
@ -330,6 +317,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
$scope.wallet = wallet;
|
$scope.wallet = wallet;
|
||||||
$scope.fee = $scope.txp = null;
|
$scope.fee = $scope.txp = null;
|
||||||
|
|
||||||
|
if ($scope.isGlidera) return;
|
||||||
if (stop) {
|
if (stop) {
|
||||||
$timeout.cancel(stop);
|
$timeout.cancel(stop);
|
||||||
stop = null;
|
stop = null;
|
||||||
|
|
@ -445,6 +433,32 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
return;
|
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;
|
var wallet = $scope.wallet;
|
||||||
if (!wallet) {
|
if (!wallet) {
|
||||||
return setSendError(gettextCatalog.getString('No wallet selected'));
|
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);
|
ongoingProcess.set('Sending 2FA code...', true);
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
glideraService.get2faCode(token, function(err, sent) {
|
glideraService.get2faCode($scope.glideraAccessToken, function(err, sent) {
|
||||||
ongoingProcess.set('Sending 2FA code...', false);
|
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) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
var title = gettextCatalog.getString("Please, enter the code below");
|
var data = {
|
||||||
var message = gettextCatalog.getString("A SMS containing a confirmation code was sent to your phone.");
|
destinationAddress: walletAddr,
|
||||||
popupService.showPrompt(title, message, null, function(code) {
|
qty: $scope.buyPrice.qty,
|
||||||
return cb(code);
|
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);
|
}, 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) {
|
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);
|
||||||
|
|
|
||||||
|
|
@ -924,7 +924,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.state('tabs.buyandsell.glidera.confirm', {
|
.state('tabs.buyandsell.glidera.confirm', {
|
||||||
url: '/confirm/:toAmount/:glideraBuy/:glideraAccessToken',
|
url: '/confirm/:toAmount/:glideraBuy/:glideraSell/:glideraAccessToken',
|
||||||
views: {
|
views: {
|
||||||
'tab-home@tabs': {
|
'tab-home@tabs': {
|
||||||
controller: 'confirmController',
|
controller: 'confirmController',
|
||||||
|
|
|
||||||
|
|
@ -192,8 +192,13 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
|
||||||
};
|
};
|
||||||
|
|
||||||
root.get2faCode = function(token, cb) {
|
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) {
|
$http(_get('/authentication/get2faCode', token)).then(function(data) {
|
||||||
|
|
||||||
$log.info('Glidera Sent 2FA code by SMS: SUCCESS');
|
$log.info('Glidera Sent 2FA code by SMS: SUCCESS');
|
||||||
return cb(null, data.status == 200 ? true : false);
|
return cb(null, data.status == 200 ? true : false);
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,11 @@
|
||||||
color: #9B9B9B;
|
color: #9B9B9B;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.buy-price {
|
||||||
|
bottom: 20px;
|
||||||
|
position: absolute;
|
||||||
|
color: $light-gray;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.item {
|
.item {
|
||||||
border-color: $item-border-color;
|
border-color: $item-border-color;
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,11 @@
|
||||||
<div class="amount">{{displayAmount || '...'}} <span class="unit">{{displayUnit}}</span></div>
|
<div class="amount">{{displayAmount || '...'}} <span class="unit">{{displayUnit}}</span></div>
|
||||||
<div class="alternative">{{alternativeAmountStr || '...'}}</div>
|
<div class="alternative">{{alternativeAmountStr || '...'}}</div>
|
||||||
</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>
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<div class="item single-line" ng-if="paypro">
|
<div class="item single-line" ng-if="paypro">
|
||||||
|
|
@ -29,11 +34,12 @@
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<span class="label" translate>To</span>
|
<span class="label" translate>To</span>
|
||||||
<span class="payment-proposal-to">
|
<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">
|
<img ng-if="cardId" src="img/icon-card.svg" width="34">
|
||||||
<i ng-if="isGiftCard" class="icon big-icon-svg">
|
<i ng-if="isGiftCard" class="icon big-icon-svg">
|
||||||
<div class="bg icon-amazon"></div>
|
<div class="bg icon-amazon"></div>
|
||||||
</i>
|
</i>
|
||||||
|
<img ng-if="isGlidera" src="img/glidera-logo.png" width="90"/>
|
||||||
|
|
||||||
<div copy-to-clipboard="toAddress" ng-if="!paypro" class="ellipsis">
|
<div copy-to-clipboard="toAddress" ng-if="!paypro" class="ellipsis">
|
||||||
<contact ng-if="!toName" address="{{toAddress}}"></contact>
|
<contact ng-if="!toName" address="{{toAddress}}"></contact>
|
||||||
|
|
@ -67,7 +73,7 @@
|
||||||
</span>
|
</span>
|
||||||
<i class="icon bp-arrow-right"></i>
|
<i class="icon bp-arrow-right"></i>
|
||||||
</a>
|
</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="label" translate>Fee: {{feeLevel}}</span>
|
||||||
<span class="item-note">
|
<span class="item-note">
|
||||||
{{fee || '...'}}
|
{{fee || '...'}}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue