Merge pull request #3979 from matiu/v192

fixes SHARED Wallet status, and refresh until it changes
This commit is contained in:
Gustavo Maximiliano Cortez 2016-03-09 12:18:02 -03:00
commit f0004761b6
7 changed files with 103 additions and 35 deletions

View file

@ -9,6 +9,11 @@ angular.module('copayApp.controllers').controller('copayersController',
var cancel_msg = gettextCatalog.getString('Cancel'); var cancel_msg = gettextCatalog.getString('Cancel');
var confirm_msg = gettextCatalog.getString('Confirm'); var confirm_msg = gettextCatalog.getString('Confirm');
// Note that this is ONLY triggered when the page is opened
// IF a wallet is incomplete and copay is at /#copayers
// and the user switch to an other complete wallet
// THIS IS NOT TRIGGERED.
//
self.init = function() { self.init = function() {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
if (fc.isComplete()) { if (fc.isComplete()) {

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('disclaimerController', angular.module('copayApp.controllers').controller('disclaimerController',
function($scope, $timeout, $log, profileService, isCordova, storageService, applicationService, gettextCatalog, uxLanguage, go) { function($scope, $timeout, $log, profileService, isCordova, applicationService, gettextCatalog, uxLanguage, go) {
var self = this; var self = this;
self.tries = 0; self.tries = 0;
$scope.creatingProfile = true; $scope.creatingProfile = true;
@ -34,14 +34,20 @@ angular.module('copayApp.controllers').controller('disclaimerController',
this.init = function() { this.init = function() {
self.lang = uxLanguage.currentLanguage; self.lang = uxLanguage.currentLanguage;
storageService.getProfile(function(err, profile) {
if (!profile) create(false);
else $scope.creatingProfile = false;
//compatible profileService.getProfile(function(err, profile) {
profileService.isDisclaimerAccepted(function(val) { if (!profile) {
if (val) go.walletHome(); create(false);
}); } else {
$log.debug('There is a profile already');
$scope.creatingProfile = false;
profileService.bindProfile(profile, function(err) {
if (!err || !err.message || !err.message.match('NONAGREEDDISCLAIMER')) {
$log.debug('Disclaimer already accepted at #disclaimer. Redirect to Wallet Home.')
go.walletHome();
}
});
}
}); });
}; };
@ -51,4 +57,4 @@ angular.module('copayApp.controllers').controller('disclaimerController',
else go.walletHome(); else go.walletHome();
}); });
}; };
}); });

View file

@ -141,9 +141,30 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.initGlidera(); self.initGlidera();
self.setCustomBWSFlag(); self.setCustomBWSFlag();
if (!self.isComplete) {
$log.debug('Wallet not complete BEFORE update... redirecting');
go.path('copayers');
} else {
if ($state.is('copayers')) {
$log.debug('Wallet Complete BEFORE update... redirect to home');
go.walletHome();
}
}
profileService.isBackupNeeded(self.walletId, function(needsBackup) { profileService.isBackupNeeded(self.walletId, function(needsBackup) {
self.needsBackup = needsBackup; self.needsBackup = needsBackup;
self.openWallet(); self.openWallet(function() {
if (!self.isComplete) {
$log.debug('Wallet not complete after update... redirecting');
go.path('copayers');
} else {
if ($state.is('copayers')) {
$log.debug('Wallet Complete after update... redirect to home');
go.walletHome();
}
}
});
}); });
}); });
}; };
@ -363,6 +384,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$emit('Local/BalanceUpdated', walletStatus.balance); $rootScope.$emit('Local/BalanceUpdated', walletStatus.balance);
$rootScope.$apply(); $rootScope.$apply();
if (opts.triggerTxUpdate && opts.untilItChanges) { if (opts.triggerTxUpdate && opts.untilItChanges) {
$timeout(function() { $timeout(function() {
self.debounceUpdateHistory(); self.debounceUpdateHistory();
@ -370,6 +392,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r
} else { } else {
self.loadingWallet = false; self.loadingWallet = false;
} }
if (opts.cb) return opts.cb();
}); });
}); });
}; };
@ -433,7 +457,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.handleError = lodash.debounce(_handleError, 1000); self.handleError = lodash.debounce(_handleError, 1000);
self.openWallet = function() { self.openWallet = function(cb) {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
$timeout(function() { $timeout(function() {
$rootScope.$apply(); $rootScope.$apply();
@ -447,9 +471,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r
return; return;
} }
$log.debug('Wallet Opened'); $log.debug('Wallet Opened');
self.updateAll(lodash.isObject(walletStatus) ? { self.updateAll(lodash.isObject(walletStatus) ? {
walletStatus: walletStatus walletStatus: walletStatus,
} : null); cb: cb,
} : {
cb: cb
});
$rootScope.$apply(); $rootScope.$apply();
}); });
}); });
@ -1334,9 +1362,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}, cb); }, cb);
}); });
$rootScope.$on('Local/WalletCompleted', function(event) { $rootScope.$on('Local/WalletCompleted', function(event, walletId) {
self.setFocusedWallet(); var fc = profileService.focusedClient;
go.walletHome(); if (fc && fc.credentials.walletId == walletId) {
// reset main wallet variables
self.setFocusedWallet();
go.walletHome();
}
}); });
$rootScope.$on('Local/ProfileCreated', function(event) { $rootScope.$on('Local/ProfileCreated', function(event) {
@ -1446,28 +1478,43 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setBalance(n.data); self.setBalance(n.data);
}); });
$rootScope.$on('NewOutgoingTx', function() {
self.newTx = true; //untilItChange TRUE
self.updateAll({ lodash.each(['NewOutgoingTx', 'NewOutgoingTxByThirdParty'], function(eventName) {
walletStatus: null, $rootScope.$on(eventName, function(event) {
untilItChanges: true, self.newTx = true;
triggerTxUpdate: true, self.updateAll({
walletStatus: null,
untilItChanges: true,
triggerTxUpdate: true,
});
}); });
}); });
//untilItChange FALSE
lodash.each(['NewTxProposal', 'TxProposalFinallyRejected', 'TxProposalRemoved', 'NewOutgoingTxByThirdParty', lodash.each(['NewTxProposal', 'TxProposalFinallyRejected', 'TxProposalRemoved', 'NewOutgoingTxByThirdParty',
'Local/NewTxProposal', 'Local/TxProposalAction', 'Local/GlideraTx' 'Local/GlideraTx'
], function(eventName) { ], function(eventName) {
$rootScope.$on(eventName, function(event, untilItChanges) { $rootScope.$on(eventName, function(event) {
self.newTx = eventName == 'Local/TxProposalAction' && untilItChanges;
self.updateAll({ self.updateAll({
walletStatus: null, walletStatus: null,
untilItChanges: untilItChanges, untilItChanges: null,
triggerTxUpdate: true, triggerTxUpdate: true,
}); });
}); });
}); });
//untilItChange Maybe
$rootScope.$on('Local/TxProposalAction', function(event, untilItChanges) {
self.newTx = untilItChanges;
self.updateAll({
walletStatus: null,
untilItChanges: untilItChanges,
triggerTxUpdate: true,
});
});
$rootScope.$on('ScanFinished', function() { $rootScope.$on('ScanFinished', function() {
$log.debug('Scan Finished. Updating history'); $log.debug('Scan Finished. Updating history');
storageService.removeTxHistory(self.walletId, function() { storageService.removeTxHistory(self.walletId, function() {
@ -1517,6 +1564,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.startScan(walletId); self.startScan(walletId);
}); });
storageService.removeCleanAndScanAddresses(function() {}); storageService.removeCleanAndScanAddresses(function() {});
$rootScope.$emit('Local/NewFocusedWalletReady');
} }
}); });
}); });

