add popover menu to share/scan addresses

This commit is contained in:
Javier 2016-11-18 15:29:53 -03:00
parent 439300743d
commit de65f88b9e
10 changed files with 117 additions and 59 deletions

View File

@ -1,8 +1,9 @@
'use strict';
angular.module('copayApp.controllers').controller('addressesController', function($scope, $stateParams, $state, $timeout, $ionicScrollDelegate, configService, popupService, gettextCatalog, ongoingProcess, lodash, profileService, walletService) {
angular.module('copayApp.controllers').controller('addressesController', function($scope, $stateParams, $state, $timeout, $ionicHistory, $ionicPopover, $ionicScrollDelegate, configService, popupService, gettextCatalog, ongoingProcess, lodash, profileService, walletService, platformInfo) {
var UNUSED_ADDRESS_LIMIT = 5;
var BALANCE_ADDRESS_LIMIT = 5;
var MENU_ITEM_HEIGHT = 55;
var config;
var unitName;
var unitToSatoshi;
@ -11,6 +12,8 @@ angular.module('copayApp.controllers').controller('addressesController', functio
var withBalance;
$scope.showInfo = false;
$scope.showMore = false;
$scope.allAddressesView = false;
$scope.isCordova = platformInfo.isCordova;
$scope.wallet = profileService.getWallet($stateParams.walletId);
function init() {
@ -111,6 +114,79 @@ angular.module('copayApp.controllers').controller('addressesController', functio
});
};
$scope.showMenu = function(allAddresses, $event) {
var scanObj = {
text: gettextCatalog.getString('Scan addresses for funds'),
action: scan,
};
var sendAddressesObj = {
text: gettextCatalog.getString('Send addresses by email'),
action: sendByEmail,
}
$scope.items = allAddresses ? [sendAddressesObj] : [scanObj];
$scope.height = $scope.items.length * MENU_ITEM_HEIGHT;
$ionicPopover.fromTemplateUrl('views/includes/menu-popover.html', {
scope: $scope
}).then(function(popover) {
$scope.menu = popover;
$scope.menu.show($event);
});
};
var scan = function() {
walletService.startScan($scope.wallet);
$scope.menu.hide();
$ionicHistory.clearHistory();
$state.go('tabs.home');
};
var sendByEmail = function() {
function formatDate(ts) {
var dateObj = new Date(ts * 1000);
if (!dateObj) {
$log.debug('Error formating a date');
return 'DateError';
}
if (!dateObj.toJSON()) {
return '';
}
return dateObj.toJSON();
};
ongoingProcess.set('sendingByEmail', true);
$timeout(function() {
var body = 'Copay Wallet "' + $scope.walletName + '" Addresses\n Only Main Addresses are shown.\n\n';
body += "\n";
body += $scope.allAddresses.map(function(v) {
return ('* ' + v.address + ' ' + 'xpub' + v.path.substring(1) + ' ' + formatDate(v.createdOn));
}).join("\n");
ongoingProcess.set('sendingByEmail', false);
window.plugins.socialsharing.shareViaEmail(
body,
'Copay Addresses',
null, // TO: must be null or an array
null, // CC: must be null or an array
null, // BCC: must be null or an array
null, // FILES: can be null, a string, or an array
function() {},
function() {}
);
$scope.menu.hide();
});
};
$scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.allAddressesView = data.stateName == 'tabs.receive.allAddresses' ? true : false;
$timeout(function() {
$scope.$apply();
});
});
$scope.$on("$ionicView.afterEnter", function(event, data) {
config = configService.getSync().wallet.settings;
unitToSatoshi = config.unitToSatoshi;

View File

@ -1,59 +1,15 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesInformation',
function($scope, $log, $timeout, $ionicHistory, platformInfo, lodash, profileService, configService, $stateParams, walletService, $state) {
var base = 'xpub';
function($scope, $log, $ionicHistory, platformInfo, lodash, profileService, configService, $stateParams, $state) {
var wallet = profileService.getWallet($stateParams.walletId);
var walletId = wallet.id;
var config = configService.getSync();
var b = 1;
var colorCounter = 1;
var BLACK_WALLET_COLOR = '#202020';
$scope.isCordova = platformInfo.isCordova;
config.colorFor = config.colorFor || {};
$scope.sendAddrs = function() {
function formatDate(ts) {
var dateObj = new Date(ts * 1000);
if (!dateObj) {
$log.debug('Error formating a date');
return 'DateError';
}
if (!dateObj.toJSON()) {
return '';
}
return dateObj.toJSON();
};
$timeout(function() {
walletService.getMainAddresses(wallet, {}, function(err, addrs) {
if (err) {
$log.warn(err);
return;
};
var body = 'Copay Wallet "' + $scope.walletName + '" Addresses\n Only Main Addresses are shown.\n\n';
body += "\n";
body += addrs.map(function(v) {
return ('* ' + v.address + ' ' + base + v.path.substring(1) + ' ' + formatDate(v.createdOn));
}).join("\n");
window.plugins.socialsharing.shareViaEmail(
body,
'Copay Addresses',
null, // TO: must be null or an array
null, // CC: must be null or an array
null, // BCC: must be null or an array
null, // FILES: can be null, a string, or an array
function() {},
function() {}
);
$timeout(function() {
$scope.$apply();
});
});
});
};
$scope.saveBlack = function() {
function save(color) {
var opts = {
@ -68,14 +24,8 @@ angular.module('copayApp.controllers').controller('preferencesInformation',
});
};
if (b != 5) return b++;
save('#202020');
};
$scope.scan = function() {
walletService.startScan(wallet);
$ionicHistory.removeBackView();
$state.go('tabs.home');
if (colorCounter != 5) return colorCounter++;
save(BLACK_WALLET_COLOR);
};
$scope.$on("$ionicView.enter", function(event, data) {

View File

@ -36,6 +36,7 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti
'sendingFeedback': gettext('Sending feedback...'),
'generatingNewAddress': gettext('Generating new address...'),
'gettingAddresses': gettext('Getting addresses...'),
'sendingByEmail': gettext('Preparing addresses...'),
};
root.clear = function() {

View File

@ -0,0 +1,12 @@
#menu-popover {
border-radius: 5px;
.list {
.item {
cursor: pointer;
cursor: hand;
&:hover {
background-color: #E4E2E2;
}
}
}
}

View File

@ -115,7 +115,6 @@
.item {
padding-top: 5px;
padding-bottom: 5px;
display: inline-block;
font-size: .7rem;
@media(min-width:350px){
font-size:.9rem;

View File

@ -27,6 +27,7 @@
@import "export";
@import "import";
@import "join";
@import "includes/menu-popover";
@import "includes/walletActivity";
@import "includes/wallets";
@import "includes/modals/modals";

View File

@ -3,10 +3,15 @@
<ion-nav-title>{{'Wallet Addresses' | translate}}</ion-nav-title>
<ion-nav-back-button>
</ion-nav-back-button>
<ion-nav-buttons side="secondary">
<button class="button back-button" ng-click="showMenu(false, $event)">
<i class="icon ion-ios-more"></i>
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-content>
<div class="zero-state banner-icon">
<div class="text-center banner-icon">
<i class="icon zero-state-icon">
<img src="img/tab-icons/ico-receive-selected.svg"/>
</i>

View File

@ -3,6 +3,11 @@
<ion-nav-title>{{'All Addresses' | translate}}</ion-nav-title>
<ion-nav-back-button>
</ion-nav-back-button>
<ion-nav-buttons side="secondary">
<button class="button back-button" ng-click="showMenu(true, $event)" ng-hide="!isCordova && allAddressesView">
<i class="icon ion-ios-more"></i>
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-content>

View File

@ -0,0 +1,9 @@
<ion-popover-view ng-style="{'height': height + 'px'}" id="menu-popover">
<ion-content>
<div class="list">
<div class="item" ng-repeat="i in items track by $index" ng-click="i.action()">
{{i.text}}
</div>
</div>
</ion-content>
</ion-popover-view>

View File

@ -70,7 +70,7 @@
<div class="item item-icon-left item-icon-right">
<i class="icon icon-svg receive-tab-bitcoin-icon"><img src="img/icon-bitcoin-symbol.svg"></i>
<span class="bit-address-gen-address" ng-if="generatingAddress">...</span>
<span class="bit-address-gen-address" ng-if="!generatingAddress">{{walletAddrs[wallet.id]}}</span>
<span class="bit-address-gen-address" ng-if="!generatingAddress" class="ellipsis">{{walletAddrs[wallet.id]}}</span>
<i class="icon ion-ios-arrow-right"></i>
</div>
</div>