fixes SHARED Wallet status, and refresh until it changes

This commit is contained in:
Matias Alejo Garcia 2016-03-09 11:53:47 -03:00
parent 139adb9974
commit 3b5387fb70
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 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() {
var fc = profileService.focusedClient;
if (fc.isComplete()) {

View File

@ -1,7 +1,7 @@
'use strict';
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;
self.tries = 0;
$scope.creatingProfile = true;
@ -34,14 +34,20 @@ angular.module('copayApp.controllers').controller('disclaimerController',
this.init = function() {
self.lang = uxLanguage.currentLanguage;
storageService.getProfile(function(err, profile) {
if (!profile) create(false);
else $scope.creatingProfile = false;
//compatible
profileService.isDisclaimerAccepted(function(val) {
if (val) go.walletHome();
});
profileService.getProfile(function(err, profile) {
if (!profile) {
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();
});
};
});
});

View File

@ -141,9 +141,30 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.initGlidera();
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) {
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.$apply();
if (opts.triggerTxUpdate && opts.untilItChanges) {
$timeout(function() {
self.debounceUpdateHistory();
@ -370,6 +392,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r
} else {
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.openWallet = function() {
self.openWallet = function(cb) {
var fc = profileService.focusedClient;
$timeout(function() {
$rootScope.$apply();
@ -447,9 +471,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r
return;
}
$log.debug('Wallet Opened');
self.updateAll(lodash.isObject(walletStatus) ? {
walletStatus: walletStatus
} : null);
walletStatus: walletStatus,
cb: cb,
} : {
cb: cb
});
$rootScope.$apply();
});
});
@ -1334,9 +1362,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}, cb);
});
$rootScope.$on('Local/WalletCompleted', function(event) {
self.setFocusedWallet();
go.walletHome();
$rootScope.$on('Local/WalletCompleted', function(event, walletId) {
var fc = profileService.focusedClient;
if (fc && fc.credentials.walletId == walletId) {
// reset main wallet variables
self.setFocusedWallet();
go.walletHome();
}
});
$rootScope.$on('Local/ProfileCreated', function(event) {
@ -1446,28 +1478,43 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setBalance(n.data);
});
$rootScope.$on('NewOutgoingTx', function() {
self.newTx = true;
self.updateAll({
walletStatus: null,
untilItChanges: true,
triggerTxUpdate: true,
//untilItChange TRUE
lodash.each(['NewOutgoingTx', 'NewOutgoingTxByThirdParty'], function(eventName) {
$rootScope.$on(eventName, function(event) {
self.newTx = true;
self.updateAll({
walletStatus: null,
untilItChanges: true,
triggerTxUpdate: true,
});
});
});
//untilItChange FALSE
lodash.each(['NewTxProposal', 'TxProposalFinallyRejected', 'TxProposalRemoved', 'NewOutgoingTxByThirdParty',
'Local/NewTxProposal', 'Local/TxProposalAction', 'Local/GlideraTx'
'Local/GlideraTx'
], function(eventName) {
$rootScope.$on(eventName, function(event, untilItChanges) {
self.newTx = eventName == 'Local/TxProposalAction' && untilItChanges;
$rootScope.$on(eventName, function(event) {
self.updateAll({
walletStatus: null,
untilItChanges: untilItChanges,
untilItChanges: null,
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() {
$log.debug('Scan Finished. Updating history');
storageService.removeTxHistory(self.walletId, function() {
@ -1517,6 +1564,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.startScan(walletId);
});
storageService.removeCleanAndScanAddresses(function() {});
$rootScope.$emit('Local/NewFocusedWalletReady');
}
});
});

View File

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

View File

@ -534,6 +534,7 @@ angular
}
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
$log.debug('Route change from:', fromState.name || '-', ' to:', toState.name);
if (!profileService.profile && toState.needProfile) {
@ -556,12 +557,12 @@ angular
$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)) {

View File

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

View File

@ -92,7 +92,7 @@ angular.module('copayApp.services')
$log.debug('Wallet completed');
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) {
storageService.getProfile(function(err, profile) {
if (err) {