From 3bc3552129bea069a22f166ae7516913d759be43 Mon Sep 17 00:00:00 2001 From: Javier Date: Tue, 23 Aug 2016 16:15:10 -0300 Subject: [PATCH] add wallet widget in confirm (send) view --- public/views/amount.html | 8 ++- public/views/confirm.html | 30 ++++++----- src/js/controllers/confirm.js | 93 ++++++++++++++--------------------- 3 files changed, 57 insertions(+), 74 deletions(-) diff --git a/public/views/amount.html b/public/views/amount.html index 56d6cb15c..373eacf42 100644 --- a/public/views/amount.html +++ b/public/views/amount.html @@ -2,11 +2,9 @@ Enter Amount - - - @@ -17,7 +15,7 @@
- Recipient + Recipient
diff --git a/public/views/confirm.html b/public/views/confirm.html index b13559c79..f52529809 100644 --- a/public/views/confirm.html +++ b/public/views/confirm.html @@ -3,15 +3,13 @@ Confirm - - -
@@ -24,9 +22,15 @@
Fee: {{feeLevel}} +<<<<<<< eb8c739515d024200f5ea2bad72fffb21437375b {{fee || '...'}} +======= + + {{fee || '...'}} + +>>>>>>> add wallet widget in confirm (send) view
@@ -42,11 +46,10 @@
- + -

[Only showing testnet wallets]

-

[Filtering wallets with no enought balance]

+<<<<<<< eb8c739515d024200f5ea2bad72fffb21437375b
@@ -66,6 +69,9 @@
+======= + +>>>>>>> add wallet widget in confirm (send) view
Add Description @@ -75,11 +81,11 @@
-
- - -
+
+
- diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index 59e79202f..c11c545bd 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -42,7 +42,6 @@ angular.module('copayApp.controllers').controller('confirmController', function( }; }; - var setFromPayPro = function(uri, cb) { if (!cb) cb = function() {}; @@ -92,9 +91,8 @@ angular.module('copayApp.controllers').controller('confirmController', function( }); }; - - $scope.init = function() { + $scope.wallet = profileService.getWallets()[0]; if ($stateParams.paypro) { return setFromPayPro($stateParams.paypro, function(err) { @@ -125,61 +123,48 @@ angular.module('copayApp.controllers').controller('confirmController', function( var network = (new bitcore.Address($scope.toAddress)).network.name; $scope.network = network; - function setWallets() { - var w = profileService.getWallets({ - onlyComplete: true, - network: network, - }); - $scope.wallets = lodash.filter(w, function(x) { - if (!x.availableBalanceSat) return true; - return x.availableBalanceSat > amount; - }); - - $scope.someFiltered = $scope.wallets.length != w.length; - - }; - - var stop; - - function setWallet(wallet, delayed) { - $scope.wallet = wallet; - $scope.fee = $scope.txp = null; - $timeout(function() { - $scope.$apply(); - }, 10); - - if (stop) { - $timeout.cancel(stop); - stop = null; - } - - if (cachedTxp[wallet.id]) { - apply(cachedTxp[wallet.id]); - } else { - stop = $timeout(function() { - createTx(wallet, function(err, txp) { - if (err) return; - cachedTxp[wallet.id] = txp; - apply(txp); - }); - }, delayed ? 2000 : 1); - } - }; - txFormatService.formatAlternativeStr(amount, function(v) { $scope.alternativeAmountStr = v; }); + }; - $scope.$on("$ionicSlides.slideChangeEnd", function(event, data) { - setWallet($scope.wallets[data.slider.activeIndex], true); - }); + $scope.$on('Wallet/Changed', function(event, wallet) { + $log.debug('Wallet changed: ' + wallet.name); + setWallet(wallet, true); + $scope.$apply(); + }); - setWallets(); - setWallet($scope.wallets[0]); + function setWallet(wallet, delayed) { + var stop; + $scope.wallet = wallet; + $scope.fee = $scope.txp = null; $timeout(function() { - $ionicScrollDelegate.resize(); - }, 100); + $scope.$apply(); + }, 10); + + if (stop) { + $timeout.cancel(stop); + stop = null; + } + + function apply(txp) { + $scope.fee = txFormatService.formatAmountStr(txp.fee); + $scope.txp = txp; + $scope.$apply(); + }; + + if (cachedTxp[wallet.id]) { + apply(cachedTxp[wallet.id]); + } else { + stop = $timeout(function() { + createTx(wallet, $scope.toAddress, $scope.toAmount, $scope.comment || null, function(err, txp) { + if (err) return; + cachedTxp[wallet.id] = txp; + apply(txp); + }); + }, delayed ? 2000 : 1); + } }; var setSendError = function(msg) { @@ -244,7 +229,6 @@ angular.module('copayApp.controllers').controller('confirmController', function( }); }; - $scope.openPPModal = function() { $ionicModal.fromTemplateUrl('views/modals/paypro.html', { scope: $scope @@ -254,8 +238,6 @@ angular.module('copayApp.controllers').controller('confirmController', function( }); }; - - $scope.approve = function() { var wallet = $scope.wallet; var txp = $scope.txp; @@ -287,7 +269,4 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.cancel = function() { $state.transitionTo('tabs.send'); }; - - - });