diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index b795853e0..2a1f0a9f6 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -7,19 +7,70 @@ angular.module('copayApp.controllers').controller('tabSendController', function( var currentContactsPage; $scope.isChromeApp = platformInfo.isChromeApp; - var updateList = function() { - CONTACTS_SHOW_LIMIT = 10; - currentContactsPage = 0; - originalList = []; - var wallets = profileService.getWallets({ + var hasWallets = function() { + $scope.wallets = profileService.getWallets({ onlyComplete: true }); - $scope.hasWallets = lodash.isEmpty(wallets) ? false : true; - $scope.oneWallet = wallets.length == 1; + $scope.hasWallets = lodash.isEmpty($scope.wallets) ? false : true; + }; - if (!$scope.oneWallet) { - lodash.each(wallets, function(v) { + // THIS is ONLY to show the 'buy bitcoins' message + // does not has any other function. + + var updateHasFunds = function() { + + if ($rootScope.everHasFunds) { + $scope.hasFunds = true; + return; + } + + $scope.hasFunds = false; + var index = 0; + lodash.each($scope.wallets, function(w) { + walletService.getStatus(w, {}, function(err, status) { + + ++index; + if (err && !status) { + $log.error(err); + // error updating the wallet. Probably a network error, do not show + // the 'buy bitcoins' message. + + $scope.hasFunds = true; + } else if (status.availableBalanceSat > 0) { + $scope.hasFunds = true; + $rootScope.everHasFunds = true; + } + + if (index == $scope.wallets.length) { + $scope.checkingBalance = false; + $timeout(function() { + $scope.$apply(); + }); + } + }); + }); + }; + + var updateWalletsList = function() { + + var networkResult = lodash.countBy($scope.wallets, 'network'); + + $scope.showTransferCard = $scope.hasWallets && (networkResult.livenet > 1 || networkResult.testnet > 1); + + if ($scope.showTransferCard) { + var walletsToTransfer = $scope.wallets; + if (!(networkResult.livenet > 1)) { + walletsToTransfer = lodash.filter(walletsToTransfer, function(item) { + return item.network == 'testnet'; + }); + } + if (!(networkResult.testnet > 1)) { + walletsToTransfer = lodash.filter(walletsToTransfer, function(item) { + return item.network == 'livenet'; + }); + } + lodash.each(walletsToTransfer, function(v) { originalList.push({ color: v.color, name: v.name, @@ -29,12 +80,17 @@ angular.module('copayApp.controllers').controller('tabSendController', function( }, }); }); + $scope.updateList(originalList); } + } + var updateContactsList = function() { addressbookService.list(function(err, ab) { if (err) $log.error(err); $scope.hasContacts = lodash.isEmpty(ab) ? false : true; + if (!$scope.hasContacts) return; + var completeContacts = []; lodash.each(ab, function(v, k) { completeContacts.push({ @@ -47,26 +103,28 @@ angular.module('copayApp.controllers').controller('tabSendController', function( }, }); }); - var contacts = completeContacts.slice(0, (currentContactsPage + 1) * CONTACTS_SHOW_LIMIT); $scope.contactsShowMore = completeContacts.length > contacts.length; originalList = originalList.concat(contacts); - $scope.list = lodash.clone(originalList); - - $timeout(function() { - $ionicScrollDelegate.resize(); - $scope.$apply(); - }, 10); + $scope.updateList(); }); }; + $scope.updateList = function() { + $scope.list = lodash.clone(originalList); + $timeout(function() { + $ionicScrollDelegate.resize(); + $scope.$apply(); + }, 10); + }; + $scope.openScanner = function() { $state.go('tabs.scan'); }; $scope.showMore = function() { currentContactsPage++; - updateList(); + updateWalletsList(); }; $scope.findContact = function(search) { @@ -110,67 +168,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function( }); }; - - // THIS is ONLY to show the 'buy bitcoins' message - // does not has any other function. - - var updateHasFunds = function() { - - if ($rootScope.everHasFunds) { - $scope.hasFunds = true; - return; - } - - $scope.hasFunds = false; - - var wallets = profileService.getWallets({ - onlyComplete: true, - }); - - if (!wallets || !wallets.length) { - return $timeout(function() { - $scope.$apply(); - }); - } - - $scope.checkingBalance = true; - var index = 0; - lodash.each(wallets, function(w) { - walletService.getStatus(w, {}, function(err, status) { - - ++index; - if (err && !status) { - $log.error(err); - // error updating the wallet. Probably a network error, do not show - // the 'buy bitcoins' message. - - $scope.hasFunds = true; - } else if (status.availableBalanceSat > 0) { - $scope.hasFunds = true; - $rootScope.everHasFunds = true; - } - - if (index == wallets.length) { - if ($scope.hasFunds != true) { - $ionicScrollDelegate.freezeScroll(true); - } - $scope.checkingBalance = false; - $timeout(function() { - $scope.$apply(); - }); - } - }); - }); - }; - - $scope.$on("$ionicView.beforeEnter", function(event, data) { - $scope.formData = { - search: null - }; - updateList(); - updateHasFunds(); - }); - // This could probably be enhanced refactoring the routes abstract states $scope.createWallet = function() { $state.go('tabs.home').then(function() { @@ -180,8 +177,28 @@ angular.module('copayApp.controllers').controller('tabSendController', function( $scope.buyBitcoin = function() { $state.go('tabs.home').then(function() { - $state.go('tabs.buyandsell.glidera'); + $state.go('tabs.buyandsell'); }); }; + $scope.$on("$ionicView.beforeEnter", function(event, data) { + $scope.checkingBalance = true; + $scope.formData = { + search: null + }; + originalList = []; + CONTACTS_SHOW_LIMIT = 10; + currentContactsPage = 0; + hasWallets(); + }); + + $scope.$on("$ionicView.enter", function(event, data) { + if (!$scope.hasWallets) { + $scope.checkingBalance = false; + return; + } + updateHasFunds(); + updateWalletsList(); + updateContactsList(); + }); }); diff --git a/src/sass/views/tab-send.scss b/src/sass/views/tab-send.scss index 1bbb72cb2..9b9c6d25f 100644 --- a/src/sass/views/tab-send.scss +++ b/src/sass/views/tab-send.scss @@ -58,6 +58,35 @@ color: #387ef5; font-weight: bold; } + .sendTip { + text-align: center; + & > .item-heading { + margin-top: 10px; + background: 0 none; + } + .item { + border-style: none; + } + & > .title { + font-size: 20px; + font-weight: bold; + color: $dark-gray; + margin: 20px 10px; + } + & > .subtitle { + font-size: 1rem; + line-height: 1.5em; + font-weight: 300; + color: $dark-gray; + margin: 20px 1em 2.5em; + } + .big-icon-svg{ + .bg.green{ + padding: 0 10px; + box-shadow: none; + } + } + } .list { .item { color: #444; diff --git a/www/views/tab-send.html b/www/views/tab-send.html index 839376ddd..c2ccbd069 100644 --- a/www/views/tab-send.html +++ b/www/views/tab-send.html @@ -2,75 +2,76 @@ {{'Send' | translate}} - -
-
- - - -
Start sending bitcoin
-
To get started, buy bitcoin or share your address. You can receive bitcoin from any wallet or service.
-
To get started, you'll need to create a bitcoin wallet and get some bitcoin.
-
- - - -
-
-
-
-
Recipient
+ +
+
Recipient
+
-
-
- Contacts - - - +
+
+
+
+ + +
-
- - - - - Add a Contact - - - - - - - - {{item.name}} - - -
- Show more -
+
+ Start sending bitcoin
-
- -
-
-
- Transfer to Wallet +
+ To get started, buy bitcoin or share your address. You can receive bitcoin from any wallet or service. + To get started, you'll need to create a bitcoin wallet and get some bitcoin. +
+ + +
- - - - - - {{item.name}} - -
+ +
+
+ Contacts + + + +
+
+ + + + + + {{item.name}} + + +
+ Show more +
+
+
+ +
+
+
+ Transfer to Wallet +
+ + + + + {{item.name}} + + +
+
+