View file

@ -47,12 +47,12 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
self.setAddress(true); self.setAddress(true);
}); });
var disableFocusListener = $rootScope.$on('Local/NewFocusedWallet', function() { var disableFocusListener = $rootScope.$on('Local/NewFocusedWalletReady', function() {
self.addr = null; self.addr = null;
self.resetForm(); self.resetForm();
$scope.search = ''; $scope.search = '';
if (profileService.focusedClient) { if (profileService.focusedClient && rofileService.focusedClient.isComplete) {
self.setAddress(); self.setAddress();
self.setSendFormInputs(); self.setSendFormInputs();
} }

View file

@ -534,6 +534,7 @@ angular
} }
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
$log.debug('Route change from:', fromState.name || '-', ' to:', toState.name);
if (!profileService.profile && toState.needProfile) { if (!profileService.profile && toState.needProfile) {
@ -556,12 +557,12 @@ angular
$state.transitionTo(toState.name || toState, toParams); $state.transitionTo(toState.name || toState, toParams);
} }
}); });
} } else {
if (profileService.focusedClient && !profileService.focusedClient.isComplete() && toState.walletShouldBeComplete) {
if (profileService.focusedClient && !profileService.focusedClient.isComplete() && toState.walletShouldBeComplete) { $state.transitionTo('copayers');
event.preventDefault();
$state.transitionTo('copayers'); }
event.preventDefault();
} }
if (!animationService.transitionAnimated(fromState, toState)) { if (!animationService.transitionAnimated(fromState, toState)) {

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.services').factory('go', function($window, $rootScope, $location, $state, $timeout, profileService, nodeWebkit) { angular.module('copayApp.services').factory('go', function($window, $rootScope, $location, $state, $timeout, $log, profileService, nodeWebkit) {
var root = {}; var root = {};
var hideSidebars = function() { var hideSidebars = function() {
@ -55,6 +55,7 @@ angular.module('copayApp.services').factory('go', function($window, $rootScope,
root.walletHome = function() { root.walletHome = function() {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
if (fc && !fc.isComplete()) { if (fc && !fc.isComplete()) {
$log.debug("Wallet not complete at startup... redirecting")
root.path('copayers'); root.path('copayers');
} else { } else {
root.path('walletHome', function() { root.path('walletHome', function() {

View file

@ -92,7 +92,7 @@ angular.module('copayApp.services')
$log.debug('Wallet completed'); $log.debug('Wallet completed');
root.updateCredentialsFC(function() { root.updateCredentialsFC(function() {
$rootScope.$emit('Local/WalletCompleted') $rootScope.$emit('Local/WalletCompleted', client.credentials.walletId);
}); });
}); });
@ -151,6 +151,13 @@ angular.module('copayApp.services')
}; };
root.getProfile = function(cb) {
storageService.getProfile(function(err, profile) {
return cb(err, profile);
});
};
root.loadAndBindProfile = function(cb) { root.loadAndBindProfile = function(cb) {
storageService.getProfile(function(err, profile) { storageService.getProfile(function(err, profile) {
if (err) { if (err) {