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
commit 3b5387fb70
7 changed files with 103 additions and 35 deletions

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');
}
});
});