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..115c8824d 100644 --- a/public/views/confirm.html +++ b/public/views/confirm.html @@ -3,15 +3,13 @@ Confirm - - -
@@ -24,9 +22,9 @@
Fee: {{feeLevel}} - - {{fee || '...'}} - + + {{fee || '...'}} +
@@ -42,30 +40,12 @@
- + -

[Only showing testnet wallets]

-

[Filtering wallets with no enought balance]

-
- -
- - -
-
    -
  • - - {{item.name || item.id}} - - {{item.availableBalanceStr}} - -
  • -
-
-
-
+ Not available
+
Add Description @@ -75,11 +55,9 @@
-
- - -
-
+
- diff --git a/public/views/includes/note.html b/public/views/includes/note.html index e52beba85..451ac6baf 100644 --- a/public/views/includes/note.html +++ b/public/views/includes/note.html @@ -1,11 +1,11 @@
- +
- +
- +
diff --git a/public/views/includes/wallets.html b/public/views/includes/wallets.html new file mode 100644 index 000000000..978d7804e --- /dev/null +++ b/public/views/includes/wallets.html @@ -0,0 +1,16 @@ +
+ + +
+ + {{wallet.name || wallet.id}} + + {{wallet.m}}-of-{{wallet.n}} + + + Incomplete + +
+
+
+
diff --git a/public/views/tab-receive.html b/public/views/tab-receive.html index 8320cb69d..6a3287722 100644 --- a/public/views/tab-receive.html +++ b/public/views/tab-receive.html @@ -3,48 +3,33 @@ Receive - - - -
+ +
+
+ {{error|translate}} +
+
- +
+ +
-
-
-incomplete wallet -
- -
- -
-
- -
-
- -
+
+ No Wallet
-
-
-Error: {{addrError}} -
-
- - -
+
Share address
-
+
Next Address
@@ -53,27 +38,8 @@ Error: {{addrError}} ... {{addr}}
-
-
- - -
-
    -
  • - - {{item.name || item.id}} - - {{item.m}}-of-{{item.n}} - - - Incomplete - -
  • -
