add wallet change events

This commit is contained in:
Javier 2016-08-23 12:57:58 -03:00
commit 26b58fd9ed
5 changed files with 78 additions and 32 deletions

View file

@ -1,7 +1,7 @@
<div class="wallets" ng-show="wallets[0]"> <div class="wallets" ng-show="content.wallets[0]">
<ion-slides class="slides" slider="data.slider"> <ion-slides class="slides" slider="data.slider">
<ion-slide-page ng-repeat="wallet in wallets track by $index"> <ion-slide-page ng-repeat="wallet in content.wallets track by $index">
<div ng-show="wallets[0]" class="item item-icon-left"> <div class="item item-icon-left">
<i class="icon ion-briefcase size-21" ng-style="{'color':wallet.color}"></i> <i class="icon ion-briefcase size-21" ng-style="{'color':wallet.color}"></i>
{{wallet.name || wallet.id}} {{wallet.name || wallet.id}}
<span class="item-note" ng-show="wallet.n > 1 && wallet.isComplete()"> <span class="item-note" ng-show="wallet.n > 1 && wallet.isComplete()">

View file

@ -54,7 +54,8 @@ Error: {{addrError}}
<span ng-show="!generatingAddress" copy-to-clipboard="addr">{{addr}}</span> <span ng-show="!generatingAddress" copy-to-clipboard="addr">{{addr}}</span>
</div> </div>
</div> </div>
<div class="item item-text-wrap" ng-style="{'height' : '200px'}"> <wallets only-complete="false"></wallets>
<!-- <div class="item item-text-wrap" ng-style="{'height' : '200px'}">
<ion-slides class="slides" options="options" slider="data.slider"> <ion-slides class="slides" options="options" slider="data.slider">
<ion-slide-page ng-repeat="item in wallets track by $index" > <ion-slide-page ng-repeat="item in wallets track by $index" >
<div class="list card"> <div class="list card">
@ -74,6 +75,6 @@ Error: {{addrError}}
</div> </div>
</ion-slide-page> </ion-slide-page>
</ion-slides> </ion-slides>
</div> </div> -->
</ion-content> </ion-content>
</ion-view> </ion-view>

View file

@ -18,6 +18,7 @@
<div class="item item-divider"> <div class="item item-divider">
Preferences Preferences
</div> </div>
<wallets></wallets>
<div class="list"> <div class="list">
<div class="item item-icon-left" href ui-sref="settings.language"> <div class="item item-icon-left" href ui-sref="settings.language">
<i class="icon ion-ios-chatbubble-outline"></i> <i class="icon ion-ios-chatbubble-outline"></i>

View file

