From 92737bc49cd44bdf15eda680e6445815b2a2eaee Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Mon, 1 Dec 2014 05:24:19 -0300 Subject: [PATCH] Trying to fix bip72 --- js/controllers/paymentIntent.js | 39 +++++++++++++++---------------- js/controllers/send.js | 41 +++++++++++++++++++-------------- js/models/Wallet.js | 2 +- views/homeWallet.html | 4 ++-- views/modals/qr-address.html | 2 +- views/paymentIntent.html | 1 + views/profile.html | 2 +- views/send.html | 2 +- 8 files changed, 50 insertions(+), 43 deletions(-) diff --git a/js/controllers/paymentIntent.js b/js/controllers/paymentIntent.js index 2fe6f71c1..79f9e9435 100644 --- a/js/controllers/paymentIntent.js +++ b/js/controllers/paymentIntent.js @@ -2,27 +2,12 @@ angular.module('copayApp.controllers').controller('PaymentIntentController', function($rootScope, $scope, $modal, $location, balanceService) { - $scope.wallets = []; - $rootScope.title = 'Payment intent'; - $scope.wallets = $rootScope.iden.listWallets(); + $rootScope.title = 'Payment intent'; - var l = $scope.wallet.length; - _.each($scope.wallets, function(w, i) { - balanceService.update(w, function(){ - if (i === l-1) - $rootScope.$digest(); - }); - }); - - $scope.open = function() { + $scope.open = function() { var modalInstance = $modal.open({ templateUrl: 'myModalContent.html', - controller: ModalInstanceCtrl, - resolve: { - items: function() { - return $scope.wallets; - } - } + controller: ModalInstanceCtrl }); }; @@ -30,8 +15,22 @@ angular.module('copayApp.controllers').controller('PaymentIntentController', fun // Please note that $modalInstance represents a modal window (instance) dependency. // It is not the same as the $modal service used above. - var ModalInstanceCtrl = function($scope, $modalInstance, items, identityService) { - $scope.wallets = items; + var ModalInstanceCtrl = function($scope, $modalInstance, identityService) { + $scope.loading = true; + $scope.setWallets = function() { + if (!$rootScope.iden) return; + var ret = _.filter($rootScope.iden.listWallets(), function(w) { + return w.balanceInfo && w.balanceInfo.totalBalanceBTC; + }); + $scope.wallets = ret; + $scope.loading = false; + }; + if ($rootScope.iden) { + var iden = $rootScope.iden; + iden.on('newWallet', function() { + $scope.setWallets(); + }); + } $scope.ok = function(selectedItem) { identityService.setPaymentWallet(selectedItem); $modalInstance.close(); diff --git a/js/controllers/send.js b/js/controllers/send.js index 8c3879bfc..f1aec87ff 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -11,10 +11,10 @@ angular.module('copayApp.controllers').controller('SendController', $rootScope.title = 'Send'; $scope.loading = false; $scope.error = $scope.success = null; - var satToUnit = 1 / w.settings.unitToSatoshi; + var unitToSatoshi = w.settings.unitToSatoshi; + var satToUnit = 1 / unitToSatoshi; $scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT * satToUnit; - $scope.unitToBtc = w.settings.unitToSatoshi / bitcore.util.COIN; - $scope.unitToSatoshi = w.settings.unitToSatoshi; + $scope.unitToBtc = unitToSatoshi / bitcore.util.COIN; $scope.alternativeName = w.settings.alternativeName; $scope.alternativeIsoCode = w.settings.alternativeIsoCode; @@ -33,9 +33,9 @@ angular.module('copayApp.controllers').controller('SendController', $scope.setAlternativeAmount = function(w, tx, cb) { rateService.whenAvailable(function() { _.each(tx.outs, function(out) { - var valueSat = out.value * w.settings.unitToSatoshi; - out.alternativeAmount = rateService.toFiat(valueSat, w.settings.alternativeIsoCode); - out.alternativeIsoCode = w.settings.alternativeIsoCode; + var valueSat = out.value * unitToSatoshi; + out.alternativeAmount = rateService.toFiat(valueSat, $scope.alternativeIsoCode); + out.alternativeIsoCode = $scope.alternativeIsoCode; }); if (cb) return cb(tx); }); @@ -78,7 +78,7 @@ console.log('[send.js.44:updateTxs:]'); //TODO this._alternative = newValue; if (typeof(newValue) === 'number' && $scope.isRateAvailable) { this._amount = parseFloat( - (rateService.fromFiat(newValue, w.settings.alternativeIsoCode) * satToUnit).toFixed(w.settings.unitDecimals), 10); + (rateService.fromFiat(newValue, $scope.alternativeIsoCode) * satToUnit).toFixed(w.settings.unitDecimals), 10); } else { this._amount = 0; } @@ -96,7 +96,7 @@ console.log('[send.js.44:updateTxs:]'); //TODO if (typeof(newValue) === 'number' && $scope.isRateAvailable) { this._alternative = parseFloat( - (rateService.toFiat(newValue * w.settings.unitToSatoshi, w.settings.alternativeIsoCode)).toFixed(2), 10); + (rateService.toFiat(newValue * unitToSatoshi, $scope.alternativeIsoCode)).toFixed(2), 10); } else { this._alternative = 0; } @@ -124,12 +124,19 @@ console.log('[send.js.44:updateTxs:]'); //TODO if ($rootScope.pendingPayment) { var pp = $rootScope.pendingPayment; - $scope.address = pp.address + ''; - var amount = pp.data.amount / w.settings.unitToSatoshi * 100000000; - $scope.amount = $filter('noFractionNumber')(amount); - var alternativeAmount = rateService.toFiat((amount + defaultFee) * unitToSatoshi, alternativeIsoCode); - $scope.alternativeAmountPayPro = $filter('noFractionNumber')(alternativeAmount, 2); + var amount = pp.data.amount * 100000000 * satToUnit; + var alternativeAmountPayPro = rateService.toFiat((amount + $scope.defaultFee) * unitToSatoshi, $scope.alternativeIsoCode); + if (pp.data.merchant) { + $scope.address = 'bitcoin:' + pp.address.data + '?amount=' + amount + '&r=' + pp.data.r; + } + else { + $scope.address = pp.address + ''; + $scope.amount = amount; + $scope.alternative = alternativeAmountPayPro; + } + $scope.alternativeAmountPayPro = $filter('noFractionNumber')(alternativeAmountPayPro, 2); $scope.commentText = pp.data.message; + $scope.onChanged(); } navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; @@ -165,7 +172,7 @@ console.log('[send.js.44:updateTxs:]'); //TODO $scope.loading = true; var address = form.address.$modelValue; - var amount = parseInt((form.amount.$modelValue * w.settings.unitToSatoshi).toFixed(0)); + var amount = parseInt((form.amount.$modelValue * unitToSatoshi).toFixed(0)); var commentText = form.comment.$modelValue; @@ -539,7 +546,7 @@ console.log('[send.js.44:updateTxs:]'); //TODO apply(); var balance = $rootScope.availableBalance; - var available = +(balance * w.settings.unitToSatoshi).toFixed(0); + var available = +(balance * unitToSatoshi).toFixed(0); if (merchantData && available < +merchantData.total) { err = new Error('Insufficient funds.'); err.amount = merchantData.total; @@ -547,7 +554,7 @@ console.log('[send.js.44:updateTxs:]'); //TODO if (err) { if (err.amount) { - $scope.sendForm.amount.$setViewValue(+err.amount / w.settings.unitToSatoshi); + $scope.sendForm.amount.$setViewValue(+err.amount / unitToSatoshi); $scope.sendForm.amount.$render(); $scope.sendForm.amount.$isValid = false; $scope.notEnoughAmount = true; @@ -578,7 +585,7 @@ console.log('[send.js.44:updateTxs:]'); //TODO var url = merchantData.request_url; var domain = /^(?:https?)?:\/\/([^\/:]+).*$/.exec(url)[1]; - merchantData.unitTotal = (+merchantData.total / w.settings.unitToSatoshi) + ''; + merchantData.unitTotal = (+merchantData.total / unitToSatoshi) + ''; merchantData.expiration = new Date( merchantData.pr.pd.expires * 1000); merchantData.domain = domain; diff --git a/js/models/Wallet.js b/js/models/Wallet.js index 6c96a9b2a..be28d3808 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -629,7 +629,7 @@ Wallet.prototype._onAddressBook = function(senderId, data) { var self = this, hasChange; _.each(data.addressBook, function(value, key) { - if (!self.addressBook[key] && Address.validate(key)) { + if (key && !self.addressBook[key] && Address.validate(key)) { self.addressBook[key] = _.pick(value, ['createdTs', 'label']); diff --git a/views/homeWallet.html b/views/homeWallet.html index bba7198e8..5563d1fd5 100644 --- a/views/homeWallet.html +++ b/views/homeWallet.html @@ -17,13 +17,13 @@
- {{$root.wallet.balanceInfo.totalBalance || 0 |noFractionNumber}} + {{$root.wallet.balanceInfo.totalBalance || 0}} {{$root.wallet.settings.unitName}} - {{$root.wallet.balanceInfo.totalBalanceAlternative |noFractionNumber:2}} {{$root.wallet.balanceInfo.alternativeIsoCode}} + {{$root.wallet.balanceInfo.totalBalanceAlternative}} {{$root.wallet.balanceInfo.alternativeIsoCode}} N/A diff --git a/views/modals/qr-address.html b/views/modals/qr-address.html index fb82d6b03..d52da6d03 100644 --- a/views/modals/qr-address.html +++ b/views/modals/qr-address.html @@ -13,7 +13,7 @@ - {{address.balance || 0|noFractionNumber}} {{$root.wallet.settings.unitName}} + {{address.balance || 0}} {{$root.wallet.settings.unitName}}

diff --git a/views/paymentIntent.html b/views/paymentIntent.html index cd267745a..4a1fb750a 100644 --- a/views/paymentIntent.html +++ b/views/paymentIntent.html @@ -1,6 +1,7 @@