remove functions from before enter event in send view

This commit is contained in:
Gabriel Bazán 2017-02-21 11:33:31 -05:00
commit f1a676a6ee
3 changed files with 181 additions and 134 deletions

View file

@ -7,19 +7,70 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
var currentContactsPage; var currentContactsPage;
$scope.isChromeApp = platformInfo.isChromeApp; $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 onlyComplete: true
}); });
$scope.hasWallets = lodash.isEmpty(wallets) ? false : true; $scope.hasWallets = lodash.isEmpty($scope.wallets) ? false : true;
$scope.oneWallet = wallets.length == 1; };
if (!$scope.oneWallet) { // THIS is ONLY to show the 'buy bitcoins' message
lodash.each(wallets, function(v) { // 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({ originalList.push({
color: v.color, color: v.color,
name: v.name, 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) { addressbookService.list(function(err, ab) {
if (err) $log.error(err); if (err) $log.error(err);
$scope.hasContacts = lodash.isEmpty(ab) ? false : true; $scope.hasContacts = lodash.isEmpty(ab) ? false : true;
if (!$scope.hasContacts) return;
var completeContacts = []; var completeContacts = [];
lodash.each(ab, function(v, k) { lodash.each(ab, function(v, k) {
completeContacts.push({ completeContacts.push({
@ -47,26 +103,28 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
}, },
}); });
}); });
var contacts = completeContacts.slice(0, (currentContactsPage + 1) * CONTACTS_SHOW_LIMIT); var contacts = completeContacts.slice(0, (currentContactsPage + 1) * CONTACTS_SHOW_LIMIT);
$scope.contactsShowMore = completeContacts.length > contacts.length; $scope.contactsShowMore = completeContacts.length > contacts.length;
originalList = originalList.concat(contacts); originalList = originalList.concat(contacts);
$scope.list = lodash.clone(originalList); $scope.updateList();
$timeout(function() {
$ionicScrollDelegate.resize();
$scope.$apply();
}, 10);
}); });
}; };
$scope.updateList = function() {
$scope.list = lodash.clone(originalList);
$timeout(function() {
$ionicScrollDelegate.resize();
$scope.$apply();
}, 10);
};
$scope.openScanner = function() { $scope.openScanner = function() {
$state.go('tabs.scan'); $state.go('tabs.scan');
}; };
$scope.showMore = function() { $scope.showMore = function() {
currentContactsPage++; currentContactsPage++;
updateList(); updateWalletsList();
}; };
$scope.findContact = function(search) { $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 // This could probably be enhanced refactoring the routes abstract states
$scope.createWallet = function() { $scope.createWallet = function() {
$state.go('tabs.home').then(function() { $state.go('tabs.home').then(function() {
@ -180,8 +177,28 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
$scope.buyBitcoin = function() { $scope.buyBitcoin = function() {
$state.go('tabs.home').then(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();
});
}); });

View file

@ -58,6 +58,35 @@
color: #387ef5; color: #387ef5;
font-weight: bold; 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 { .list {
.item { .item {
color: #444; color: #444;

View file

@ -2,75 +2,76 @@
<ion-nav-bar class="bar-royal"> <ion-nav-bar class="bar-royal">
<ion-nav-title>{{'Send' | translate}}</ion-nav-title> <ion-nav-title>{{'Send' | translate}}</ion-nav-title>
</ion-nav-bar> </ion-nav-bar>
<ion-content ng-show="!checkingBalance"> <ion-content>
<div ng-if="hasFunds == false" class="zero-state">
<div>
<i class="icon zero-state-icon">
<img src="img/tab-icons/ico-send-selected.svg"/>
</i>
<div class="zero-state-heading" translate>Start sending bitcoin</div>
<div class="zero-state-description" ng-show="hasWallets" translate>To get started, buy bitcoin or share your address. You can receive bitcoin from any wallet or service.</div>
<div class="zero-state-description" ng-show="!hasWallets" translate>To get started, you'll need to create a bitcoin wallet and get some bitcoin.</div>
<div class="zero-state-cta">
<button class="button button-standard button-primary" ng-click="buyBitcoin()" ng-show="hasWallets" translate>Buy Bitcoin</button>
<button class="button button-standard button-primary" ng-click="createWallet()" ng-show="!hasWallets" translate>Create bitcoin wallet</button>
<button class="button button-standard button-secondary" ui-sref="tabs.receive" ng-show="hasWallets" translate>Show bitcoin address</button>
</div>
</div>
</div>
<div ng-if="hasFunds">
<div class="item item-heading send-heading" translate>Recipient</div>
<div ng-if="hasWallets">
<div class="item item-heading send-heading" translate>Recipient</div>
<div class="item item-icon-left item-icon-right input"> <div class="item item-icon-left item-icon-right input">
<i class="icon icon-svg left"><img src="img/icon-bitcoin-symbol.svg"></i> <i class="icon icon-svg left"><img src="img/icon-bitcoin-symbol.svg"></i>
<input type="text" placeholder="{{'Search or enter bitcoin address' | translate}}" ng-model="formData.search" ng-change="findContact(formData.search)" ng-model-onblur> <input type="text" placeholder="{{'Search or enter bitcoin address' | translate}}" ng-model="formData.search" ng-change="findContact(formData.search)" ng-model-onblur>
<i class="icon icon-svg qr" on-tap="openScanner()"><img src="img/scan-ico.svg"/></i> <i class="icon icon-svg qr" on-tap="openScanner()"><img src="img/scan-ico.svg"/></i>
</div> </div>
</div>
<div class="card"> <div ng-if="!checkingBalance && (!hasFunds || !hasWallets)">
<div class="item item-icon-right item-heading"> <div class="list card sendTip">
<span translate>Contacts</span> <div class="item item-icon-right item-heading"></div>
<a ng-if="hasContacts" ui-sref="tabs.send.addressbook"> <div>
<i class="icon ion-ios-plus-empty list-add-button"></i> <i class="icon zero-state-icon">
</a> <img src="img/tab-icons/ico-send-selected.svg"/>
</i>
</div> </div>
<div class="list"> <div class="title" translate>
<a class="item item-icon-left item-icon-right" ng-if="!hasContacts" ui-sref="tabs.send.addressbook"> Start sending bitcoin
<i class="icon big-icon-svg">
<img src="img/contact-placeholder.svg" class="bg"/>
</i>
<span translate>Add a Contact</span>
<i class="icon bp-arrow-right"></i>
</a>
<a class="item item-icon-left item-icon-right" ng-repeat="item in list" ng-if="hasContacts && item.recipientType != 'wallet'" ng-click="goToAmount(item)">
<i class="icon big-icon-svg">
<img src="img/contact-placeholder.svg" class="bg"/ ng-if="isChromeApp">
<gravatar class="send-gravatar" name="{{item.name}}" width="30" email="{{item.email}}" ng-if="!isChromeApp"></gravatar>
</i>
{{item.name}}
<i class="icon bp-arrow-right"></i>
</a>
<div class="show-more" ng-if="contactsShowMore" ng-click="showMore()" translate>
Show more
</div>
</div> </div>
</div> <div class="subtitle" translate>
<span ng-show="hasWallets" translate>To get started, buy bitcoin or share your address. You can receive bitcoin from any wallet or service.</span>
<div class="card" ng-if="hasWallets && !oneWallet"> <span ng-show="!hasWallets" translate>To get started, you'll need to create a bitcoin wallet and get some bitcoin.</span>
<div class="list"> <div class="padding">
<div class="item item-heading"> <button class="button button-standard button-primary" ng-click="buyBitcoin()" ng-show="hasWallets" translate>Buy Bitcoin</button>
<span translate>Transfer to Wallet</span> <button class="button button-standard button-primary" ng-click="createWallet()" ng-show="!hasWallets" translate>Create bitcoin wallet</button>
<button class="button button-standard button-secondary" ui-sref="tabs.receive" ng-show="hasWallets" translate>Show bitcoin address</button>
</div> </div>
<a class="item item-icon-left item-icon-right" ng-repeat="item in list" ng-if="hasWallets && item.recipientType == 'wallet'" ng-click="goToAmount(item)">
<!-- <i ng-show="item.recipientType == 'wallet'" class="icon ion-briefcase size-21" ng-style="{'color':item.color}"></i> -->
<i class="icon big-icon-svg" ng-if="item.recipientType == 'wallet'">
<img src="img/icon-wallet.svg" ng-style="{'background-color': item.color}" class="bg"/>
</i>
{{item.name}}
<i class="icon bp-arrow-right"></i>
</a>
</div> </div>
</div> </div>
</div> </div>
<div class="card" ng-if="hasContacts && hasWallets && hasFunds">
<div class="item item-icon-right item-heading">
<span translate>Contacts</span>
<a ng-if="hasContacts" ui-sref="tabs.send.addressbook">
<i class="icon ion-ios-plus-empty list-add-button"></i>
</a>
</div>
<div class="list">
<a class="item item-icon-left item-icon-right" ng-repeat="item in list" ng-if="!item.isWallet && item.recipientType != 'wallet'" ng-click="goToAmount(item)">
<i class="icon big-icon-svg">
<img src="img/contact-placeholder.svg" class="bg"/ ng-if="isChromeApp">
<gravatar class="send-gravatar" name="{{item.name}}" width="30" email="{{item.email}}" ng-if="!isChromeApp"></gravatar>
</i>
{{item.name}}
<i class="icon bp-arrow-right"></i>
</a>
<div class="show-more" ng-if="contactsShowMore" ng-click="showMore()" translate>
Show more
</div>
</div>
</div>
<div class="card" ng-if="showTransferCard && hasFunds">
<div class="list">
<div class="item item-heading">
<span translate>Transfer to Wallet</span>
</div>
<a class="item item-icon-left item-icon-right" ng-repeat="item in list" ng-if="hasWallets && item.recipientType == 'wallet'" ng-click="goToAmount(item)">
<i class="icon big-icon-svg" ng-if="item.recipientType == 'wallet'">
<img src="img/icon-wallet.svg" ng-style="{'background-color': item.color}" class="bg"/>
</i>
{{item.name}}
<i class="icon bp-arrow-right"></i>
</a>
</div>
</div>
</ion-content> </ion-content>
</ion-view> </ion-view>