@ -1,6 +1,6 @@
'use strict'; '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, $ionicPopover, $timeout, $log, platformInfo, nodeWebkit, walletService, profileService, configService, lodash, gettextCatalog) {
$scope.isCordova = platformInfo.isCordova; $scope.isCordova = platformInfo.isCordova;
@ -8,43 +8,82 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
$scope.index = 0; $scope.index = 0;
$scope.isCordova = platformInfo.isCordova; $scope.isCordova = platformInfo.isCordova;
$scope.isNW = platformInfo.isNW; $scope.isNW = platformInfo.isNW;
$scope.setWallets(); // $scope.setWallets();
$scope.setAddress(false); $scope.setAddress(false);
$scope.options = { // $scope.options = {
loop: false, // loop: false,
effect: 'flip', // effect: 'flip',
speed: 500, // speed: 500,
spaceBetween: 100 // spaceBetween: 100
} // }
//
$scope.$on("$ionicSlides.sliderInitialized", function(event, data) { // $scope.$on("$ionicSlides.sliderInitialized", function(event, data) {
// data.slider is the instance of Swiper // // data.slider is the instance of Swiper
$scope.slider = data.slider; // $scope.slider = data.slider;
}); // });
//
$scope.$on("$ionicSlides.slideChangeStart", function(event, data) { // $scope.$on("$ionicSlides.slideChangeStart", function(event, data) {
console.log('Slide change is beginning'); // console.log('Slide change is beginning');
}); // });
//
$scope.$on("$ionicSlides.slideChangeEnd", function(event, data) { // $scope.$on("$ionicSlides.slideChangeEnd", function(event, data) {
$scope.index = data.slider.activeIndex; // $scope.index = data.slider.activeIndex;
$scope.setAddress(); // $scope.setAddress();
}); // });
} }
$scope.copyToClipboard = function(addr, $event) {
var showPopover = function() {
$ionicPopover.fromTemplateUrl('views/includes/copyToClipboard.html', {
scope: $scope
}).then(function(popover) {
$scope.popover = popover;
$scope.popover.show($event);
});
$scope.close = function() {
$scope.popover.hide();
}
$timeout(function() {
$scope.popover.hide(); //close the popover after 0.7 seconds
}, 700);
$scope.$on('$destroy', function() {
$scope.popover.remove();
});
};
if ($scope.isCordova) {
window.cordova.plugins.clipboard.copy(addr);
window.plugins.toast.showShortCenter(gettextCatalog.getString('Copied to clipboard'));
} else if ($scope.isNW) {
nodeWebkit.writeToClipboard(addr);
showPopover($event);
}
};
$scope.$on('Wallet/Changed', function(event, wallet) {
console.log(wallet);
$log.debug('Wallet changed: ' + wallet.name);
$scope.setAddress(wallet);
});
$scope.shareAddress = function(addr) { $scope.shareAddress = function(addr) {
if ($scope.isCordova) { if ($scope.isCordova) {
window.plugins.socialsharing.share('bitcoin:' + addr, null, null, null); window.plugins.socialsharing.share('bitcoin:' + addr, null, null, null);
} }
}; };
$scope.setAddress = function(forceNew) { $scope.setAddress = function(wallet, forceNew) {
if (!wallet) return;
if ($scope.generatingAddress) return; if ($scope.generatingAddress) return;
$scope.addr = null; $scope.addr = null;
$scope.addrError = null; $scope.addrError = null;
var wallet = $scope.wallets[$scope.index];
if (!wallet.isComplete()) { if (!wallet.isComplete()) {
$scope.incomplete = true; $scope.incomplete = true;
$timeout(function() { $timeout(function() {
@ -55,8 +94,9 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
$scope.incomplete = false; $scope.incomplete = false;
$scope.generatingAddress = true; $scope.generatingAddress = true;
$timeout(function() { $timeout(function() {
walletService.getAddress($scope.wallets[$scope.index], forceNew, function(err, addr) { walletService.getAddress(wallet, forceNew, function(err, addr) {
$scope.generatingAddress = false; $scope.generatingAddress = false;
if (err) { if (err) {
$scope.addrError = err; $scope.addrError = err;

View file

@ -143,25 +143,29 @@ angular.module('copayApp.directives')
} }
} }
}) })
.directive('wallets', function(profileService, lodash) { .directive('wallets', function(profileService) {
return { return {
restrict: 'E', restrict: 'E',
templateUrl: 'views/includes/wallets.html', templateUrl: 'views/includes/wallets.html',
scope: {}, scope: false,
link: function(scope, element, attrs) { link: function(scope, element, attrs) {
var opts = {}; var opts = {};
opts.onlyComplete = attrs.onlyComplete == 'true' ? true : null; opts.onlyComplete = attrs.onlyComplete == 'true' ? true : null;
opts.network = attrs.network; opts.network = attrs.network;
opts.n = attrs.n; opts.n = attrs.n;
scope.wallets = profileService.getWallets(opts); scope.content = {};
scope.content.wallets = profileService.getWallets(opts);
scope.$on("$ionicSlides.sliderInitialized", function(event, data) { scope.$on("$ionicSlides.sliderInitialized", function(event, data) {
scope.slider = data.slider; scope.slider = data.slider;
scope.content.index = data.slider.activeIndex;
scope.$emit('Wallet/Changed', scope.content.wallets[scope.content.index]);
}); });
scope.$on("$ionicSlides.slideChangeEnd", function(event, data) { scope.$on("$ionicSlides.slideChangeEnd", function(event, data) {
scope.index = data.slider.activeIndex; scope.content.index = data.slider.activeIndex;
scope.$emit('Wallet/Changed', scope.content.wallets[scope.content.index]);
}); });
} }
} }