-
-
-
+
diff --git a/public/views/tab-send.html b/public/views/tab-send.html index de09b2511..688a84c64 100644 --- a/public/views/tab-send.html +++ b/public/views/tab-send.html @@ -26,7 +26,11 @@
-
+
+ No Wallet - Contact +
+ +
diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index 59e79202f..ae183bc93 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -28,12 +28,14 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.commentPopupClose = function() { commentPopup.close(); }; - $scope.commentPopupSave = function() { - $log.debug('Saving description: ' + $scope.data.comment); - $scope.description = $scope.data.comment; + $scope.commentPopupSave = function(description) { + $log.debug('Saving description: ' + description); + $scope.description = description; $scope.txp = null; + ongoingProcess.set('creatingTx', true); createTx($scope.wallet, function(err, txp) { + ongoingProcess.set('creatingTx', false); if (err) return; cachedTxp[$scope.wallet.id] = txp; apply(txp); @@ -42,7 +44,6 @@ angular.module('copayApp.controllers').controller('confirmController', function( }; }; - var setFromPayPro = function(uri, cb) { if (!cb) cb = function() {}; @@ -92,23 +93,12 @@ angular.module('copayApp.controllers').controller('confirmController', function( }); }; - - $scope.init = function() { - - if ($stateParams.paypro) { - return setFromPayPro($stateParams.paypro, function(err) { - if (err && !isChromeApp) { - showAlert(gettext('Could not fetch payment')); - } - }); - } - + // TODO (URL , etc) if (!$stateParams.toAddress || !$stateParams.toAmount) { $log.error('Bad params at amount') throw ('bad params'); } - $scope.isCordova = platformInfo.isCordova; var config = configService.getSync().wallet; @@ -122,64 +112,87 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.description = $stateParams.description; $scope.paypro = $stateParams.paypro; - var network = (new bitcore.Address($scope.toAddress)).network.name; - $scope.network = network; + var networkName = (new bitcore.Address($scope.toAddress)).network.name; + $scope.network = networkName; - function setWallets() { - var w = profileService.getWallets({ - onlyComplete: true, - network: network, + $scope.notAvailable = false; + var wallets = profileService.getWallets({ + onlyComplete: true, + network: networkName, + }); + + var filteredWallets = []; + var index = 0; + + ongoingProcess.set('scanning', true); + + lodash.each(wallets, function(w) { + walletService.getStatus(w, {}, function(err, status) { + if (err) $log.error(err); + if (!status.availableBalanceSat) $log.debug('No balance available in: ' + w.name); + if (status.availableBalanceSat > amount) filteredWallets.push(w); + + if (++index == wallets.length) { + ongoingProcess.set('scanning', false); + + if (!lodash.isEmpty(filteredWallets)) { + $scope.wallets = lodash.clone(filteredWallets); + $scope.notAvailable = false; + } else { + $scope.notAvailable = true; + $log.warn('No wallet available to make the payment'); + } + + $timeout(function() { + $scope.$apply(); + }, 10); + return; + } }); - $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) { + if (lodash.isEmpty(wallet)) { + $log.debug('No wallet provided'); + return; + } + $log.debug('Wallet changed: ' + wallet.name); + setWallet(wallet, true); + }); - 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; + } + + if (cachedTxp[wallet.id]) { + apply(cachedTxp[wallet.id]); + } else { + ongoingProcess.set('creatingTx', true); + stop = $timeout(function() { + createTx(wallet, function(err, txp) { + ongoingProcess.set('creatingTx', false); + if (err) return; + cachedTxp[wallet.id] = txp; + apply(txp); + }); + }, delayed ? 2000 : 1); + } }; var setSendError = function(msg) { @@ -244,7 +257,6 @@ angular.module('copayApp.controllers').controller('confirmController', function( }); }; - $scope.openPPModal = function() { $ionicModal.fromTemplateUrl('views/modals/paypro.html', { scope: $scope @@ -254,8 +266,6 @@ angular.module('copayApp.controllers').controller('confirmController', function( }); }; - - $scope.approve = function() { var wallet = $scope.wallet; var txp = $scope.txp; @@ -287,7 +297,4 @@ angular.module('copayApp.controllers').controller('confirmController', function( $scope.cancel = function() { $state.transitionTo('tabs.send'); }; - - - }); diff --git a/src/js/controllers/tab-receive.js b/src/js/controllers/tab-receive.js index 28ede85ad..c7e2b319b 100644 --- a/src/js/controllers/tab-receive.js +++ b/src/js/controllers/tab-receive.js @@ -1,65 +1,54 @@ 'use strict'; -angular.module('copayApp.controllers').controller('tabReceiveController', function($scope, $ionicPopover, $timeout, platformInfo, nodeWebkit, walletService, profileService, configService, lodash, gettextCatalog) { +angular.module('copayApp.controllers').controller('tabReceiveController', function($scope, $timeout, $log, platformInfo, walletService, profileService, configService, lodash, gettextCatalog) { $scope.isCordova = platformInfo.isCordova; $scope.init = function() { - $scope.index = 0; + $scope.wallets = profileService.getWallets({ + onlyComplete: true + }); $scope.isCordova = platformInfo.isCordova; $scope.isNW = platformInfo.isNW; - $scope.setWallets(); - $scope.setAddress(false); - $scope.options = { - loop: false, - effect: 'flip', - speed: 500, - spaceBetween: 100 - } - - $scope.$on("$ionicSlides.sliderInitialized", function(event, data) { - // data.slider is the instance of Swiper - $scope.slider = data.slider; - }); - - $scope.$on("$ionicSlides.slideChangeStart", function(event, data) { - console.log('Slide change is beginning'); - }); - - $scope.$on("$ionicSlides.slideChangeEnd", function(event, data) { - $scope.index = data.slider.activeIndex; - $scope.setAddress(); - }); } + $scope.$on('Wallet/Changed', function(event, wallet) { + if (lodash.isEmpty(wallet)) { + $log.debug('No wallet provided'); + return; + } + $scope.defaultWallet = wallet; + $log.debug('Wallet changed: ' + wallet.name); + $scope.setAddress(wallet); + }); + $scope.shareAddress = function(addr) { if ($scope.isCordova) { window.plugins.socialsharing.share('bitcoin:' + addr, null, null, null); } }; - $scope.setAddress = function(forceNew) { + $scope.setAddress = function(wallet, forceNew) { + var wallet = wallet || $scope.defaultWallet; if ($scope.generatingAddress) return; $scope.addr = null; - $scope.addrError = null; + $scope.error = null; - var wallet = $scope.wallets[$scope.index]; - if (!wallet.isComplete()) { - $scope.incomplete = true; + if (wallet && !wallet.isComplete()) { $timeout(function() { $scope.$digest(); }); return; } - $scope.incomplete = false; $scope.generatingAddress = true; + $timeout(function() { - walletService.getAddress($scope.wallets[$scope.index], forceNew, function(err, addr) { + walletService.getAddress(wallet, forceNew, function(err, addr) { $scope.generatingAddress = false; if (err) { - $scope.addrError = err; + $scope.error = err; } else { if (addr) $scope.addr = addr; @@ -68,10 +57,4 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi }); }); }; - - - $scope.setWallets = function() { - $scope.wallets = profileService.getWallets(); - }; - }); diff --git a/src/js/directives/directives.js b/src/js/directives/directives.js index 285df5fd4..88458c146 100644 --- a/src/js/directives/directives.js +++ b/src/js/directives/directives.js @@ -142,4 +142,23 @@ angular.module('copayApp.directives') }); } } + }) + .directive('wallets', function($log, profileService, walletService, lodash) { + return { + restrict: 'E', + templateUrl: 'views/includes/wallets.html', + scope: { + wallets: '=wallets' + }, + link: function(scope, element, attrs) { + scope.$on("$ionicSlides.sliderInitialized", function(event, data) { + scope.slider = data.slider; + scope.$emit('Wallet/Changed', scope.wallets ? scope.wallets[0] : null); + }); + + scope.$on("$ionicSlides.slideChangeEnd", function(event, data) { + scope.$emit('Wallet/Changed', scope.wallets ? scope.wallets[data.slider.activeIndex] : null); + }); + } + } }); diff --git a/src/sass/main.scss b/src/sass/main.scss index 4683eb09f..43bccceb0 100644 --- a/src/sass/main.scss +++ b/src/sass/main.scss @@ -881,6 +881,9 @@ input[type=file] { width: inherit; } +.wallets { + height: 105px; +} /* * Calculator */